/** Javascript for Kidlandia. Included in kidlandia.master for all pages to use **/

// Img rollovers follow a convention named 'UP' and 'OVER' for regular and rollover respectively
// Imgs are preloaded in master page to let them be loaded before the body is.   
function up(img) {
	document.getElementById(img).src = eval(img + 'Up').src;
}
function over(img) {
	document.getElementById(img).src = eval(img + 'Over').src;
}
function combineurls(u1, u2) {
	if (u1.length > 0 && u1[u1.length - 1] == '/')
		u1 = u1.substr(0, u1.length - 1);
	if (u2.length > 1 && u2[0] == '/')
		u2 = u2.substring(1);
	return u1 + '/' + u2;
}

// -----------------------------------------------------------------------------
// Kidlandia Globals 
// myFlashVars to pass parameters to/from main Flash object
var myFlashVars = "";
// base url for easy navigation regardless of environment
var BASEURL = "";
// -----------------------------------------------------------------------------

/* common method to deal with warning users if they exits a page without saving */
window.onbeforeunload = exitCheck;
function exitCheck() {
	// ask the main flash movie if its ok to leave
	var movieId = getFlashMovieObject("PrimaryDisplayObject");
	if (movieId != null) {
		if (movieId.ShowExitWarning() == "true") {
			return "Your map has not been saved, changes will be lost.";
		}
	}
};


// common get started method that anyone can use if needed
function getStarted() {
	var url = combineurls(BASEURL, "/Map.aspx");
	window.location.href = url;
};

function clearText(thefield) {
	if (thefield.defaultValue == thefield.value)
		thefield.value = ""
}

// common show swf logo method that anyone can use if needed. Its included in master and masternofooter
function showLogo() {
	var width = 200;
	var height = 140;
	var mode = "transparent";
	var id = "logomovi";
	var src = BASEURL + '/assets/KL_Logo';
	var flashvars = "BASEURL=" + BASEURL;
	var altcontent = "";
	showSwf(width, height, mode, id, src, flashvars, altcontent);
};

// common method to show featured map swf (also used by share map as they are one and the same for now.
function showFeaturedMap() {
	var width = "100%";
	var height = "100%";
	var mode = "transparent";
	var id = "PrimaryDisplayObject";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/PrimaryDisplayObject");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent);
};



// method to show the map maker
function showMapMaker() {
	var width = "100%";
	var height = "100%";
	var mode = "transparent";
	var id = "PrimaryDisplayObject";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/PrimaryDisplayObject");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent);
};

function showKingdoms() {
	var width = "100%";
	var height = "100%";
	var mode = "window";
	var id = "PrimaryDisplayObject";
	var name = "MyKingdom";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/MyKingdom");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent, name);
};

function showPbkPopup() {
	var width = "100%";
	var height = "100%";
	var mode = "window";
	var id = "PrimaryDisplayObject";
	var name = "PBK_Popup";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/pbk_popup");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent, name);
};

function showDisneyStore() {
	var width = "100%";
	var height = "100%";
	var mode = "window";
	var id = "PrimaryDisplayObject";
	var name = "DisneyStore";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/DisneyStore");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent, name);
};

function showFacebook() {
	var width = "100%";
	var height = "100%";
	var mode = "window";
	var id = "PrimaryDisplayObject";
	var name = "Facebook";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/Facebook");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent, name);
};

function showNgPopup() {
	var width = "100%";
	var height = "100%";
	var mode = "transparent";
	var id = "PrimaryDisplayObject";
	var name = "NG_Popup";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/ng_popup");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent, name);
};

function showGenericEmbed() {
	var width = "100%";
	var height = "100%";
	var mode = "window";
	var id = "PrimaryDisplayObject";
	var name = "GenericEmbed";
	var altcontent = "";
	var src = combineurls(BASEURL, "/assets/GenericEmbed");
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent, name);
};
// method to show the homepage swf (this will go away with version 2.2)
function showHome() {
	var width = 956;
	var height = 530;
	var mode = "window";
	var id = "KL_HomeV1";
	var src = combineurls(BASEURL, '/assets/KL_HomeV1');
	var altcontent = "";
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent);
};
// method to show the homepage swf on new default.aspx
function showDefault() {
	var width = 601;
	var height = 423;
	var mode = "window";
	var id = "KL_Home_IllustrationMain";
	var src = combineurls(BASEURL, '/assets/homepage');
	var altcontent = "<div id='mainnocontent' class='likidlandia'></div>";
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent);
};
// method to show tradingcard swf on new default.aspx
function showCards() {
	var width = 200;
	var height = 287;
	var mode = "window";
	var id = "KreechurCards";
	var src = combineurls(BASEURL, '/assets/KreechurCards');
	var altcontent = "<div id='cardsnocontent' class='litradingcard'></div>";
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent);
};
// method to show howto swf on new default.aspx
function showHowTo() {
	var width = "100%";
	var height = "100%";
	var mode = "transparent";
	var id = "KL_Home_HowtoVideo";
	var src = combineurls(BASEURL, '/assets/KL_Home_HowtoVideo');
	var altcontent = "";
	// hook mouse wheel to prevent browser scrolling on mouse wheel when inside flash ( NOT WORKING ! )
	hookMouseWheel();
	showSwf(width, height, mode, id, src, myFlashVars, altcontent);
};
// methods to show and hide popups
function showPopUp(divid) {
	var cvr = document.getElementById("cover");
	var pop = document.getElementById(divid);
	cvr.style.display = "block";
	pop.style.display = "block";
	/*    if (document.body.style.overflow = "hidden") {
	cvr.style.width = "1024";
	cvr.style.height = "100%";
	}*/
}
function closePopUp(divid) {
	var cvr = document.getElementById("cover");
	var pop = document.getElementById(divid);
	cvr.style.display = "none";
	pop.style.display = "none";
	//    document.body.style.overflowY = "scroll";
}

// common rollover functionality 
function roll(img_name, img_src) {
	var btn = document.getElementById(img_name);
	if (btn != null)
		btn.src = img_src;
};

function rollover() {
	if (!document.getElementById) return;
	var imgOrSrc;
	var imgPreload = new Array();
	var images = document.getElementsByTagName('img');
	for (var i = 0; i < images.length; i++) {
		if (images[i].getAttribute('rsrc')) {
			imgPreload[i] = new Image();
			imgPreload[i].src = images[i].getAttribute('rsrc');
			images[i].onmouseover = function () {
				imgOrSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('rsrc'))
			}
			images[i].onmouseout = function () {
				this.setAttribute('src', imgOrSrc)
			}
		}
	}
}

if (window.addEventListener) //DOM method for binding an event
	window.addEventListener("load", rollover, false)
else if (window.attachEvent) //IE exclusive method for binding an event
	window.attachEvent("onload", rollover)
else if (document.getElementById) //support older modern browsers
	window.onload = rollover

