﻿var browserIE = false;
var IEversion = false;
var strapIndex = getCookie('strapIndex');
var index = parseInt(Math.floor(Math.random() * 4));
var color = '';

$(function () {
	if (strapIndex != "" && strapIndex != null && strapIndex != false) {
		index = parseInt(strapIndex);
	}
	else {
		setCookie('strapIndex', index, null);
	}

	switch (index) {
		case 0: $('body').attr('id', 'fuschia'); color = 'fuschia'; break;
		case 1: $('body').attr('id', 'navy'); color = 'navy'; break;
		case 2: $('body').attr('id', 'aqua'); color = 'aqua'; break;
		case 3: $('body').attr('id', 'orange'); color = 'orange'; break;
		default: $('body').attr('id', ''); color = 'fuschia';
	}

	if ($.browser.msie) {
		browserIE = true;
		IEversion = $.browser.version;
		if (IEversion < 7) {
			$('.dropdown').mouseover(
					function () {
						$(this).addClass('over');
					}
				)
			$('.dropdown .submenu').mouseout(
					function () {
						$(this).parent().removeClass('over');
					}
				)
		}
	}

	if ($.browser.mozilla && $.browser.version.substring(0, 5) == '1.9.1') {
		$('body').addClass('ff35');
	}

	if ($('ul.dropDownNav').length > 0) {
		$('ul.dropDownNav').superfish({
			animation: { slide: 'toggle' },
			autoArrows: false,
			delay: 300
		});
	}

	if ($('div.linkSection').length > 0) {
		$('div.linkSection').click(function () {
			if ($(this).find('a').attr('target') == "_blank") { window.open($(this).find('a').attr('href')); return false; }
			else document.location.href = $(this).find('a').attr('href');
		});
	}
	if ($('#search_text').length > 0) {
		$('#searchSubmit').click(function () {
			$('#searchSubmitBtn').click();
		});
		$('#search_text').keypress(function (event) {
			if (event.keyCode == 13) {
				$('#searchSubmitBtn').click();
			}
		});
	}

	if ($('#stories').length > 0) {
		$('body').css('backgroundImage', 'none');
		getStory(index);
	}

	var search_textDefault = '';
	if ($('#search_text')) {
		// clear input on focus
		$('#search_text').focus(function () {
			if ($(this).val() == $(this).attr('title')) {
				search_textDefault = $(this).val();
				$(this).val('').addClass('default');
			}
		});
		// if field is empty afterward, add text again
		$('#search_text').blur(function () {
			if ($(this).val() == '') {
				$(this).val(search_textDefault).removeClass('default');
			}
		});
	}

	$('.ui-button').mouseover(function () {
		$(this).addClass('ui-state-hover');
	});
	$('.ui-button').mouseout(function () {
		$(this).removeClass('ui-state-hover');
	});

	setActiveStyleSheet(color);

});            /****End onload functions*******/


$(document).ready(function() {

	if($('.productsAndPrograms').length > 0){
		productsAndProgramsHoverStates();
	}
	
});

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		var i, x, y, ARRcookies = document.cookie.split(";");
		for (i = 0; i < ARRcookies.length; i++) {
			x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
			y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
			x = x.replace(/^\s+|\s+$/g, "");
			if (x == c_name) {
				return unescape(y);
			}
		}
	}
	return false;
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) +
	((expiredays == null) ? ";path=/" : ";expires=" + exdate.toUTCString());+"path=/";
}



