
$(document).ready(function() {
	// for customer care page
	// when user type is toggled
	setInterval('swapImages()', 7000);
	$('#userType').change(function() {
		if($('#userType').val() == "technology") {
			$('.techUsersOnly').show();
		} else {
			$('.techUsersOnly').hide();
		}
	});

	$('#contactTypeSelect').change(function() {
		if($('#contactTypeSelect').val() == "customer-care") {
			$('#contact-us-general').hide();
			$('#contact-us-customer').show();
		} else {
			$('#contact-us-general').show();
			$('#contact-us-customer').hide();
		}
	});

});


var selectedState = '<?=$state_var?>';
var currentPath = window.location.pathname;

function hideOne(idToHide)
{
	hideTarget = document.getElementById(idToHide);
	hideTarget.style.display = 'none';
}

function showOne(idToshow)
{
	showTarget = document.getElementById(idToshow);
	showTarget.style.display = 'block';
}

function hideAllBut(section)
{
	switch(section)
	{
		case 'test':
			hideOne('collegeDropdown');
			hideOne('button-college-highlight');
			break;
		case 'college':
			hideOne('testDropdown');
			hideOne('button-test-highlight');
			break;
	}
	
	
	
	
}

function hideOneVisibility(idToHide)
{
	hideTarget = document.getElementById(idToHide);
	hideTarget.style.visibility= 'hidden';
}

function showOneVisibility(idToshow)
{
	showTarget = document.getElementById(idToshow);
	showTarget.style.visibility = 'visible';
}

function setWidth(idToSet, desiredWidth)
{
	changeTarget = document.getElementById(idToSet);
	changeTarget.style.width = desiredWidth;
}




function changeStatePDF(stateCode)
{	
	eraseCookie('kaplanState');
	createCookie('kaplanState',stateCode,60);
	window.location = "/changeState.php?state="+stateCode+"&current="+currentPath+"&pricelist=true";
}

function changeState(stateCode)
{	
	eraseCookie('kaplanState');
	createCookie('kaplanState',stateCode,60);
	window.location = "/changeState.php?state="+stateCode+"&current="+currentPath;
}

function pauseComp(millis) 
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); } 
	while(curDate-date < millis);
}

function changeBookImage(section,newImage)
{
	var target = document.getElementById('bookImagePicture');
	newSource = '/images/book-covers/' + section + '/' + newImage;
	//alert('and!' + newSource);
	target.src = newSource;
	
	
	
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }
 
 function getIntroCookie() {
  /*var text = document.htmlForm.sendField.value;*/
  var skipIntro = readCookie('kaplanSkipIntro');
  document.getElementById("home").sendTextToFlash(skipIntro);
  
 }
 
 function getTextFromFlash(str) {
  /*document.htmlForm.receivedField.value = "From Flash: " + str;
  return*/ alert( str + " received" );
 }



function resizeContent()
{
	// get the size
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    
  } else if( document.body && document.body.clientWidth  ){
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    
  }
  
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
    itsIE = false;
	
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
	itsIE = true;
    
  } else if( document.body && document.body.clientHeight  ){
    //IE 4 compatible
    myHeight = document.body.clientHeight;
    itsIE = true;
  }

	var wrapperDiv = document.getElementById('mainContainerWithTree');
	wrapperDiv.style.width = "960px";
	wrapperDiv.style.marginLeft = "auto";
	
}


function gotoProduct(prodID,section,subsection,prodName,state_var)
{
	/*
	var subInput = document.getElementById('prodID');
	subInput.value = prodID;
	
	var subForm = document.getElementById('menuChoice')
	subForm.action = '/'+state_var+'/'+section+'/'+subsection+'/'+prodName;
	subForm.submit();
	*/

	window.location = '/'+state_var+'/'+section+'/'+subsection+'/'+prodName;

	
}

function swapImages(){
	var $active = $('#myGallery .active');
	var $next = ($('#myGallery .active').next().length > 0) ? $('#myGallery .active').next() : $('#myGallery img:first');
	$active.fadeOut(function(){
	$active.removeClass('active');
	$next.fadeIn().addClass('active');
	});
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
