//
//  VimeoViewController.m
//  Yoni Mordechay
//
//  Created by Nguyen Viet Minh on 5/3/13.
//  Copyright (c) 2013 Hieu Nguyen. All rights reserved.
//

#import "VimeoViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface VimeoViewController ()

@end

@implementation VimeoViewController
@synthesize txtURL;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
        
        // getting an NSString
        NSString *myString = [prefs stringForKey:@"language"];
        
        if([myString isEqualToString:@"عربي"])
        {
            UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"فعلت" style:UIBarButtonItemStylePlain
                                                                             target:self action:@selector(dismissView:)];
            self.navigationItem.rightBarButtonItem = anotherButton;
        }
        else
        {
            UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain
                                                                             target:self action:@selector(dismissView:)];
            self.navigationItem.rightBarButtonItem = anotherButton;
        }
    }
    return self;
}

 - (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    
    [[self navigationController] setNavigationBarHidden:NO animated:NO];
    [self.navigationItem setHidesBackButton:YES animated:NO];
    
    self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];
    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    [self setTitle:delegate.stringTitle];
    
}
-(IBAction)dismissView:(id)sender
{
    CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [[self navigationController] popViewControllerAnimated:NO];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    //Create a URL object.
//    NSURL *url = [NSURL URLWithString:@"http://dihqa.videovision.ca/"];
    NSURL *url = [NSURL URLWithString:txtURL];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    webView.scalesPageToFit=YES;
    //Load the request in the UIWebView.
    [webView loadRequest:requestObj];
}

 - (void)webViewDidStartLoad:(UIWebView *)webView
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

-(IBAction)btnBack:(id)sender
{
    [webView goBack];
}
-(IBAction)btnForw:(id)sender
{
    [webView goForward];
}
-(IBAction)btnReload:(id)sender
{
    [webView reload];
}

-(void)dealloc
{
    [webView release];
    [super dealloc];
}
-(void)viewWillDisappear:(BOOL)animated
{
         [webView stopLoading];
         webView=nil;
         [webView release];
}

@end
