$(document).ready(function(){	
						   
	loadContent();
	
});


function loadContent()
{	

	var languageFromBakugan = getParameterByName("lang");	
	if(languageFromBakugan != "") $.cookie("lang", languageFromBakugan, {path: "/", domain:".bakugan.com"});	
	if($.cookie("lang") == null) $.cookie("lang", "en-us", {path: "/", domain:".bakugan.com"});
					
	var content = $("#bottomContent");
	var footer = $("#footer");
	
	var url = /(https?:\/\/[^\/]+)/.exec(window.location.href)[1] + "/"+$.cookie("lang")+"/"+section+"/"+page+".html";	
	var url1 = url+" #bottomContent";
	var url2 = url+" #footer";
	
	content.load(url1);
	footer.load(url2);
		
	embedFlash();
	bannerSwap();
	
}

function embedFlash()
{
	
	var contentURL = "/";	
	var flashDiv = (swf.indexOf("subsection") == -1) ? "flashContent" : "flashContentSubsection";
	var flashHeight = (swf.indexOf("subsection") == -1) ? "485" : "200";
					
	var flashvars = {};
	flashvars.swf = swf+".swf";
	flashvars.lang = $.cookie("lang");
	flashvars.contentURL = contentURL;
	flashvars.section = section;
	flashvars.page = page;	
	flashvars.appURL = returnDomain();
	if(section == "connect") flashvars.articleID = getParameterByName("article_id");
	
	var params = {};
	params.menu = "false";
	params.quality = "high";
	params.wmode = "opaque";
	params.scale = "noscale";
	params.bgcolor = "#000000";
	params.allowscriptaccess = "always";
	params.allownetworking = "external";
	var attributes = {};
	attributes.id = "preloader";
	attributes.name = "preloader";
	swfobject.embedSWF("/preloader.swf", flashDiv, "100%", flashHeight, "10.0.0", null, flashvars, params, attributes);
	
	if (!swfobject.hasFlashPlayerVersion("10.0.0"))
	{
		window.location = '/getflash.html';
	} 
			
}

function focusFlashMovie()
{
	
	if(window.document.preloader) window.document.preloader.focus();	
	
}


function changeLanguage(which)
{
			
	$.cookie("lang", which, {path: "/", domain:".bakugan.com"});
	
	var content = $("#bottomContent");
	var footer = $("#footer");
	
	var url = /(https?:\/\/[^\/]+)/.exec(window.location.href)[1] + "/"+$.cookie("lang")+"/"+section+"/"+page+".html";	
	var url1 = url+" #bottomContent";
	var url2 = url+" #footer";
	
	content.load(url1);	
	footer.load(url2);
		
}


function getParameterByName( name ) 
{ 
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp( regexS ); 
	var results = regex.exec( window.location.href ); 
	if( results == null ) 
		return ""; 
	else 
		return results[1]; 
} 

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openTutorial(theURL, winName) {
	
	var ratio;
	var screenWidth = screen.width;
	var screenHeight = screen.height;
	
	var windowWidth = 1025;
	var windowHeight = 770;
	
	if(windowWidth > screenWidth){
		
		ratio = screenWidth / windowWidth;
		windowWidth *= ratio;
		windowHeight *= ratio;
				
	}
	
	if(windowHeight > screenHeight) {
		
		ratio = screenHeight / windowHeight;		
		windowWidth *= ratio;
		windowHeight *= ratio;
		
	}
	
	windowWidth = Math.floor(windowWidth);
	windowHeight = Math.floor(windowHeight);
	
	var string = "width="+windowWidth+",height="+windowHeight;
	
	window.open(theURL,winName,string);	
	
}

function returnDomain() {
	
	var url = /(https?:\/\/[^\/]+)/.exec(window.location.href)[1].split("http://").join("").split("https://").join("");
	return url;
	
}

function bannerSwap() {
	var whichImage = 0;
	window.setInterval(function() {
		if (whichImage == 0) {
			$(".banner1").show();
			$(".banner2").hide();
			whichImage = 1;
		}
		else {
			$(".banner2").show();
			$(".banner1").hide();
			whichImage = 0;
		}
	}, 3000);
}

