/* ////////////////////////////////////////////////////////

   JAVASCRIPT FUNCTIONS FOR econnect
   econnect-specific functions for client-side JavaScript.

//////////////////////////////////////////////////////// */

// Content area dimensions for econnect Flash-based sites
var econnect_flash_x = 715;
var econnect_flash_y = 680;
var econnect_new_x = 848;
var econnect_new_y = 758;


// Function for Flash files to incorporate JavaScript functionality into links
function eConnectFlashLinks(link) {

	// URL string for redirect
	var url;
	
	// Maximum length of link value to take as straight URL
	var link_max = 100;
	
	// Parameters for new windows
	var window_specs_full =			"width=" + screen.availWidth + ",height=" + screen.availHeight +
									",top=0,left=0,location=no,menubar=no,resizable=no," +
									"scrollbars=yes,status=yes,titlebar=yes,toolbar=no";
	// Set window_specs_flash equal to window_specs_full on smaller screens
	if (screen.availHeight < (econnect_flash_y + 80) || screen.availWidth < (econnect_flash_x + 10)) {
		var window_specs_flash = window_specs_full;
	}
	else {
		var window_specs_flash =	"width=" + econnect_flash_x + ",height=" + econnect_flash_y + "," +
									"top=" + (Math.floor((screen.availHeight-econnect_flash_y)/2)) + "," +
									"left=" + (Math.floor((screen.availWidth-econnect_flash_x)/2)) + "," +
									"location=no,menubar=no,resizable=no," +
									"scrollbars=no,status=yes,titlebar=yes,toolbar=no";
	}
	var window_specs_new =	"width=" + econnect_new_x + ",height=" + econnect_new_y + "," +
									"top=" + (Math.floor((screen.availHeight-econnect_new_y)/2)) + "," +
									"left=" + (Math.floor((screen.availWidth-econnect_new_x)/2)) + "," +
									"location=no,menubar=no,resizable=yes," +
									"scrollbars=yes,status=yes,titlebar=yes,toolbar=no";
	var window_specs_normal = "";
	var window_specs = window_specs_normal;

	// Boolean for handling links that should open in parent window
	var parent_window;
	if (window.opener) {
		parent_window = true;
	}
	else {
		parent_window = false;
	}
	
	// Boolean for handling links that should open in same window
	// This can also be set on a page-specific basis in switch below
	var same_window = true;

	// Boolean for altering links based on whether or not user is logged in
	var logged_in = true;
	/*
	if (!getCookie("saved-login")) {
		logged_in = false;
	}
	*/

	// Match link value against predefined values
	if (link)
	{
		switch (link)
		{
	
			// Simply reload the Learner Center in opening window and close the current window
			case "close":
				if (parent_window && !window.opener.closed) {
					window.opener.location.href = "";
					window.close();
				}
				return;
				break;

			// Home page of current site
			case "home":
				url = "/";
				same_window = true;
				break;

			// Help page
			case "help":
				url = "/help.php";
				break;

			// Contact page
			case "contact":
				url = "/customerservice.php";
				break;

			// Copyright page
			case "copyright":
				url = "/copyright.php";
				parent_window = true;
				same_window = false;
				window_specs = window_specs_normal;
				break;

			// Membership Agreement page
			case "agreement":
				url = "/agreement.php";
				parent_window = true;
				same_window = false;
				window_specs = window_specs_normal;
				break;

			// Privacy Policy page
			case "privacy":
				url = "/privacy.php";
				parent_window = true;
				same_window = false;
				window_specs = window_specs_normal;
				break;

			// Terms of Use page
			case "terms":
				url = "/terms.php";
				parent_window = true;
				same_window = false;
				window_specs = window_specs_normal;
				break;

			// Trial Terms page
			case "trialterms":
				url = "/trialterms.php";
				parent_window = true;
				same_window = false;
				window_specs = window_specs_normal;
				break;

			// econnect main site
			case "econnect":
				url = "http://" + location.host;
				parent_window = true;
				same_window = false;
				window_specs = window_specs_normal;
				break;

			// Ages 3-4 learner site
			case "econage34":
				if (logged_in) {
					url = "/econage34/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
				
			case "econage34-demo":
				if (logged_in) {
					url = "/econage34-demo/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			// Grade K learner
			case "econgk":
				if (logged_in) {
					url = "/econgk/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			case "econgk-demo":
				if (logged_in) {
					url = "/econgk/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			// Grade 1 learner site
			case "econg1":
				if (logged_in) {
					url = "/econg1/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			// Grade 2 learner site
			case "econg2":
				if (logged_in) {
					url = "/econg2/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			// Grade 3 learner site
			case "econg3":
				if (logged_in) {
					url = "/econg3/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			// Grade 4 learner site
			case "econg4":
				if (logged_in) {
					url = "/econg4/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			// Grade 5 learner site
			case "econg5":
				if (logged_in) {
					url = "/econg5/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			case "econg5-demo":
				if (logged_in) {
					url = "/econg5-demo/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			// Grade 6 learner site
			case "econg6":
				if (logged_in) {
					url = "/econg6/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			// Grade 7 learner site
			case "econg7":
				if (logged_in) {
					url = "/econg7/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;

			case "econg7-demo":
				if (logged_in) {
					url = "/econg7-demo/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			// Grade 8 learner site
			case "econg8":
				if (logged_in) {
					url = "/econg8/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			
			// Grades 9-12 learner site
			case "econg912":
				if (logged_in) {
					url = "/econg912/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_flash;
				}
				break;
			
			case "econg912-demo":
							if (logged_in) {
								url = "/econg912-demo/";
								parent_window = false;
								same_window = false;
								window_specs = window_specs_flash;
							}
				break;

			// Adult Intro learner site
			case "econad":
				if (logged_in) {
					url = "/econad/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_new;
				}
				break;

			case "econfamily":
				if (logged_in) {
					url = "/econfamily/";
					parent_window = false;
					same_window = false;
					window_specs = window_specs_new;
				}
				break;
			
			case "econad-demo":
							if (logged_in) {
								url = "/econad-demo/";
								parent_window = false;
								same_window = false;
								window_specs = window_specs_new;
							}
				break;

			// Harcourt Religion Publishers home page
			case "hrp":
				url = "http://www.harcourtreligion.com/";
				// Force page to load in new window
				parent_window = true;
				same_window = false;
				break;
			
			// Default: treat link as a straight URL
			default:
				// Value must be less than link_max in length and start with "/" or "http" to be valid
				if (link.length <= link_max && (link.indexOf("/") == 0 || link.indexOf("http") == 0))
				{
					url = '/' + link + '/';
					// Set to load in same window if same domain
					if (link.indexOf("/") == 0 || link.indexOf(location.host) != -1)
					{
						same_window = false;
						parent_window = false;
					}
				}
				else {
					url = null;
				}
				break;
		}
	}
	
	// Redirect to new URL
	if (url) {
		if (same_window) {
			location.href = url;
		}
		else if (parent_window && window.opener && !window.opener.closed) {
			window.opener.location.href = url;
			window.opener.focus();
			return;
		}
		else {
			window.open(url,null,window_specs);
			return;
		}
	}
	else {
		return;
	}
}




/* Image Preloader
 * Ver. 1.0 2007-07-15
 * Use:
 	// Set up a unique array for each image set:
		var navImageArray = new Array();
	// Create the associative array - use the non-rolled-over image IDs with the the rolled-over src versions
		navImageArray['head_art'] = 'images/head_art_on.gif';
		navImageArray['head_videos'] = 'images/head_videos_on.gif';
 */
var econnectImagePreloader = new Image(); // Set up a preloader object

function econnectPreloadImages(imageArray) {
	// Run through the list and preload the images
	for (var i in imageArray) {
		econnectImagePreloader.src = imageArray[i];
	}
}




/* Image Rollover Script
 * Ver 1.0 2007-07-15
 * Uses and associative image array to display rollovers
 * THIS SCRIPT RELIES ON THE econnectImagePreloader FUNCTION
	// HTML snippet:
		<img src="images/head_art_off.gif" alt="Art" width="44" height="38" id="head_art" onmouseover="rolloverImages(this,1);" onmouseout="rolloverImages(this,0);" />
 */

var econnectLastRolledImage = new Array(); // Set up the original image array

function econnectRolloverImages(imageThis,status)
{
	if (status) {
		// Get the index name (since it's the same as the image id)
		econnectLastRolledImage[imageThis.id] = document.images[imageThis.id].src;
		document.images[imageThis.id].src = navImageArray[imageThis.id];
	} else {
		document.images[imageThis.id].src = econnectLastRolledImage[imageThis.id];
	}
}
