function go_fullscreen(){
	var elem = document.getElementById("body");  
	if (elem.requestFullScreen) {  
	  elem.requestFullScreen();  
	} else if (elem.mozRequestFullScreen) {  
	  elem.mozRequestFullScreen();  
	} else if (elem.webkitRequestFullScreen) {  
	  elem.webkitRequestFullScreen();  
	} 
}

function exit_fullscreen(){
	//var elem = document.getElementById("body");  
	
	//alert('exit');
	
	if (document.cancelFullScreen) {  
	  document.cancelFullScreen();  
	} else if (document.mozCancelFullScreen) {  
	  document.mozCancelFullScreen();  
	} else if (document.webkitCancelFullScreen) {  
	  document.webkitCancelFullScreen();  
	} 
}

$(document).ready(function(){
	$('form').validate();

	$('.homeslide li').mouseenter(function(){
		$(this).children('div.wood').children('p.title').slideUp('slow');
		$(this).children('div.text').children('div').hide();
		$(this).children('div.text').children('div').css('opacity', '1');
		$(this).children('div.text').animate( { width: "show", paddingLeft: "show", paddingRight: "show", marginLeft: "show", marginRight: "show" }, 'slow', 'easeOutExpo',function(){
			$(this).children('div.text div').fadeIn();
			
		});
	});
	
	$('.homeslide li').mouseleave(function(){
		$(this).children('div.wood').children('p.title').stop(true, true).slideDown('slow');
		title = $(this).children('div.wood').children('p.title');
		//$(this).children('div.wood').children('p.title');
		$(this).children('div.text').stop();
		$(this).children('div.text').children('div').stop();
		$(this).children('div.text').children('div').hide();
		$(this).children('div.text').animate( { width: "hide", paddingLeft: "hide", paddingRight: "hide", marginLeft: "hide", marginRight: "hide" }, 'slow', 'easeOutExpo',function(){
			$(this).css('width', '343px');
			$(this).css('margin-left', '-343px');
			//title.removeAttr("style");
		} );
	});

	$('.news_title').click(function(){
		news_text = $(this).attr('rel');
		news_title = $(this).next();
		$('.news_title.active').removeClass('active');
		$(this).addClass('active');
		
		
		if (!(news_title.hasClass('active'))){
			$('.animate.active').animate( { width: "hide", paddingLeft: "hide", paddingRight: "hide", marginLeft: "hide", marginRight: "hide" }, 'slow', function(){	
				
				news_title.animate( { width: "show", paddingLeft: "show", paddingRight: "show", marginLeft: "show", marginRight: "show" }, 'slow', function(){
					$('.animate.active').removeClass('active');
					news_title.addClass('active');
				});
				
				
				$('#'+news_text).stop();
			});
			
			
			$('.news_text.active').animate( {"margin-left": "-=270px"}, 'slow', function(){	
					$('.news_text.active').hide();
					$('.news_text.active').removeClass('active');
					$('#'+news_text).css('margin-left', '-270px');
					$('#'+news_text).show();
					
					
						$('#'+news_text).animate( {"margin-left": "+=270px"}, 'slow', function(){
							$('#'+news_text).addClass('active');
							margin_left = $('#'+news_text).css('margin-left');
							$('#'+news_text).stop();
						});
					
			});
		}
	});
	
	
	$('.navigation div a').click(function(){
		if ($(this).parent().children('div.submeniu').length > 0){
			rel = $(this).attr('rel');
			if (!($(this).hasClass('active'))){	
				if($('.navigation div a.active').parent().children('div.submeniu').length>0){
					/*$('.navigation div a.active').parent().children('div.submeniu').fadeOut('fast', function(){
						$('.navigation div a.active').parent().children('div.submeniu').children('div').fadeOut('fast', function(){
							//$('.navigation div a.active').parent().children('div.submeniu').children('div').stop();
						});
					});*/
					$('.navigation div a.active').parent().children('div.submeniu').hide();
					$('.navigation div a.active').parent().children('div.submeniu').children('div').hide();
				}
				$('.navigation div a.active').removeClass('active');
				
				
				
				$(this).parent().children('div.submeniu').fadeIn('fast', function(){
					$(this).parent().children('div.submeniu').children('div').fadeIn('fast', function(){
						//$(this).parent().children('div.submeniu').children('div').stop();
					});
					
				});
				$(this).addClass('active');
			}	
			
			if (rel == "template0"){
				
				return false;
			}
		}
	});
	
	if ($.browser.webkit) {
		 document.addEventListener ("webkitfullscreenchange", function(){
			isFullScreen = document.mozFullScreen || document.webkitIsFullScreen;
			
			if (isFullScreen){
				$('#fullscreen_control').removeClass('fullscreen');
				$('#fullscreen_control').addClass('semiscreen');
			}else{
				$('#fullscreen_control').removeClass('semiscreen');
				$('#fullscreen_control').addClass('fullscreen');
			}
		 }, false);
			
		
		
		isFullScreen = document.mozFullScreen || document.webkitIsFullScreen;
		
		if (isFullScreen){
			$('.footer .top .right').prepend('<a href="javascript:void(0)" id="fullscreen_control" class="semiscreen"><div></div></a>');
		}else{
			$('.footer .top .right').prepend('<a href="javascript:void(0)" id="fullscreen_control" class="fullscreen"><div></div></a>');
		}
		
		$('#fullscreen_control').click(function(){
			isFullScreen = document.mozFullScreen || document.webkitIsFullScreen;
			
			if (!isFullScreen){
				go_fullscreen();
			}else{
				exit_fullscreen();
			}
			
			return false;
		});
	}

	
});

function write_to_log(text){
	html = $('#test').html();
	$('#test').html(html +'<br/>'+ text);
}

function link_video(video_id){
	$('#link a.video').attr('href', video_id+'&iframe=true');
	$('#link').show();
}


