/*
	site: 		www.capcom-europe.com
	author: 	matt, johan, engwei
	company:	www.dialmediagroup.com
	index:
			1. VIDEO PANEL
			2. CONTENT SLIDER - JFLOW
			3. SCROLLER
			4. SIMPLE TABS
			5. FANCYBOX
			6. HOME BOXES 
			7. IMAGE MOUSE OVER FADE
			8. MOUSE OVER BUBBLES
			9. ACCORDION
			10. EXTERNAL SITES / OPEN NEW WINDOW

*/

////////////////// VIDEO PANEL //////////////////
$(document).ready(function() {
	// this code is not the same as in behaviours-forum	
	
	$("#panel .btn-slide-video").addClass("btn-slide-video-active");
	$("#panel").animate({"height": "455px"}, 0); 
	
	function getFlashMovie(movieName) {
	  // IE and Netscape refer to the movie object differently.
	  // This function returns the appropriate syntax depending on the browser.
	  if (navigator.appName.indexOf ("Microsoft") !=-1) {
		return window[movieName]
	  } else {
		return document[movieName]
	  }
	}
	function loadMoviePlayer(){
		var intColour=0;
		if ($.cookie('capcolour')=='Red'){
			intColour = 1;
		}else if($.cookie('capcolour')=='Yellow'){
			intColour = 2;
		}else if($.cookie('capcolour')=='Green'){
			intColour = 3;
		}else if($.cookie('capcolour')=='Brown'){
			intColour = 4;
		}else if($.cookie('capcolour')=='Pink'){
			intColour = 5;
		}else if($.cookie('capcolour')=='Blue'){
			intColour = 6;
		}else if($.cookie('capcolour')=='Purple'){
			intColour = 7;
		}else if($.cookie('capcolour')=='Flame'){
			intColour = 8;
		}

		var FO = { movie:"/capcom_video_player.swf?intColour="+intColour, width:"976", height:"455", majorversion:"9", build:"115", setcontainercss:"true",scale:"showall",wmode:"transparent",allowfullscreen:"true",name:"videoplayer" }; 
		UFO.create(FO, "videoplayercontainer");	
	}
		
	var contentShowTop = false;
	   $(".btn-slide-video").click(function(){
			
			//if we're on the homepage do the following:
			if (window.location.pathname == "/" || window.location.pathname == "/index.php") {
				var showTop = $.cookie('showTop');
				if (showTop == 'collapsed') {
					//OPEN
					$("#panel").animate({"height": "455px"}, "slow");
					 $(this).addClass("btn-slide-video-active");
					$.cookie('showTop', 'expanded', { expires: 7, path: "/" });
					if (typeof(getFlashMovie('videoplayer')) != "undefined") {
						getFlashMovie('videoplayer').SetVariable('intOpen', 1);
					}else{
						loadMoviePlayer();	
					}
					return false;
				
				  } else {
					//CLOSE
					$("#panel").animate({"height": "155px"}, "slow");
					$(this).removeClass("btn-slide-video-active");
					$.cookie('showTop', 'collapsed');
					if (typeof(getFlashMovie('videoplayer')) != "undefined") {
						getFlashMovie('videoplayer').SetVariable('intOpen', 0);
					}
					return false;
				}
			}else{
			//if we're on a content page, then do the following:
				if (!contentShowTop) {
					//OPEN
					$("#panel").animate({"height": "455px"}, "slow");
					 $(this).addClass("btn-slide-video-active");
					contentShowTop = true;
					if (typeof(getFlashMovie('videoplayer')) != "undefined") {
						getFlashMovie('videoplayer').SetVariable('intOpen', 1);
					}else{
						loadMoviePlayer();	
					}
					return false;
				
				  } else {
					//CLOSE
					$("#panel").animate({"height": "155px"}, "slow");
					$(this).removeClass("btn-slide-video-active");
					contentShowTop = false;
					if (typeof(getFlashMovie('videoplayer')) != "undefined") {
						getFlashMovie('videoplayer').SetVariable('intOpen', 0);
					}
					return false;
				}
			}
	   });
		

	// COOKIES
	// Header State
		var showTop = $.cookie('showTop');
		//IF YOU'RE NOT ON THE HOMEPAGE DO
		if (window.location.pathname != "/" && window.location.pathname != "/index.php") {
			$("#panel").animate({"height": "155px"}, 0);
			$(".btn-slide-video").removeClass("btn-slide-video-active");
			if (typeof(getFlashMovie('videoplayer')) != "undefined") {
				getFlashMovie('videoplayer').SetVariable('intOpen', 0);
			}
		//IF ON HOMEPAGE DO BELOW	
		}else{
			if (showTop=='collapsed'){
				$("#panel").animate({"height": "155px"}, 0);
				$(".btn-slide-video").removeClass("btn-slide-video-active");
				if (typeof(getFlashMovie('videoplayer')) != "undefined") {
					getFlashMovie('videoplayer').SetVariable('intOpen', 0);
				}
				$.cookie('showTop', 'collapsed', { expires: 7, path: "/" });
			}else{
				loadMoviePlayer();	
				if (typeof(getFlashMovie('videoplayer')) != "undefined") {
					getFlashMovie('videoplayer').SetVariable('intOpen', 1);
				}
				$.cookie('showTop', 'expanded', { expires: 7, path: "/" });
			}
			//if(showTop==null || showTop=='' || showTop=='expanded'){
		}
		//resets the cookie for another 7 days
		$.cookie("showTop", $.cookie("showTop"), { expires: 7, path: "/" });
});




