// JavaScript Document
$(document).ready(function()
{
	$('#imgflipa').rotate({bind:
	  [
	   {"click":function(){
		   if($(this).attr("name") == "flipped"){
			   $(this).rotateAnimation(0);
			   $(this).attr("name","notflipped");
			   $(".largeboxcontent div").animate({opacity:0},{duration:800});
				   $('.largeboxcontent').delay(1200).slideUp("slow","easeInExpo");
				   $(".littlebox").delay(1800).animate({opacity:'1',filter: ''},{duration:500});
				   $('#imgflipa').delay(1800).animate({ marginTop:'0px' },{duration:500});
		   } else {
			   $(this).rotateAnimation(180);
			   $(this).attr("name","flipped");
			   $(".littlebox").fadeTo(500,0);
			   $(".largeboxcontent div").animate({opacity:0},{duration:1});
			   $('.largeboxcontent').slideUp("fast").delay(950).slideDown("slow","easeOutExpo",function(){
				   $(".largeboxcontent div").animate({opacity:1},{duration:800});
				});
			   $('#imgflipa').animate({ marginTop:'-30px' },{duration:500});
		   }
	   }}
	  ]
	});
	$('#imgflipb').rotate({bind:
	  [
	   {"click":function(){
		   if($(this).attr("name") == "flipped"){
			   $(this).rotateAnimation(0);
			   $(this).attr("name","notflipped");
		   } else {
			   $(this).rotateAnimation(180);
			   $(this).attr("name","flipped");
		   }
	   }}
	  ]
	});
	$('.bigbox').fadeIn(10,"easeInExpo");
	$('.headers').fadeIn(10,"easeInExpo");
	$('.thebody').fadeIn(10,"easeInExpo");
	$('#imgflipa').animate({ marginTop:'0px' });
	$('.littlebox .thebutton').animate({ paddingTop:'102px' });
	$('.littlebox').fadeIn(10,"easeInExpo");
	$('.entersite').fadeIn(10,"easeInElastic");
	$('.entersite h2').click(function() {
		$('.entersite h2').entersite();
	});
	$('.topmenu li').each(function() {
		$(this).fadeOut("fast");
	});
	$('.homeviddrop1').click(function() {
		$('.homeviddrop1').showvideo();
	});
	$('.homeviddrop2').click(function() {
		$('.homeviddrop2').showvideo();
	});
	$('.homeviddrop3').click(function() {
		$('.homeviddrop3').showvideo();
	});
	$('.closeplayer').click(function() {
		$('.closeplayer').closevideo();
	 });
	$('.closescreenshot').click(function() {
		$('.closescreenshot').closescreenshot();
	 });
});
jQuery.fn.entersite = function() {
	$('.entersite').fadeOut(500);
	$('.topmenu').animate({height: "100px"},{duration:1400,specialEasing:{height:"easeInOutQuart"}});
	$('.thelogoface').delay(1000).animate({width:"202px",height:"98px",filter: ''}).fadeMenuIn();
	$('.contactdetails').animate({marginTop: "10px",marginRight: "0px"});
	$.post("/getcontent.php",{ id: "about-us" }, function(xml) {
		parent.location.hash = "!/about-us";
	   changePage(xml,"about-us");
	 });   
};
jQuery.fn.showvideo = function() {
	$('.mainpage').animate({opacity: '0.1',filter: ''},{duration:500});
	$('.videoholder').fadeIn(500,"easeInExpo");
	var videoid = $(this).attr('id');
	$('.videoplayer').html("<iframe id=\"vimeoholder\" src=\"http://player.vimeo.com/video/"+videoid+"?title=0&amp;byline=0&amp;portrait=0&amp;color=595D2C\" width=\"650\" height=\"366\" frameborder=\"0\"></iframe>");
	$('#vimeoholder').fadeOut(500).delay(1000).fadeIn(800,"easeInExpo");
};
function letsDoVideo(videoid)
{
	$('.mainpage').animate({opacity: '0.1',filter: ''},{duration:500});
	$('.videoholder').fadeIn(500,"easeInExpo");
	$('.videoplayer').html("<iframe id=\"vimeoholder\" src=\"http://player.vimeo.com/video/"+videoid+"?title=0&amp;byline=0&amp;autoplay=1&amp;portrait=0&amp;color=595D2C\" width=\"650\" height=\"366\" frameborder=\"0\"></iframe>");
	$('#vimeoholder').fadeOut(500).delay(1000).fadeIn(800,"easeInExpo");
}
jQuery.fn.closevideo = function() {
	$('.mainpage').fadeTo(500,1);
	$('.videoholder').fadeOut(500,"easeOutExpo");
	$('.videoplayer').html("&nbsp;");
};
jQuery.fn.closescreenshot = function() {
	$('.mainpage').fadeTo(500,1);
	$('.screenshotholder').fadeOut(500,"easeOutExpo");
	$('.screenshotinner').html("&nbsp;");
};
jQuery.fn.fadeMenuIn = function() {
	var i = 1;
	var d = 500;
	$('.topmenu .menuitem').each(function() {
		var timer = Math.ceil(d*i);
		$(this).delay(timer).fadeIn("slow");
		i++;
	});
	$('.menuitem span').click(function(){
		var theid = $(this).attr('id');
		$('.isactivemenu').animate({color:'#BDCCD3',textDecoration:'none'});
		$('isactivemenu').attr('class','notactivemenu');
		$('#'+theid).animate({color:'#595D2C',textDecoration:'underline'});
		$(this).attr('class','isactivemenu');
		$.post("/getcontent.php",{ id: theid }, function(xml) {
			parent.location.hash = "!/"+theid;
		   changePage(xml,theid);
		 });   
	});
}
function getContent(theid)
{
	$('.isactivemenu').animate({color:'#BDCCD3'});
	$('#'+theid).animate({color:'#595D2C'});
	$.post("/getcontent.php",{ id: theid }, function(xml) {
		parent.location.hash = "!/"+theid;
	   changePage(xml,theid);
	 });   
}
jQuery.fn.fixClearType = function(){
    return this.each(function(){
        if(typeof this.style.filter  && this.style.removeAttribute)
        this.style.removeAttribute("filter");
    })
}
function changePage(xml,theid) {  
	var thexhtml = $("xhtml",xml).html();  
	$(".contentarea").animate({opacity:0},500,function(){
		$(".contentarea").html(thexhtml);
		$(".contentarea").animate({opacity:1});
		if(theid == "about-us" || theid == "production" || theid == "contact-us") {
			$.post("/getvideo.php",{ id: theid }, function(xml) {  
			   changeVideo(xml,theid);  
			}); 		
		} else {
		   changeLeft();  
		}
	  });
}
function changeVideo(xml)
{
	var thexhtml = $("xhtml",xml).html();  
	$(".leftmenu").animate({opacity:0},500,function(){
		$('.leftmenu').css("display","none");
		$(".leftmenu_inner .bigbox").html(thexhtml);
		$('.leftmenu_inner').css("opacity","0");
		$('.leftmenu_inner').css("display","block");
		$(".leftmenu_inner").animate({opacity:1});
	  });
}
function changeLeft()
{
	$(".leftmenu_inner").animate({opacity:0},500,function(){
		$('.leftmenu_inner').css("display","none");
		$('.leftmenu').css("display","block");
		$(".leftmenu").animate({opacity:1});
	  });
}
function listShow(theid)
{
	$("#listpage_"+theid).animate({opacity:1});	
}
function listHide(theid)
{
	$("#listpage_"+theid).animate({opacity:0.6});
}
function getArticle(theid,category,pname)
{
	$.post("/getarticle.php",{ id: theid, backto: category }, function(xml) {  
	   parent.location.hash = "!/"+category+"/"+pname+"-"+theid;
	   listToArticle(xml,theid);  
	 });   
}
function getRArticle(theid,category,pname)
{
	$('.isactivemenu').animate({color:'#BDCCD3',textDecoration:'none'});
	$('isactivemenu').attr('class','notactivemenu');
	$('#'+category).animate({color:'#595D2C',textDecoration:'underline'});
	$.post("/getarticle.php",{ id: theid }, function(xml) {  
	   parent.location.hash = "!/"+category+"/"+pname+"-"+theid;
	   articleToArticle(xml,theid);
	 });   
}
function listToArticle(xml,theid) {  
	var thexhtml = $("xhtml",xml).html();
	$('.thelist').animate({opacity:0},500).hide("drop",{direction: "right"},500,function(){
		$(".contentarea").animate({opacity:0},500,function(){
		$(".contentarea").html(thexhtml);
		$(".contentarea").animate({opacity:1},400);
		$.post("/getvideo.php",{ id: theid }, function(xml) {
		   changeVideo(xml,theid);
		 });
	  });
  });
}
function articleToArticle(xml,theid) {
	var thexhtml = $("xhtml",xml).html();  
	$(".contentarea").animate({opacity:0},500,function(){
		$(".contentarea").html(thexhtml);
		$(".contentarea").animate({opacity:1});
			$.post("/getvideo.php",{ id: theid }, function(xml) {  
			   changeVideo(xml,theid);  
			}); 		
	  });
}
function fadeToPrev()
{
	var icurrent= parseInt(document.getElementById('icurrent').value);
	var itotal	= document.getElementById('itotal').value;
	var prev	= Math.round(icurrent - 1);
	if(prev > 0){
		$("#imageset_"+prev).css("display","block");
		$("#imageset_"+icurrent).animate({opacity:0},{duration:500});
		$("#imageset_"+icurrent).delay(500).css("display","none");
		$("#imageset_"+prev).delay(500).animate({opacity:1},{duration:500});
		document.getElementById('icurrent').value = prev;
	}
}
function fadeToNext()
{
	var icurrent= parseInt(document.getElementById('icurrent').value);
	var itotal	= parseInt(document.getElementById('itotal').value);
	var iotot	= Math.round(itotal +1);
	var next	= Math.round(icurrent + 1);
	if(next < iotot){
		$("#imageset_"+next).css("display","block");
		$("#imageset_"+icurrent).animate({opacity:0},{duration:500});
		$("#imageset_"+icurrent).delay(500).css("display","none");
		$("#imageset_"+next).delay(500).animate({opacity:1},{duration:500});
		document.getElementById('icurrent').value = next;
	}
}
function checkHash()
{
	if(document.location.hash != "") {
		var ishash = document.location.hash;
		var strippedhash = ishash.split("#!/");
		var urlhash = strippedhash[1].split("/");
		//	alert(urlhash[0]);
		//	alert(urlhash[1]);
		if(!urlhash[1]){
			$('.entersite').fadeOut(500);
			$('.topmenu').animate({height: "100px"},{duration:1400,specialEasing:{height:"easeInOutQuart"}});
			$('.thelogoface').delay(1000).animate({width:"202px",height:"98px",filter: ''}).fadeMenuIn();
			$('.contactdetails').animate({marginTop: "10px",marginRight: "0px"});
			$.post("/getcontent.php",{ id: urlhash[0] }, function(xml) {
				changePage(xml,urlhash[0]);
			});
		} else {
			var pageid = urlhash[1].split("-");
			var thepage= pageid.pop();
			$('.entersite').fadeOut(500);
			$('.topmenu').animate({height: "100px"},{duration:1400,specialEasing:{height:"easeInOutQuart"}});
			$('.thelogoface').delay(1000).animate({width:"202px",height:"98px",filter: ''}).fadeMenuIn();
			$('.contactdetails').animate({marginTop: "10px",marginRight: "0px"});
			$.post("/getarticle.php",{ id: thepage }, function(xml) {  
				var thexhtml = $("xhtml",xml).html();
				$(".contentarea").animate({opacity:0},500,function(){
				$(".contentarea").html(thexhtml);
				$(".contentarea").animate({opacity:1},400);
				$.post("/getvideo.php",{ id: thepage }, function(xml) {
				   changeVideo(xml,thepage);
				 });
			  });
			});   
		}
	}
}