function getStory(index) {
  var delay = 2000;
  if (browserIE) {
  	if (IEversion > 6) {
  		//$('#storyBG').css({ background: 'url(assets/images/stories/' + color + '/bg.jpg) no-repeat top right' }).show('fade', 1000, function () {
		$('#storyBG').css({ background: 'url(assets/images/stories/' + color + '/bg.jpg) no-repeat' }).show('fade', 1000, function () {
																																			  
//  			$('#topImg').css({ background: 'url(assets/images/stories/' + color + '/topImgIE.png) no-repeat top right' }).show('drop', 500)
//  			$('#midImg').css({ background: 'url(assets/images/stories/' + color + '/midImgIE.png) no-repeat top right' }).show('puff', 700)
//  			$('#btmImg').css({ background: 'url(assets/images/stories/' + color + '/btmImgIE.png) no-repeat top right' }).show('scale', 900, function () {
				//--Begin introTxt
  				$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt1.png) no-repeat 25px 50%' }).show('puff', 600, function () {
										
										
  					setTimeout(function () {
  						$('#storyIntroTxt').hide('fade', 'slow', function () {
  							$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt2.png) no-repeat 25px 50%' }).show('puff', 600, function () {
										
										
  								setTimeout(function () {
  									$('#storyIntroTxt').hide('fade', 'slow', function () {
  										$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt3.png) no-repeat 25px 50%' }).show('puff', 600, function () {
																																														 
									setTimeout(function () {
										$('#storyIntroTxt').hide('fade', 'slow', function () {
											$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt4.png) no-repeat 25px 50%' }).show('puff', 600, function () {																																						 
										setTimeout(function () {
											$('#storyIntroTxt').hide('fade', 'slow', function () {
												$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt5.png) no-repeat 25px 50%' }).show('puff', 600, function () {					
													
													
													
																																														 
  											setTimeout(function () {
  												$('#storyIntroTxt').hide('fade', 'slow', function () {
  													$('#storyHdr').css({ background: 'url(assets/images/stories/' + color + '/storyHdr.png) no-repeat 25px 100%' }).show('puff', 600);
  													$('#storyTxt').css({ background: 'url(assets/images/stories/' + color + '/storyTxt.png) no-repeat 25px 0%' }).show('puff', 600);
  												});
  											}, delay);
											
											
	
												});
											});
										}, delay);
									
									
											});
										});
									}, delay);
								
								
											
  										});
  									});
  								}, delay);
								
								
  							});
  						});
  					}, delay);
					
					
  				});
				//--End introTxt				
//  			});
  		});
  	}
  }
  else {
  	$('#storyBG').css({ background: 'url(assets/images/stories/' + color + '/bg.jpg) no-repeat top right' }).show('fade', 1000, function () {
//  		$('#topImg').css({ background: 'url(assets/images/stories/' + color + '/topImg.png) no-repeat top right' }).show('drop', 500);
//  		$('#midImg').css({ background: 'url(assets/images/stories/' + color + '/midImg.png) no-repeat top right' }).show('puff', 700);
//  		$('#btmImg').css({ background: 'url(assets/images/stories/' + color + '/btmImg.png) no-repeat top right' }).show('scale', 900, function () {
			
			//--Begin introTxt
  			$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt1.png) no-repeat 25px 50%' }).show('puff', 600, function () {
																																							 
  				setTimeout(function () {
  					$('#storyIntroTxt').hide('fade', 'slow', function () {
  						$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt2.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  							setTimeout(function () {
  								$('#storyIntroTxt').hide('fade', 'slow', function () {
  									$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt3.png) no-repeat 25px 50%' }).show('puff', 600, function () {
																																													 
  										
								
									setTimeout(function () {
									$('#storyIntroTxt').hide('fade', 'slow', function () {
										$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt4.png) no-repeat 25px 50%' }).show('puff', 600, function () {
																																													 
																																													 
										setTimeout(function () {
										$('#storyIntroTxt').hide('fade', 'slow', function () {
											$('#storyIntroTxt').css({ background: 'url(assets/images/stories/' + color + '/introTxt5.png) no-repeat 25px 50%' }).show('puff', 600, function () {
										
										
										
										
										
											
											setTimeout(function () {
												$('#storyIntroTxt').hide('fade', 'slow', function () {
													$('#storyHdr').css({ background: 'url(assets/images/stories/' + color + '/storyHdr.png) no-repeat 25px 100%' }).show('puff', 600);
													$('#storyTxt').css({ background: 'url(assets/images/stories/' + color + '/storyTxt.png) no-repeat 25px 0%' }).show('puff', 600);
												});
											}, delay);
										
										
										
												});
										});
									}, delay);			
										
										
										
											});
									});
								}, delay);
										
										
										
  									});
  								});
  							}, delay);
							
							
							
							
							
							
  						});
  					});
  				}, delay);
  			});
			//--End introTxt
			
