// JavaScript Document

$.fn.buildShadows = function(){

	$(".shadow").each(function(i){

		var plug = $(this).html();

		var spacer = "<img src='/content/images/spacer.gif' width='5' height='5' border='0'>";

		var topLeft = "<img src='/content/images/shadowTL.jpg' width='5' height='5' border='0' align='left' style='display:inline' />";

		var btmLeft = "<img src='/content/images/shadowBL.jpg' width='5' height='5' border='0' align='left' style='display:inline' />";

		var topRight = "<img src='/content/images/shadowTR.jpg' width='5' height='5' border='0' align='right' style='display:inline' />";

		var btmRight = "<img src='/content/images/shadowBR.jpg' width='5' height='5' border='0' align='right' style='display:inline' />";

		$(this).html("<table cellpadding='0' cellspacing='0' border='0'><tr><td colspan='3' id='shdwTop'>"+topLeft+topRight+"</td></tr><tr><td id='shdwLeft'>"+spacer+"</td><td id='shdwContent'>"+plug+"</td><td id='shdwRight'>"+spacer+"</td></tr><tr><td colspan='3' id='shdwBottom'>"+btmLeft+btmRight+"</td></tr></table>");

	});

}

$.fn.buildShadowsAlt = function(){

	$(".shadowNoTop").each(function(i){

		var plug = $(this).html();

		var spacer = "<img src='/content/images/spacer.gif' width='5' height='5' border='0'>";

		var topLeft = "<img src='/content/images/shadowTL.jpg' width='5' height='5' border='0' align='left' style='display:inline' />";

		var btmLeft = "<img src='/content/images/shadowBL.jpg' width='5' height='5' border='0' align='left' style='display:inline' />";

		var topRight = "<img src='/content/images/shadowTR.jpg' width='5' height='5' border='0' align='right' style='display:inline' />";

		var btmRight = "<img src='/content/images/shadowBR.jpg' width='5' height='5' border='0' align='right' style='display:inline' />";

		$(this).html("<table cellpadding='0' cellspacing='0' border='0'><tr><td colspan='3' id='shdwNoTop'>"+topLeft+topRight+"</td></tr><tr><td id='shdwLeft'>"+spacer+"</td><td id='shdwContent'>"+plug+"</td><td id='shdwRight'>"+spacer+"</td></tr><tr><td colspan='3' id='shdwBottom'>"+btmLeft+btmRight+"</td></tr></table>");

	});

}

$.fn.buildShadowsTextBox = function(){

	$(".shadowTextBox").each(function(i){

		var plug = $(this).html();

		var spacer = "<img src='/content/images/spacer.gif' width='5' height='5' border='0'>";

		var topLeft = "<img src='/content/images/shadowTL.jpg' width='5' height='5' border='0' align='left' style='display:inline' />";

		var btmLeft = "<img src='/content/images/shadowBL.jpg' width='5' height='5' border='0' align='left' style='display:inline' />";

		var topRight = "<img src='/content/images/shadowTR.jpg' width='5' height='5' border='0' align='right' style='display:inline' />";

		var btmRight = "<img src='/content/images/shadowBR.jpg' width='5' height='5' border='0' align='right' style='display:inline' />";

		$(this).html("<table cellpadding='0' cellspacing='0' border='0'><tr><td colspan='3' id='shdwTop'>"+topLeft+topRight+"</td></tr><tr><td id='shdwLeft'>"+spacer+"</td><td class='textBox' id='shdwContent'>"+plug+"</td><td id='shdwRight'>"+spacer+"</td></tr><tr><td colspan='3' id='shdwBottom'>"+btmLeft+btmRight+"</td></tr></table>");

	});

}



/**** SITE WIDE ****/

function clearTextBox(){

	$(this).val('');

}

function href(url){

	window.location = url;

}

function preLoadImages(){

	for(var i=0;i<arguments.length;i++){

		var img = new Image();

		img.src = arguments[i];

	}

}



/**** PACKAGES ****/

function showExtraImage(){

	var ei = $(this);
	var eiH = $(ei).attr("height");
	var eiW = $(ei).attr("width");
	var eiSRC = $(ei).attr("src");
	var percentH = (eiH/eiW);
	var h = percentH*200;
	var padH = (200-h)/2;
	var percentW = (eiW/eiH);
	var w = percentW*200;
	var padW = (200-w)/2;

	var mSRC = $(".mainImage").attr("src");
	var mi = $(".mainImage");
	var miH = $(mi).attr("height");
	var miW = $(mi).attr("width");


	if(w>h){

		w = 200;
		$(".mainImage").css("margin-top",padH+"px");
		$(".mainImage").css("margin-left","0");

	}else{
		h = 200;
		$(".mainImage").css("margin-top","0");
		$(".mainImage").css("margin-left",padW+"px");
	}
	
	if(miW>miH){
		$(ei).attr("height",45);
		$(ei).attr("width",60);
	}
	else{
		$(ei).attr("height",60);
		$(ei).attr("width",45);
	}



	$(".mainImage").css("display","none");
	$(".mainImage").attr("height",h);
	$(".mainImage").attr("width",w);
	$(".mainImage").attr("src",eiSRC);
	$(ei).attr("src",mSRC);
	$(".mainImage").fadeIn("fast");

}

function signUpRedirect(){

	window.setTimeout(function(){

		var email = document.getElementById('newsletterEmail');

		var emailFilter=/^.+@.+\..{2,3}$/;

		if(email.value!=''){

			if (!(emailFilter.test(email.value))){

				return false;

			}else{

				window.location = '/content/signup.php?email='+email.value;	

			}

		}

	},1000);

	return true;

}

function validate(formName){

	var f = document.forms[formName];

	for(var i=0;i<f.length;i++){

		var n = $(f[i]).attr('name');

		var field = $("label[@for='"+n+"']").text();

		if($(f[i]).val()=='' && $(f[i]).attr("class")!='not-required'){

			alert('Please fill in the '+field+' field!');

			return false;

		}

	}

	return true;

}

function toggle(showHideDiv, switchTextDiv) {
	var ele = document.getElementById(showHideDiv);
	var text = document.getElementById(switchTextDiv);
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = "<strong>read more...</strong>";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "<strong>read less...</strong>";
	}
}
