$(document).ready(function() {

if ($("#pfam").val()) {
var plocation = $("#pfam").val().toLowerCase()
var mcol = "#402dcd";

        switch(plocation)
        {
            case "general": mcol = "#402dcd";
            break;
            case "products": mcol = "#8dd820";
            break;
            case "content": mcol = "#705ff4";
            break;
            case "support": mcol = "#b1b1b1";
            break;
            default: mcol ="#402dcd";
        }

	var fadeSpeed = 900;
	var animSpeed = 600;

	$(".core_box").delay(300).show(260,'easeOutBack')
	$("#pagescontent h5").stop().html(plocation).animate({'left':'-425px','opacity':'0'},animSpeed,function(){
						$(this).hide();
						$(this).show().animate({'left':'0px','opacity':'1'},animSpeed)

	$("#pagescontent h2").delay(900).slideDown(fadeSpeed*2).animate({opacity:1},400,'easeOutBack')
	$("#boxtext").delay(600).fadeIn( fadeSpeed, 'linear')
	$("div.core_box").delay(1400).animate({backgroundColor: mcol}, 'slow', 'linear')
	$("#widget").delay(2000).fadeIn( fadeSpeed, 'linear')
	$("iframe").delay(2400).fadeIn( fadeSpeed, 'linear')
	$("#ytplayer").css("border-bottom","5px solid " + mcol)
					});
}


var pid = $("#pid").val()
if ($("#hd_folder").val() !== "home"){
getCase(pid)
// add case studies to any pages not home
}


var hasvid = $("#pVideo").text()
if (hasvid) {
var vidcode = "<object width='455' height='310' id='ytplayer'><param name='movie' value='http://www.youtube.com/v/" + hasvid + "?fs=1&amp;hl=en_US'></param><param name='allowFullScreen' value='true'><param name='wmode' value='transparent'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" + hasvid + "?fs=1&amp;hl=en_US' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='455' height='310' wmode='transparent'></embed></object>"
$("#widget").html(vidcode)
} else {

}


});//end



/*-----------------
BACK TO TOP
-------------------*/

	jQuery(function () {
		var scrollDiv = document.createElement('div');
		jQuery(scrollDiv).attr('id', 'toTop').html('^ Back to Top').appendTo('body');    
		jQuery(window).scroll(function () {
		        if (jQuery(this).scrollTop() != 0) {
		            jQuery('#toTop').fadeIn();
		$(".footer").slideDown(455, 'easeOutBack');
		        } else {
		            jQuery('#toTop').fadeOut();
			$(".footer").slideUp(455, 'easeOutBack');
		        }
		    });
		    jQuery('#toTop').click(function () {
		        jQuery('body,html').animate({
		            scrollTop: 0
		        },
		        800);
		    });
		});

/* -------------------
 case study getter fn
-----------------------*/

	function getCase(pnl){
	$.ajax({ 
	url: "../aj_getcase.aspx?pnl=" + pnl, 
	dataType: "html", 
	type: "GET", 
	beforeSend: function(){
	$('#casestudy').html("<img src='http://www.e3msi.com/img/loading.gif' style='width:16px'/>");
	},
	error: function(data){ 
	$("#casestudy").html('Panels cannot be retrieved right now' + data); 
	$("#casestudy").fadeIn(350)
	}, 
	success: function(data){
	if (data.length > 12){
	$('#casestudy').html("<h4>Case Study</h4>" + data)
	$("#casestudy").delay(2300).slideDown(350)
	Cufon.replace('h4', { fontFamily: 'bubbleboddy Light', fontSize: '30px', color: '#fff'})
	}
	} 
	}); 
}


/* -------------------
 Register Fn
-----------------------*/

function runRegister(){
	the_job = $('#enewsletter input:radio:checked').val();
	the_fname = $('#enewsletter #nwsfName').val();
	the_lname = $('#enewsletter #nwslName').val();
	the_email = $('#enewsletter  #nwsEm').val();
	var newsdata = ("fn=" + the_fname  + "&ln=" + the_lname + "&jb=" + the_job + "&em=" + the_email);
	if (the_fname !=0 && the_lname !=0  && isValidEmailAddress(the_email)) {
$.fancybox.showActivity();
//alert(newsdata)
	$.ajax({
		type	: "GET",
		cache	: false,
		url	: "../aj_joinenews.aspx",
		data	: newsdata,
	error: function(){ 
		$.fancybox("Cannot Register you right now, Try Later.");
	}, 
		success: function(data) {
			$.fancybox(data);
			$.fancybox.resize();
		}
	});
	}else{
	$("#reg_error").fadeIn( function(){
	setTimeout( function() { $("#reg_error").fadeOut("fast"); }, 2000);
	});
	return false;
	}
}

function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	}




