// JavaScript Document
// register onclick events for search_tips div show hide
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function fix_IE_flicker() {
	//window.alert("called fix_IE_flicker()");
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}	
}

function getFlashMovie(movieName) {
	//window.alert("called getFlashMovie()");
	try {
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		return (isIE) ? window[movieName] : document[movieName];
	} catch(e) {}
}



function modal_load(popuptype) {
	//window.alert("called modal_load: " + popuptype);
	try {
		var modal_flash = $("header_embed");
		if(modal_flash) {
			getFlashMovie("header_embed").modal_load(popuptype);
		} else {
			window.alert("didn't find modal_flash");
		}
	} catch(e) {}
}




// give 5 star ratings to movies
function rate(product_ID, stars) {
	var params = new Array;
	params["product_ID"] = product_ID;
	params["stars"] = stars;
	var options = {
		method : 'post',
		parameters : params
	};
	new Ajax.Request('ajax_star_rating.cfm', options);
	
	// var widthLI = document.getElementById("ul_" + request_ID);
	$("ul_" + product_ID).setStyle({width: stars * 20 + "%"});
}

//check for Vista in checkout and then use conditional comments in markup to show instructions to add to Trusted Sites so IE install will work
function vista_check() {
	//window.alert("called vista_check()");
	try {
		var on_checkout = $("delivery_manager_download_vista");
		if(on_checkout) {
			if (navigator.userAgent.indexOf("Windows NT 6.0")) {
				$("delivery_manager_download_vista").style.display = "block";
				//window.alert("using Vista");
			} 
			// run Widevine polugin check
			idm_init();
		}
	} catch(e) {}
}

addLoadEvent(fix_IE_flicker);
//addLoadEvent(modal_init);
//addLoadEvent(modal_close);
addLoadEvent(vista_check);
//addLoadEvent(initModal);
//addLoadEvent(assign_toggle_login);
//addLoadEvent(initSearchFlash);
//addLoadEvent(show_beta_welcome);



// resize divs

/* 
Methods for resizing the flash stage at runtime.

setFlashWidth(divid, newW)
divid: id of the div containing the flash movie.
newW: new width for flash movie

setFlashWidth(divid, newH)
divid: id of the div containing the flash movie.
newH: new height for flash movie

setFlashSize(divid, newW, newH)
divid: id of the div containing the flash movie.
newW: new width for flash movie
newH: new height for flash movie

canResizeFlash()
returns true if browser supports resizing flash, false if not. 
*/
/*function setFlashWidth(divid, newW){
	//console.log("called setFlashWidth");
	$(divid).style.width = newW+"px";
}*/
function setFlashHeight(object_ID, embed_ID, newH){
	//console.log("setFlashHeight" + object_ID + newH);
	var object = $(object_ID);
	var embed = $(embed_ID);
	var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	//var docHeight = 0;
	//getScrollXY();
	//window.alert("windowHeight is " + windowHeight + " : docHeight is " + scrOfY);
	
	if(object) {
		$(object_ID).height = newH; 
	} 
	if (embed) {
		$(embed_ID).height = newH; 
	}
	
	if (newH == "30") { newH = "30px"; }
	else { newH = windowHeight - 140 + "px" }
	
	$("header").setStyle({height: newH});
	//$("header_flash_wrapper").setStyle({height: newH});
	
	// hide star ratings temporarily when showing dialogs
	//Effect.toggle('reviews_user', 'appear');
}

function window_height()
{
	var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	try {
		var modal_flash = $("header_embed");
		if(modal_flash) {
			getFlashMovie("header_embed").window_height(windowHeight);
		} else {
			window.alert("didn't find modal_flash");
		}
	} catch(e) {}
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		window.alert( 'window.pageYOffest' );
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		window.alert( 'document.body.scrollTop' );
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		window.alert( 'document.documentElement.scrollTop' );
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	window.alert( 'Horizontal scrolling = ' + scrOfX + '\nVertical scrolling = ' + scrOfY + '\npageYOffset = ' + window.pageYOffset  );
}

/*function setFlashSize(divid, newW, newH){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
}
function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	if( document.getElementById ){
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	return false;
}*/


var state = 'none';
function showhide(layer_ref) {
	if (state == 'block') {
		state = 'none';
	}
	else {
		state = 'block';
	}
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state;
	}
	
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.display = state;
	}
}

/*function modal_init() {
	//window.alert("called modal_init");
	try {
		var modal_container = $("modal_container");
		
		if (modal_container) {
			swfobject.embedSWF("popup.swf", "modal_flash", "806", "370", "9.0.0","flash/expressInstall.swf", flashvars, params, attributes);
		}
	} catch(e) {}
}*/

/*function modal_close() {
	//window.alert("called close_modal");
	var modal_container = $("modal_container");
	if (modal_container) {
		Effect.Fade("modal_container", { from: 1, to: 0.01, duration: .3 });	
		modal_container.style.top = "-10000px";
	}
}*/