//  		});
  	});
  }
  
}
function browseByDiscipline() {
	$('#disciplineitems').dialog({
		modal: true,
		resizable: false,
		width: '800',
		title: 'Browse By Discipline',
		show: 'fade',
		hide: 'fade',
		closeOnEscape: true,
		close: function () {
			$(this).dialog('destroy');
		}
	})
}
function setActiveStyleSheet(title) {
	var i, a, main;

	for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("Style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if (a.getAttribute("title") == title) a.disabled = false;
		}
	}
}
function myLabsPromoSelection(navItem, navEl) {
	$(navEl).addClass('current');
	$('#myLabsPromoNav a').not($(navEl)).removeClass('current');
	var navItem = parseInt(navItem);
	switch (navItem) {
		case 0: $('#myLabsPromoNav').stop().animate({ backgroundPosition: '100% -83px' }); break;
		case 1: $('#myLabsPromoNav').stop().animate({ backgroundPosition: '100% -61px' }); break;
		case 2: $('#myLabsPromoNav').stop().animate({ backgroundPosition: '100% -38px' }); break;
		case 3: $('#myLabsPromoNav').stop().animate({ backgroundPosition: '100% -15px' }); break;
		default: $('#myLabsPromoNav').stop().animate({ backgroundPosition: '100% -83px' });
	}
	$('#myLabsPromoContents .promoContent').not($('#myLabsPromoContents .promoContent').eq(parseInt(navItem))).addClass('hidden');
	$('#myLabsPromoContents .promoContent').eq(parseInt(navItem)).removeClass('hidden');

}
function productsAndProgramsHoverStates(){
	$('.productsAndPrograms li > a').live('mouseover', function () {
		$(this).stop().animate({ opacity: 1 }, 200);
		$('.productsAndPrograms li > a').not($(this)).stop().animate({ opacity: .2 }, 200);
	});
	$('.productsAndPrograms li > a').live('mouseout', function () {
		$('.productsAndPrograms li > a').stop().animate({ opacity: 1 }, 200);
	});
}
function pearsonPrograms(content, containerHeader) {
	$('.eventContainer').not($('#' + content)).addClass('hidden');
	$('#' + content).removeClass('hidden');
	$('.tabNav').not($(containerHeader).find('.tabNav')).removeClass('current');
	$(containerHeader).find('.tabNav').addClass('current');
}
/*Begin VideoModal*/
function videoModal(url, width, height, title) {
	var dialogWidth = width * 1.05;
	var dialogHeight = height * 1.3;
	$('<div class="videoModal" title="' + title + '"><iframe frameborder="0" src="/assets/images/ppt.gif" ></iframe></div>').dialog({
	  width: dialogWidth,
	  height: dialogHeight,
	  open: function () {
	    $(this).find('iframe').eq(0).attr({
	      src: url,
	      width: width,
	      height: height
	    })
	  },
	  modal: true,
	  resizable: false,
	  draggable: false,
	  buttons: { 'Close': function () { $(this).dialog("destroy").remove() } },

//	 RWP:
//	 05-Dec-2011
//	 Added close function to ensure jQuery dialog
//	 and its contents are destroyed when close is
//	 called from the upper-right-hand-corner 'x'
//	 Note: this is a mod of McCann's original script
	  close: function() {
    	$(this).dialog("destroy").remove();
  		}
//	 end RWP changes
		
	});
}
/*End VideoModal*/

function sendMail(user,domain)
{
	locationstring = "mailto:" + user + "@" + domain;
	window.location = locationstring;
}

function blindDownDiv(div)
{
	if (!document.getElementById(div).display || document.getElementById(div).display == "none")
	{ 
		document.getElementById(div).display = "block";
		new Effect.BlindDown(document.getElementById(div), {duration:0.5});
	}
	else if (document.getElementById(div).display == "block")
	{ 
		document.getElementById(div).display = "none";
		new Effect.BlindUp(document.getElementById(div), {duration:0.5});
	}
}

function blindDownHome(div1, div2, div3)
{
	if (!document.getElementById(div1).display || document.getElementById(div1).display == "none")
	{ 
		document.getElementById(div3).style.height = "auto";
		document.getElementById(div1).display = "none";
		new Effect.BlindUp(document.getElementById(div1), {duration:0.5});
		document.getElementById(div2).display = "block";
		new Effect.BlindDown(document.getElementById(div2), {duration:0.5});
	}
}
