﻿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', 'ng_us_fuschia'); color = 'fuschia'; break;
		case 1: $('body').attr('id', 'ng_us_navy'); color = 'navy'; break;
		case 2: $('body').attr('id', 'ng_us_aqua'); color = 'aqua'; break;
		case 3: $('body').attr('id', 'ng_us_orange'); color = 'orange'; break;
		default: $('body').attr('id', ''); color = 'fuschia';
	}

	if ($.browser.msie) {
		browserIE = true;
		IEversion = $.browser.version;
		if (IEversion < 7) {
			$('.ng_us_dropdown').mouseover(
					function () {
						$(this).addClass('over');
					}
				)
			$('.ng_us_dropdown .ng_us_submenu').mouseout(
					function () {
						$(this).parent().removeClass('over');
					}
				)
		}
	}

	if ($.browser.mozilla && $.browser.version.substring(0, 5) == '1.9.1') {
		$('body').addClass('ff35');
	}

	if ($('ul.ng_us_dropDownNav').length > 0) {
		$('ul.ng_us_dropDownNav').superfish({
			animation: { slide: 'toggle' },
			autoArrows: false,
			delay: 300
		});
	}

	if ($('div.ng_us_linkSection').length > 0) {
		$('div.ng_us_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 ($('#ng_us_search_text').length > 0) {
		$('#ng_us_searchSubmit').click(function () {
			$('#ng_us_searchSubmitBtn').click();
		});
		$('#ng_us_search_text').keypress(function (event) {
			if (event.keyCode == 13) {
				$('#ng_us_searchSubmitBtn').click();
			}
		});
	}

	if ($('#ng_us_stories').length > 0) {
		$('body').css('backgroundImage', 'none');
		getStory(index);
	}

	var search_textDefault = '';
	if ($('#ng_us_search_text')) {
		// clear input on focus
		$('#ng_us_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
		$('#ng_us_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*******/

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) {
  		$('#ng_us_storyBG').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/bg.jpg) no-repeat top right' }).show('fade', 1000, function () {
  			$('#ng_us_topImg').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/topImgIE.png) no-repeat top right' }).show('drop', 500)
  			$('#ng_us_midImg').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/midImgIE.png) no-repeat top right' }).show('puff', 700)
  			$('#ng_us_btmImg').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/btmImgIE.png) no-repeat top right' }).show('scale', 900, function () {
  				$('#ng_us_storyIntroTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/introTxt1.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  					setTimeout(function () {
  						$('#ng_us_storyIntroTxt').hide('fade', 'slow', function () {
  							$('#ng_us_storyIntroTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/introTxt2.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  								setTimeout(function () {
  									$('#ng_us_storyIntroTxt').hide('fade', 'slow', function () {
  										$('#ng_us_storyIntroTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/introTxt3.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  											setTimeout(function () {
  												$('#ng_us_storyIntroTxt').hide('fade', 'slow', function () {
  													$('#ng_us_storyHdr').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/storyHdr.png) no-repeat 25px 100%' }).show('puff', 600);
  													$('#ng_us_storyTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/storyTxt.png) no-repeat 25px 0%' }).show('puff', 600);
  												});
  											}, delay);
  										});
  									});
  								}, delay);
  							});
  						});
  					}, delay);
  				});
  			});
  		});
  	}
  }
  else {
  	$('#ng_us_storyBG').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/bg.jpg) no-repeat top right' }).show('fade', 1000, function () {
  		$('#ng_us_topImg').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/topImg.png) no-repeat top right' }).show('drop', 500);
  		$('#ng_us_midImg').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/midImg.png) no-repeat top right' }).show('puff', 700);
  		$('#ng_us_btmImg').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/btmImg.png) no-repeat top right' }).show('scale', 900, function () {
  			$('#ng_us_storyIntroTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/introTxt1.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  				setTimeout(function () {
  					$('#ng_us_storyIntroTxt').hide('fade', 'slow', function () {
  						$('#ng_us_storyIntroTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/introTxt2.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  							setTimeout(function () {
  								$('#ng_us_storyIntroTxt').hide('fade', 'slow', function () {
  									$('#ng_us_storyIntroTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/introTxt3.png) no-repeat 25px 50%' }).show('puff', 600, function () {
  										setTimeout(function () {
  											$('#ng_us_storyIntroTxt').hide('fade', 'slow', function () {
  												$('#ng_us_storyHdr').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/storyHdr.png) no-repeat 25px 100%' }).show('puff', 600);
  												$('#ng_us_storyTxt').css({ background: 'url(hip/us/ng/assets/images/stories/' + color + '/storyTxt.png) no-repeat 25px 0%' }).show('puff', 600);
  											});
  										}, delay);
  									});
  								});
  							}, delay);
  						});
  					});
  				}, delay);
  			});
  		});
  	});
  }
}
function browseByDiscipline() {
	$('#ng_us_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('ng_us_current');
	$('#ng_us_myLabsPromoNav a').not($(navEl)).removeClass('ng_us_current');
	var navItem = parseInt(navItem);
	switch (navItem) {
		case 0: $('#ng_us_myLabsPromoNav').stop().animate({ backgroundPosition: '100% -83px' }); break;
		case 1: $('#ng_us_myLabsPromoNav').stop().animate({ backgroundPosition: '100% -61px' }); break;
		case 2: $('#ng_us_myLabsPromoNav').stop().animate({ backgroundPosition: '100% -38px' }); break;
		case 3: $('#ng_us_myLabsPromoNav').stop().animate({ backgroundPosition: '100% -15px' }); break;
		default: $('#ng_us_myLabsPromoNav').stop().animate({ backgroundPosition: '100% -83px' });
	}
	$('#ng_us_myLabsPromoContents .ng_us_promoContent').not($('#ng_us_myLabsPromoContents .ng_us_promoContent').eq(parseInt(navItem))).addClass('ng_us_hidden');
	$('#ng_us_myLabsPromoContents .ng_us_promoContent').eq(parseInt(navItem)).removeClass('ng_us_hidden');

}
function productsAndProgramsHoverStates(){
	$('.ng_us_productsAndPrograms li a').each(function () {
		$(this).mouseover(function () {
			$(this).stop().animate({ opacity: 1 }, 500);
      $('.ng_us_productsAndPrograms li a').not($(this)).stop().animate({ opacity: .2 }, 500);
    });
    $('.ng_us_productsAndPrograms').mouseout(function () {
    	$('.ng_us_productsAndPrograms li a').stop().animate({ opacity: 1 }, 800);
    });
  });
}
function pearsonPrograms(content, containerHeader) {
	$('.ng_us_eventContainer').not($('#ng_us_' + content)).addClass('ng_us_hidden');
	$('#ng_us_' + content).removeClass('ng_us_hidden');
	$('.ng_us_tabNav').not($(containerHeader).find('.ng_us_tabNav')).removeClass('ng_us_current');
	$(containerHeader).find('.ng_us_tabNav').addClass('ng_us_current');
}

