//
//  Tab1.m
//  Yoni
//
//  Created by Hieu Nguyen on 4/17/13.
//  Copyright (c) 2013 Hieu Nguyen. All rights reserved.
//

#import "HomeView.h"
#import "VideoView.h"
#import "VimeoViewController.h"
#import "LiveViewController.h"
#import "AboutUsViewController.h"
@interface HomeView ()

@end

@implementation HomeView

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    //[tvHeader SettextTextView:[NSString stringWithFormat:@"<span style= 'font-family:\"HelveticaNeueLTStd-Bd\",Georgia,Serif; font-size: 16px'>YONI MORDECHAY </span><span style= 'font-family:\"OpenSans\",Georgia,Serif; font-size: 16px'>DIRECTOR</span>"]];
    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    
    // getting an NSString
    NSString *myString = [prefs stringForKey:@"language"];
 
    if(myString)
    {
      if([myString isEqualToString:@"عربي"])
      {
          lbl1.text=@"يوتيـوب";
          lbl2.text=@"الأرشيف";
          lbl3.text=@"البث الحي";
          lbl4.text=@"معرض الصور";
          lbl5.text=@"عن الجائزة";
          lbl6.text=@"أخبار";

      }
        else
        {
            lbl1.text=@"YouTube";
            lbl2.text=@"Archieves";
            lbl3.text=@"Live Streaming";
            lbl4.text=@"Photo Galary";
            lbl5.text=@"About Us";
            lbl6.text=@"News";


        }
    }
    else
    {
        lbl1.text=@"يوتيـوب";
        lbl2.text=@"الأرشيف";
        lbl3.text=@"البث الحي";
        lbl4.text=@"معرض الصور";
        lbl5.text=@"عن الجائزة";
        lbl6.text=@"أخبار";

        NSUserDefaults *prefs1 = [NSUserDefaults standardUserDefaults];

         // saving an NSString
        [prefs1 setObject:@"عربي" forKey:@"language"];
        [prefs1 synchronize];


    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //[lb1 setFont:[UIFont fontWithName:@"OpenSans" size:32]];
    
    for (UILabel *label in [self.view subviews])
    {
        if ([label isKindOfClass:[UILabel class]]){
            if ([[label.font.fontName componentsSeparatedByString:@"-"] count]>1) {
            }
            else
            {
                label.font = [UIFont fontWithName:@"OpenSans" size:label.font.pointSize];
            }
        }
    }
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)home_action:(id)sender {
    
    UIButton *btn = (UIButton *)sender;
    
    if (btn.tag ==11) {
        
         AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        delegate.stringTitle = @"YouTube";
        
        VideoView *video = [[VideoView alloc] initWithNibName:@"VideoView" bundle:nil];
        CATransition* transition = [CATransition animation];
        transition.duration = 0.3;
        transition.type = kCATransitionFade;
        transition.subtype = kCATransitionFromTop;
        video.stringURL = @"http://gdata.youtube.com/feeds/api/users/dihqauae/uploads";
        
//        http://gdata.youtube.com/feeds/api/users/userId?v=2
        [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
        [self.navigationController pushViewController:video animated:NO];
        
    }
    else if (btn.tag == 44)
    {
        AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        delegate.stringTitle = @"Archives";

        VimeoViewController *tab = [[VimeoViewController alloc] initWithNibName:@"VimeoViewController" bundle:nil];
        CATransition* transition = [CATransition animation];
        transition.duration = 0.4;
        transition.type = kCATransitionFade;
        transition.subtype = kCATransitionFromTop;
        [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
        [self.navigationController pushViewController:tab animated:NO];
//        tab = nil;
//        [tab release];
    }
    else if (btn.tag == 55)
    {
        AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        delegate.stringTitle = @"Live Stream";

        LiveViewController *tab = [[LiveViewController alloc] initWithNibName:@"LiveViewController" bundle:nil];
        CATransition* transition = [CATransition animation];
        transition.duration = 0.4;
        transition.type = kCATransitionFade;
        transition.subtype = kCATransitionFromTop;
        [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
        [self.navigationController pushViewController:tab animated:NO];
//        tab = nil;
//        [tab release];
    }
}
-(IBAction)btnInfo:(id)sender
{
     AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.stringTitle = lbl5.text;
    
    AboutUsViewController *tab = [[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];
    CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:tab animated:NO];

}
-(IBAction)btnGallery:(id)sender
{
    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.stringTitle = lbl4.text;
    
    VimeoViewController *tab = [[VimeoViewController alloc] initWithNibName:@"VimeoViewController" bundle:nil];
    tab.txtURL=[[NSString alloc]init];
    tab.txtURL=@"http://instagram.com/quran_award";
    CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:tab animated:NO];

}
-(IBAction)btnArchive:(id)sender
{
    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.stringTitle = lbl2.text;
    
    VimeoViewController *tab = [[VimeoViewController alloc] initWithNibName:@"VimeoViewController" bundle:nil];
    tab.txtURL=[[NSString alloc]init];
    tab.txtURL=@"http://dihqa.videovision.ca/";
    CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:tab animated:NO];

}
-(IBAction)btnYoutube:(id)sender
{
    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.stringTitle = lbl1.text;
    
    VideoView *video = [[VideoView alloc] initWithNibName:@"VideoView" bundle:nil];
    CATransition* transition = [CATransition animation];
    transition.duration = 0.3;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;
    video.stringURL = @"http://gdata.youtube.com/feeds/api/users/dihqauae/uploads";
    
    //        http://gdata.youtube.com/feeds/api/users/userId?v=2
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:video animated:NO];

}

-(IBAction)btnLiveStreaming:(id)sender
{
    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.stringTitle =lbl3.text;
    
    LiveViewController *tab = [[LiveViewController alloc] initWithNibName:@"LiveViewController" bundle:nil];
    CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:tab animated:NO];

}
-(void)moviePlayerEvent:(NSNotification*)aNotification{
    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    NSLog(@"%i", [UIApplication sharedApplication].statusBarHidden);
    
}
-(IBAction)btnCompany:(id)sender
{
    //http://www.vvmfz.com
    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.stringTitle = lbl6.text;
    
    VimeoViewController *tab = [[VimeoViewController alloc] initWithNibName:@"VimeoViewController" bundle:nil];
    tab.txtURL=[[NSString alloc]init];
    tab.txtURL=@"http://www.dihqa.net/ar/index.php?option=com_content&view=category&layout=blog&id=91&Itemid=549";
    CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:tab animated:NO];
    
}
-(IBAction)segmentedControlIndexChanged{
	switch (segment.selectedSegmentIndex) {
		case 0:
            [self Arabic];
            break;
		case 1:
            [self English];
			break;
            
		default:
            break;
    }
    
}
-(void)Arabic
{
    lbl1.text=@"يوتيـوب";
    lbl2.text=@"الأرشيف";
    lbl3.text=@"البث الحي";
    lbl4.text=@"معرض الصور";
    lbl5.text=@"عن الجائزة";
    lbl6.text=@"أخبار";


    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
     // saving an NSString
    [prefs setObject:@"عربي" forKey:@"language"];
     [prefs synchronize];
}
-(void)English
{
    lbl1.text=@"YouTube";
    lbl2.text=@"Archieves";
    lbl3.text=@"Live Streaming";
    lbl4.text=@"Photo Galary";
    lbl5.text=@"About Us";
    lbl6.text=@"News";


    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    // saving an NSString
    [prefs setObject:@"English" forKey:@"language"];
 [prefs synchronize];
}

@end
