var n = 12;
var version = $.browser.version.number();
var isNetscape = $.browser.netscape();
var isOpera = $.browser.opera();

			
$(function(){ 
	
		//e-postcards
		fnPostcards();

/* Flash messages on design a trainer launcher page */

	if (flash.installed && flash.version >= 8) {
		$("#noFlashContent").hide();
		$("#flashContent").removeClass("hide");
	}
      		
/* Info Boxes */
	if(isOpera==false){
	$('.infoWrap').addClass('js');
	//hide all info boxes
	$('.infoWrap').hide();
	//remover the href because safai doesn't return false
	$('a.info').removeAttr('href');
	$('a.info').click(function(event){
		//this would be ok but safari still uses the jumplink
		//var targ = $(this).attr('href');
		// so we use this instead
		var targ = $(this).parent().next('.infoWrap')
		$(targ).toggle();
		return false;
		
	});
}
	
/* Text sizing */

if(isNetscape==true && version<8){
	//
	}else{
		fnResize();
	}
});

$.jqem.bind(function(a,b,c) {
	if(isNetscape==true && version<8){
		//
		}else{
			fnResize();
		}
		

		
});

/* Changes class based on the text size */
fnResize = function(){
	if( $.jqem.current() == n ) {
		//alert($.jqem.current())
		$('#wrapper').removeClass('defaultText');
		$('#wrapper').addClass('graphicText');
		}else if($.jqem.current() != n){
			//alert($.jqem.current());
		$('#wrapper').removeClass('graphicText');
		$('#wrapper').addClass('defaultText');
		};
	};


// Opens the link in a new window.
// Usage: <a href="http://www.google.com" onclick="return fnNewWindow(this)">Google</a>
function fnNewWindow(targ) {
	window.open(targ.href);	
	return false;
}


// e postcards

fnPostcards = function(){
	
	//variables
	
	var largeImages = new Array(
	'images/postcards/postcard1.jpg',
	'images/postcards/postcard2.jpg',
	'images/postcards/postcard3.jpg',
	'images/postcards/postcard4.jpg'
	);
	
	var picker = $('.imagePicker .thumbs a');
	var mainImage = $('.lrgImage img');
	var nextLink = $('#nextBtn');
	
	picker.click(
		function(){
			var p = picker.index(this);
			var imgPath = largeImages[p];
			var nextStep = '?step=2&image=' + p;
			
			picker.removeClass('selected');
			
			$(this).addClass('selected');
			
			mainImage.attr("src", imgPath);
			
			nextLink.attr("href", nextStep);
			
			return false;
		}
	)
}



/********************************************************************************

Name:     Flash plugin detect

*********************************************************************************/
var flash = new Object();	
flash.installed = false;
if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {		
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {		
			flash.installed = true;					
			flash.version = eval(navigator.plugins[x].description.split('Shockwave Flash ')[1].split('.')[0]);					
			break;
		}
	}
}
else if (window.ActiveXObject) {
	for (x = 2; x <= 20; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {		
				flash.installed = true;	
				flash.version = x;
			}
		}
		catch(e) {}
	}
}

	
/********************************************************************************
 
Name:     			Flash embed
Description:  		Writeout flash code. Fixes Eolas update for IE as well.
@param swf  		String - path to swf file
@param width     	Number - value of movie width
@param height    	Number - value of movie height
@param noFlashID	String - ID of a div to show if flash not installed or wrong version
@param minVersion	Number - version of flash required for this movie
*********************************************************************************/
 
flash.insert = function(swf,width,height,noFlashID,minVersion) {
	swf = swf.replace(/\./g,"%2E") // encode periods as %2e	
	
	if(!minVersion){minVersion = 6;}		 // default flash required version is 6.
	
 	if(flash.installed && (flash.version >= minVersion)) {
 		flashObject = '<embed src="'+swf+'" menu="false" quality="high" width="'+width+'px" height="'+height+'px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" bgcolor="#ffffff"/>'
		document.write(flashObject);
		
		if (noFlashID) {
			$("#"+noFlashID).hide();	
		}
	} 
}


/********************************************************************************

Name:     fnPopup
Description: Standard popup, but takes target from href on link.  Scrollbars are 
hidden unless screen resolution is less than 1024 x 768, when scrollbars are present.
Usage: <a href="href" onclick="return fnPopup(this,800,600)">Pop me</a>
*********************************************************************************/

function fnPopup (targ, width, height) {
	var sScreenX = screen.width;
	var sScreenY = screen.height;
	var x = sScreenX - width;
	var y = sScreenY - height;
	var winLeft = x/2;
	var winTop =  y/2;	
	var scrollStatus = "no";

	if (!(screen.width >= 1024 && screen.height >= 768)) {
  	var scrollStatus = "yes";
	}

	window.open(targ.href, "", "width=" + width + ",height="+ height + ",scrollbars=" + scrollStatus + ",left=" + winLeft + ",top=" + winTop + ",resizable=yes, status=no");	
	return false;
}