////////////////// CONTENT SLIDER - JFLOW //////////////
$(document).ready(function(){
	$(".main-news-bottom").jFlow({
		slides: "#mySlides",
		width: "620px",
		height: "270px",
		duration: 400
	});
});




////////////////// SCROLLER //////////////////
$(document).ready(function(){
	$('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 13, arrowSize: 28, wheelSpeed:50});
	$('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 13, arrowSize: 28, wheelSpeed:50});
});



//////////////// SIMPLE TABS //////////////////////
/* jQuery Basic Tabs by Johan */
$(document).ready(function(){
	$('#tabs div').hide(); // Hide all divs
	$('#tabs div:first').show(); // Show the first div
	$('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
	$('#tabs ul li a').click(function(){ //When any link is clicked
		$('#tabs ul li').removeClass('active'); // Remove active class from all links
		$(this).parent().addClass('active'); //Set clicked link class to active
		var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		$('#tabs div').hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
}); 


////////////////// FANCYBOX //////////////////
$(document).ready(function(){
	// duplicated in behaviours-forum					   
	$(".fancyboxlink").fancybox({
		'frameWidth': 450,
		'frameHeight': 400,		
		'overlayShow':	true,
		'overlayOpacity': 0.7
	});
});

$(document).ready(function(){
	$(".gamescreenshot").fancybox({
		'frameWidth': 800,
		'frameHeight': 450,	
		'hideOnContentClick': false,
		'overlayShow':	true,
		'overlayOpacity': 0.7
	});
});

$(document).ready(function(){
	$(".languagepopup").fancybox({
		'frameWidth': 270,
		'frameHeight': 130,		
		'overlayShow':	true,
		'overlayOpacity': 0.7
	});
});

$(document).ready(function(){
	$(".age-check").fancybox({
		'frameWidth': 420,
		'frameHeight': 220,		
		'overlayShow':	true,
		'overlayOpacity': 0.7
	});
	$(".age-check-young").fancybox({
		'frameWidth': 420,
		'frameHeight': 220,		
		'overlayShow':	true,
		'overlayOpacity': 0.7
	});
});

function doAge(){
	$(".age-check").click();	
}
function tooYoung(){
	$(".age-check-young").click();	
}


////////////////// HOME BOXES //////////////////
$(document).ready(function() {			
	
	//function that sets the home boxes
	function setHomeBoxes(strTemp){
		$("#content-"+strTemp).show();
		$(".btn-box-"+strTemp).addClass("link-collapse-active");
		
		$(".btn-box-"+strTemp).click(function(){
		   if ($("#content-"+strTemp).is(":hidden")) {
				$("#content-"+strTemp).slideDown();
				$(this).addClass("link-collapse-active");
				$.cookie('showBox'+strTemp, 'collapsed', { expires: 365, path: "/" });
				$.cookie('closeBox-'+strTemp, '', { expires: -1, path: "/" });
			return false;
			  } else {
				$("#content-"+strTemp).slideUp();
				$(this).removeClass("link-collapse-active");
				$.cookie('showBox'+strTemp, 'expanded', { expires: 365, path: "/" });
				var unixTimestamp = Math.floor(new Date().getTime()/1000);
				$.cookie('closeBox-'+strTemp, unixTimestamp, { expires: 365, path: "/" });
			return false;
			}
		});
		// COOKIES
			// box State
			eval("var showBox"+strTemp+" = $.cookie('showBox"+strTemp+"')");		
			// Set the user's selection for the box State
			if (window.location.pathname == "/" || window.location.pathname == "/index.php") {
				if ( eval("showBox"+strTemp) == 'expanded') {
					$("#content-"+strTemp).hide();
					$(".btn-box-"+strTemp).removeClass("link-collapse-active");
				};
			}
		//resets the cookie for another 7 days
		$.cookie("showBox"+strTemp, $.cookie("showBox"+strTemp), { expires: 7, path: "/" });
	}
	
	//call the set home boxes function for the homepage
	setHomeBoxes("news");
	setHomeBoxes("competition");
	setHomeBoxes("games");
	setHomeBoxes("poll");
	setHomeBoxes("community");
	setHomeBoxes("downloads");
	setHomeBoxes("faqs");
	setHomeBoxes("members");
	setHomeBoxes("blog");
});


////////////////// IMAGE MOUSE OVER FADE //////////////////
$(document).ready(function(){
	$('#galleryImages a img').hover(
		function() { $(this).fadeTo('fast',0.8);},
		function() { $(this).fadeTo('fast',1);}
	);
});


////////////////// MOUSE OVER BUBBLES //////////////////
$(document).ready(function(){
	$("#footer .help-pop a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});
});

$(document).ready(function(){
	$(".achievement-icons a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});
});


////////////////// ACCORDION //////////////////
$(document).ready(function(){
	
	$("#accordion h3:first").addClass("active"); 
	$("#accordion div:not(:first)").hide(); 
	$("#accordion h3").click(function(){
		$(this).next("div").slideToggle("fast")
		.siblings("div:visible").slideUp("fast"); 
		$(this).toggleClass("active"); 
		$(this).siblings("h3").removeClass("active"); 
	}); 

}); 



////////////////// EXTERNAL SITES / OPEN NEW WINDOW //////////////////
$(document).ready( function() {
    $('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    }); 
});

