// NOTE : SOME DEFAULT GLOBAL VARIABLES ARE SET W/ PHP IN THE HEADER

// FUNCTION SET COOKIE
function setCookie(c_name,value) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+365);
	document.cookie = c_name+"="+escape(value)+";expires="+exdate.toGMTString()+";path=/";
}

// FUNCTION DELETE COOKIE
function deleteCookie(c_name) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()-355);
	document.cookie = c_name+"=;expires="+exdate.toGMTString()+";path=/";
}

// FUNCTION TOGGLE STUDY GUIDES
function togglestudyguides() {
	if (studyguidesviewable=='true') {
		studyguidesviewable='false';
		Effect.Fade('studyguides', .4);
		setTimeout("Effect.Appear('brand');",700);
		setCookie('studyguidesviewable', 'false');
	} else {
		studyguidesviewable='true';
		Effect.Fade('brand', .4);
		setTimeout("Effect.Appear('studyguides');",700);
		setCookie('studyguidesviewable', 'true');
	}
}

// FUNCTION SHOW VIDEO FORMAT OPTIONS
function showformatoptions(language) {
	if (language == 'es') {
		var low = 'Aja Resolución';
		var high = 'Alta Resolución';
	} else {
		var low = 'Low';
		var high = 'High';
	}
	
	var html ='<table border="0" cellpadding="5" align="center" style="margin-top: 72px;">';
	html +='<tr><td align="right">Flash :</td><td>';
	html +='<a href="/?format=flash&bandwidth=300">' + low + '</a> | <a href="/?format=flash&bandwidth=500">' + high + '</a>';
	html =='</td></tr>';
	html +='<tr><td align="right">Quicktime :</td><td>';
	html +='<a href="/?format=mov&bandwidth=300">' + low + '</a> | <a href="/?format=mov&bandwidth=500">' + high + '</a>';
	html +='</td></tr>';
	html +='<tr><td align="right">Windows Media :</td><td>';
	html +='<a href="/?format=wmv&bandwidth=300">' + low + '</a> | <a href="/?format=wmv&bandwidth=500">' + high + '</a>';
	html +='</td></tr>';
	document.getElementById('video').innerHTML = html;
	/* stopVideo; */
}

/*
HANDLE POPUP POSITIONING, WIDTH, AND HEIGHT
The following handles popup window positioning and dimensions.
It sets four global variables that can be used in popup links
*/

// INIT GLOBAL VARS WITH DEFAULT VALUES
var popupx = 50; // Horizontal placement of popup
var popupy = 50; // Vertical placement of popup
var popupwidth = 450; // Default width of popup
var popupheight = 700; // Default height of popup

function figurepopupinfos() {

	// DEFAULTS
	var popupoffsetx = 50; // Horizontal offset of right edge of popup to parent
	var popupoffsety = 50; // Vertical offset of top edge of popup to parent
	var minleftdiff = 350; // Minimum horizonal offset of left edge of popup to parent
	var screenmargin = 50; // Minimum margin on screen edges for popup to stay inside

	// FIGURE SCREENWIDTH, BROWSERWIDTH, AND BROWSERPOSITION
	if (parent.window.screenTop) {
		var browsery = parent.window.screenTop;
	} else {
		var browsery = parent.window.screenY;
	}
	if (parent.window.screenLeft) {
		var browserx = parent.window.screenLeft;
	} else {
		var browserx = parent.window.screenX;
	}
	var screenwidth = self.screen.width;
	var screenheight = self.screen.height;
	var browserwidth = parent.document.body.clientWidth;
	var browserheight = parent.document.body.clientHeight;

	// SET POPUP POSITION
	popupx = (browserx + browserwidth + popupoffsetx) - popupwidth;
	popupy = browsery + popupoffsety;

	// MAKE SURE IT FITS IN TOP/LEFT MARGINS
	if ( popupx < screenmargin ) { popupx = screenmargin; }
	if ( popupy < screenmargin ) { popupy = screenmargin; }

	// MAKE SURE IT IS A MIN DISTANCE FROM THE LEFT SIDE OF THE PARENT WINDOW
	if ((popupx < browserx) || (popupx - browserx < minleftdiff)) {
		popupx = browserx + minleftdiff;
	}

	// MAKE SURE IT FITS IN RIGHT/BOTTOM MARGINS
	if ( (popupx + popupwidth) > (screenwidth - screenmargin) ) { popupx = screenwidth - popupwidth - screenmargin; }
	if ( (popupy + popupheight) > (screenheight - screenmargin) ) { popupy = screenheight - popupheight - screenmargin; }

}

/*************************** Menu Management Functions ***********************
 * Require jQuery. Tested with 1.2.1
 * 
 *****************************************************************************/
var	language_trigger_on = false;
var language_menu_on = false;
var chapter_trigger_on = false;
var chapter_menu_on = false;
var purchase_trigger_on = false;
var purchase_menu_on = false;

function languageMenuOn() {
	if (!language_trigger_on || !language_menu_on) {
		jQuery('#language-menu').fadeIn("slow");
	}
}

function languageMenuOff() {
	this.menuTimer = setTimeout(function(){
		if (!language_trigger_on && !language_menu_on) {
			jQuery('#language-menu').fadeOut("slow");
		}			
		}, 800);
}

function chapterMenuOn() {
	if (!chapter_trigger_on || !chapter_menu_on) {
		jQuery('#chapter-menu').fadeIn("slow");
	}	
}

function chapterMenuOff() {
	this.menuTimer = setTimeout(function(){
		if (!chapter_trigger_on && !chapter_menu_on) {
			jQuery('#chapter-menu').fadeOut("slow");
		}			
		}, 800);
}

function purchaseMenuOn() {
	if (!purchase_trigger_on || !purchase_menu_on) {
		jQuery('#purchase-menu').fadeIn("slow");
	}	
}

function purchaseMenuOff() {
	this.menuTimer = setTimeout(function(){
		if (!purchase_trigger_on && !purchase_menu_on) {
			jQuery('#purchase-menu').fadeOut("slow");
		}			
		}, 800);
}



jQuery(document).ready(function() {

	/* Language menu on/off */
	jQuery('#language-trigger').hover(function(){
		language_trigger_on = true;
		languageMenuOn();
	}, function() {
		language_trigger_on = false;
		languageMenuOff();
	});

	jQuery('#language-menu').hover(function(){
		language_menu_on = true;
		languageMenuOn();
	}, function(){
		language_menu_on = false;
		languageMenuOff();
	});

	/* Chapter menu on/off */
	jQuery('#chapter-trigger').hover(function(){
		chapter_trigger_on = true;
		chapterMenuOn();
	}, function() {
		chapter_trigger_on = false;
		chapterMenuOff();
	});

	jQuery('#chapter-menu').hover(function(){
		chapter_menu_on = true;
		chapterMenuOn();
	}, function(){
		chapter_menu_on = false;
		chapterMenuOff();
	});	

	/* Purchase menu on/off */
	jQuery('#purchase-trigger').hover(function(){
		purchase_trigger_on = true;
		purchaseMenuOn();
	}, function() {
		purchase_trigger_on = false;
		purchaseMenuOff();
	});

	jQuery('#purchase-menu').hover(function(){
		purchase_menu_on = true;
		purchaseMenuOn();
	}, function(){
		purchase_menu_on = false;
		purchaseMenuOff();
	});


	/*
	jQuery('#flash-intro').html('');

	jQuery('#flash-intro').flash({
		src: '/assets/flash/site_introduction.swf',
		width: 400,
		height: 400
	});
	*/
});