function showScreenshot(imageid)
{
	$('.mainpage').animate({opacity: '0.1',filter: ''},{duration:500});
	$('.screenshotholder').fadeIn(500,"easeInExpo");
	$('.screenshotinner').html("<img src=\"/admin/uploads/"+imageid+"\" />");
}
function prevScreenshot()
{
	var currentimg = parseInt(document.getElementById('curimage').value);
	$('.screenshotinner').fadeOut(500,function(){
		if(currentimg > 1){
			var getimg = Math.round(currentimg - 1);
			var previmg = $('#image_'+getimg).attr("class");
			$('.screenshotinner').html("<img src=\"/admin/uploads/"+previmg+"\" />");
			document.getElementById('curimage').value = getimg;
		}
		$('.screenshotinner').delay(800).fadeIn(500);											   
   });
}
function nextScreenshot()
{
	var currentimg = parseInt(document.getElementById('curimage').value);
	var maximage = parseInt(document.getElementById('maximage').value);
	$('.screenshotinner').fadeOut(500,function(){
	if(currentimg < maximage){
		var getimg = Math.round(currentimg + 1);
		var nextimg = $('#image_'+getimg).attr("class");
		$('.screenshotinner').html("<img src=\"/admin/uploads/"+nextimg+"\" />");
		document.getElementById('curimage').value = getimg;
	}
		$('.screenshotinner').delay(800).fadeIn(500);											   
   });
}
function nextPage(theid,thpage)
{
	$.post("/getcontent.php",{ id: theid, page: thpage }, function(xml) {
		parent.location.hash = "!/"+theid;
	   changePage(xml,theid);
	 });   
}
function prevPage(theid,thpage)
{
	$.post("/getcontent.php",{ id: theid, page: thpage }, function(xml) {
		parent.location.hash = "!/"+theid;
	   changePage(xml,theid);
	 });   
}
