﻿/***************************************************
     Data Center Locator (6/3/11)
/**************************************************/

var currentDetailPanel = 'none';
var isIE;
var isIE6;
var isIE7;
var isIE8;
var isIE8CompatMode;
var isLessThanIE8;
	
$(document).ready( function() {

	//this code fixes the issue of the header showing over the Site Actions menu
	$('.jd_menu li').mouseover(function() {$('#header').addClass('hasIndex'); });
	$('.jd_menu li').mouseout(function() {$('#header').removeClass('hasIndex'); });

	fixDatacenterLayout();
});

function fixDatacenterLayout() {

	if($('.datacenters').length > 0){
		
		//initialization
		isIE = $.browser.msie;
		isIE6 = isIE && $.browser.version=='6.0';
		isIE7 = isIE && $.browser.version == '7.0';
		isIE8 = isIE && $.browser.version=='8.0'; 
		isLessThanIE8 = isIE && (isIE7 || isIE6);  //tests on IE8 in compatibility mode return IE7
		
		if(isIE6){
			$('.datacenters .dc_mapcontainer .locationpins a').css('background', 'url(/Assets/Images/DataCenterLocator/bkg_RedAreaMarker_matted-dk-gray.gif) no-repeat top left');
		}
		/*if( isLessThanIE8 ) {
			$('.datacenters .dc_regiondropdown .ddlist li a, .datacenters .dc_dropdown .ddlist li a').css('background','url(/Assets/Images/DataCenterLocator/bkg_dropdwn_arrowDown.jpg) no-repeat right top');
		}*/
		
		// video tour
		$('a.tourlink').attr({
			href: '/_layouts/SavvisUtilities/Video.aspx?src=/Assets/Video/Savvis_DataCenter_070811.flv',
			onclick: 'return false',
			rel: 'shadowbox;width=520;height=470'
		});
		
		// open the continent dropdown
		$('.dc_regiondropdown .ddlist li a').live('click', function() {
			if($('.dropdown_1col').css('display') == 'block'){
				$('.dropdown_1col').slideUp();
			}else {
				$('.dropdown_2col').slideUp();
				$('.dropdown_1col').slideDown();
			}
		});
		
		// open the city dropdown
		$('.dc_dropdown .ddlist li a').live('click', function() {
			if($('.dropdown_2col').css('display') == 'block'){
				$('.dropdown_2col').slideUp();
			}else{
				$('.dropdown_1col').slideUp();
				$('.dropdown_2col').slideDown();
			}
		});
		
		// close the dropdowns if you click on the map
		$('.dc_mapcontainer').live('click', function(){
			$('.dropdown_1col').slideUp();
			$('.dropdown_2col').slideUp();
		});
		
		// append "click for details" text to the location pin popups
		$('.locationpins a .btn .btnleft .cityname').each(function(){
				$(this).append('<em>Click for details</em>');
		});
		
		// red-dot DETAILS hover
		$('.locationpins a').hover( 
			function() {
				$(this).css('z-index', '100');
				var gohere = $(this).attr('rel');
				$('.dropdown_1col').slideUp();
				$('.dropdown_2col').slideUp();
				$('.locationdetails').hide();
				$('.locationdetailspanel').show();
				$('#details_'+gohere).show();
			},
			function() {
				$(this).css('z-index', '3');
				if(currentDetailPanel != 'none'){
					$('.locationdetails').hide();
					$('.locationdetailspanel').show();
					$('#details_'+currentDetailPanel).show();
				}else{
					$('.locationdetails').hide();
					$('.locationdetailspanel').hide();
				}
			}
		);
		
		//PROMO BOX
		// If there's no content for a given promobox, there should be no .pb_content.
		// If you want to add content, wrap each individual promo/event in a <div class="pb_content">
		if($('.promobox').length > 0){
			if($('.promobox').children('.pb_content').length > 0){
				$('.promobox').show();
			}else{
				$('.promobox').hide();
			}
		}
		
		//Set the value of the current detail panel when a city page loads
		if($('.switchable').length > 0){
			currentDetailPanel = $('.switchable').attr('id');
		}		
	}

}

/***************************************************
     Right Rail Click Tracking
/**************************************************/

function rightRailClickEvent(linkObj) {
	_gaq.push(['_trackEvent', topLevelNav(), secondLevelNav(), thirdLevelNavRightRail(linkObj)]);
	//alert(topLevelNav()+'   |   '+secondLevelNav()+'   |   '+thirdLevelNavRightRail(linkObj));
}

function topLevelNav(){
	return $('.siteNavigation .jd_menu li a.active').text();
}

function secondLevelNav(){
	return $('#sectionNavigation').children('ul').children('li.active').children('a').text();
}

function thirdLevelNavRightRail(linkObj){
	if($(linkObj).parents().hasClass('accordionPanel')){
		//video
		return $(linkObj).siblings('h3').text();
	}else if($(linkObj).hasClass('banner')){
		//banner
		var href = $(linkObj).attr('href');
		if(href == "http://www.savvis.com/datacenterlocator/"){
			return "Data Center Locator";
		}else{
			return href;
		}		
	}else if($(linkObj).parents('span').hasClass('img-btm-pad')){
		//looks like a banner but is constructed differently
		return $(linkObj).attr('href');
	}else if($(linkObj).parents('#railSavvisStation').length > 0){
		//SavvisStation Portal - contains login and learn more links
		var str = 'SavvisStationPortal';
		if($(linkObj).parent('h2').length > 0){
			return str+'_logIn';
		}else{
			return str+'_learnMore';
		}
	}else if($(linkObj).parents('h2')){
		//this is probably the news header
		if($(linkObj).text().indexOf('News') >= 0 || $(linkObj).text().indexOf('See All') >= 0){
			return 'News';
		}else{
			return $(linkObj).parents('h2').text();
		}
	}	
}



// accordion arrows
var $openArrow = '<img src=\"/assets/images/accordion_arrow_open.gif\" alt=\"\" />';
var $closedArrow = '<img src=\"/assets/images/accordion_arrow_closed.gif\" alt=\"\" />';


/***************************************************
     Home Page Refresh Hero Rotator (6/2/11)
/**************************************************/


//Set initial number of banners to rotate and counter set
var numBanners = 3;
var bannerCounter = 1;

function theRotator() {
	
	//Set the first dot to ON
	var targetDot = ('banner_'+bannerCounter);
	
	$('#'+targetDot).addClass('rotateDotOn');
	$('#'+targetDot).removeClass('rotateDotOff');
	
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 3 seconds
	setInterval('rotateNext()',5000);
}

function rotateNext() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	
	//Loop through number of banners, and set dots to ON and OFF
	if (bannerCounter >= numBanners) {
		bannerCounter = 1;
		var targetDot = ('banner_'+bannerCounter);
		//document.getElementById(targetDot).setAttribute("class", "rotateDotOn");
		$('#'+targetDot).addClass('rotateDotOn');
		$('#'+targetDot).removeClass('rotateDotOff');
		
		var lastDot = ('banner_'+numBanners);
		//document.getElementById(lastDot).setAttribute("class", "rotateDotOff");
		$('#'+lastDot).addClass('rotateDotOff');
		$('#'+lastDot).removeClass('rotateDotOn');
	}
		else {
			bannerCounter++;
			var targetDot = ('banner_'+bannerCounter);
			//document.getElementById(targetDot).setAttribute("class", "rotateDotOn");
			$('#'+targetDot).addClass('rotateDotOn');
			$('#'+targetDot).removeClass('rotateDotOff');
	
			var lastDot = ('banner_'+(bannerCounter-1));
			//document.getElementById(lastDot).setAttribute("class", "rotateDotOff");
			$('#'+lastDot).addClass('rotateDotOff');
			$('#'+lastDot).removeClass('rotateDotOn');
		}
		
	
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

function rotatePrev() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:last'));
	
	//Loop through number of banners, and set dots to ON and OFF
	if (bannerCounter == 1) {
		bannerCounter = numBanners;
		var targetDot = ('banner_'+bannerCounter);
		//document.getElementById(targetDot).setAttribute("class", "rotateDotOn");
		$('#'+targetDot).addClass('rotateDotOn');
		$('#'+targetDot).removeClass('rotateDotOff');
		
		var lastDot = ('banner_'+1);
		//document.getElementById(lastDot).setAttribute("class", "rotateDotOff");
		$('#'+lastDot).addClass('rotateDotOff');
		$('#'+lastDot).removeClass('rotateDotOn');
	}
		else {
			bannerCounter--;
			var targetDot = ('banner_'+bannerCounter);
			//document.getElementById(targetDot).setAttribute("class", "rotateDotOn");
			$('#'+targetDot).addClass('rotateDotOn');
			$('#'+targetDot).removeClass('rotateDotOff');
	
			var lastDot = ('banner_'+(bannerCounter+1));
			//document.getElementById(lastDot).setAttribute("class", "rotateDotOff");
			$('#'+lastDot).addClass('rotateDotOff');
			$('#'+lastDot).removeClass('rotateDotOn');
		}
		
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#rotator ul li:last') :current.prev()) : $('div#rotator ul li:last'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');	
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});

/***************************************************
     END Home Page Refresh Hero Rotator (6/2/11)
/**************************************************/



/***************************************************
     START SaaS Accordioan - 7/18/11
/**************************************************/


$(document).ready(function()
{
	//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
	$("#connection-accordion .menu_head").click(function()
    {	
		     
      $(this).toggleClass("down-arrow"); 
    	$(this).siblings().removeClass("down-arrow");
			$(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");       	
	});
});


(function($){
 
/**
* Switch element(s) Class Name
*
* @author pedrocorreia.net
*
* @param Object || Array Selector(s) -> Syntax: [ {elem, old_class, new class}, ... ]
*/
$.SwitchClass = function (selectors){
var _selectors = [], //our selectors array container, it will hold all our objects
 
/**
* Switch Class
*
* @private
* @param Jquery Object
* @param String Old Class Name
* @param String New Class Name
*/
_Switch = function(o, oldClass, newClass){
if(o && oldClass && newClass && o.hasClass(oldClass)){
o.removeClass(oldClass).addClass(newClass);
}
};
 
//check if we have an object or an array of objects,
//the "selectors" will always be in an array, even if we
//specify an Object, this will be added to our selectors Array
if($.isArray(selectors)){ _selectors = selectors; }
else{ _selectors.push(selectors); }
 
//do we have any elements in our, selectors, array?
if (_selectors.length === 0) { return; }
 
//iterate over selectors Array
$.each(_selectors, function(idx, selector){
_Switch($(selector.elem), selector.old_class, selector.new_class);
});
};
 
/**
* Switch element(s) Class Name
* jQuery custom function
*
* @author pedrocorreia.net
*
* @param String Old Class Name
* @param String New Class Name
* @extends jQuery
*/
$.fn.SwitchClass = function(old_class, new_class){
return this.each(function(){
$.SwitchClass({elem: this, old_class: old_class, new_class: new_class});
});
};
 
})(jQuery);


$(document).ready(function() {

// HOME PAGE REFRESH - Tabbed Content (5/31/11)	
	
  	var tab1OnState = false;
	var tab2OnState = false;

	$("#tab-1").hover(function() {
		$("#tab-1").SwitchClass("tab-1-stat", "tab-1-hov");
		}, function () {
			$("#tab-1").SwitchClass("tab-1-hov", "tab-1-stat");
	});
	
	$("#tab-2").hover(function() {
		$("#tab-2").SwitchClass("tab-2-stat", "tab-2-hov");
		}, function () {
			$("#tab-2").SwitchClass("tab-2-hov", "tab-2-stat");
	});
	
	$("#tab-3").hover(function() {
		$("#tab-3").SwitchClass("tab-3-stat", "tab-3-hov");
		}, function () {
			$("#tab-3").SwitchClass("tab-3-hov", "tab-3-stat");
	});	
	
	$(".close-news").click(function(){
			tab1OnState = false;
			tab2OnState = false;
			$("#tab-1").css('background-image', 'none');
			$("#tab-1").removeClass("tab-1-select");
			$("#tab-1").removeClass("tab-1-hov");
			$("#tab-1").addClass("tab-1-stat");
			
			$("#tab-2").css('background-image', 'none');
			$("#tab-2").removeClass("tab-2-select");
			$("#tab-2").removeClass("tab-2-hov");
			$("#tab-2").addClass("tab-2-stat");
			
			$("#tab-1").css('background-image', 'none');
			$("#tab-2").css('background-image', 'none');
			
			$("#tab1-content").css('display', 'none');
			$("#tab2-content").css('display', 'none');		
	});
	
		$(".close-datacenter").click(function(){
			tab1OnState = false;
			tab2OnState = false;
			$("#tab-1").css('background-image', 'none');
			$("#tab-1").removeClass("tab-1-select");
			$("#tab-1").removeClass("tab-1-hov");
			$("#tab-1").addClass("tab-1-stat");
			
			$("#tab-2").css('background-image', 'none');
			$("#tab-2").removeClass("tab-2-select");
			$("#tab-2").removeClass("tab-2-hov");
			$("#tab-2").addClass("tab-2-stat");
			
			$("#tab-1").css('background-image', 'none');
			$("#tab-2").css('background-image', 'none');
			
			$("#tab1-content").css('display', 'none');
			$("#tab2-content").css('display', 'none');		
	});

	$("#tab-1").click(function() {
	  
		if(tab1OnState == false){
			tab1OnState = true;
			tab2OnState = false;
			$("#tab-1").css('background-image', 'url(/assets/images/tab1-bg.png)');
			$("#tab-1").removeClass("tab-1-hov");
			$("#tab-1").addClass("tab-1-select");
			
			$("#tab-2").css('background-image', 'none');
			$("#tab1-content").css('display', 'block');
			$("#tab2-content").css('display', 'none');		
			
			$("#tab-2").css('background-image', 'none');
			$("#tab-2").removeClass("tab-2-select");
			$("#tab-2").removeClass("tab-2-hov");
			$("#tab-2").addClass("tab-2-stat");
		}
		else{
			tab1OnState = false;
			tab2OnState = false;
			$("#tab-1").css('background-image', 'none');
			$("#tab-1").removeClass("tab-1-select");
			$("#tab-1").removeClass("tab-1-hov");
			$("#tab-1").addClass("tab-1-stat");
			
			$("#tab-2").css('background-image', 'none');
			$("#tab1-content").css('display', 'none');
			$("#tab2-content").css('display', 'none');		
		}

	});		
	
	
	$("#tab-2").click(function() {
  	if(tab2OnState == false){
			tab1OnState = false;
			tab2OnState = true;
			
			$("#tab-1").css('background-image', 'none');
			$("#tab-1").removeClass("tab-1-select");
			$("#tab-1").removeClass("tab-1-hov");
			$("#tab-1").addClass("tab-1-stat");
			
			$("#tab-2").css('background-image', 'url(/assets/images/tab2-bg.png)');
			$("#tab-2").removeClass("tab-2-hov");
			$("#tab-2").addClass("tab-2-select");
			
			$("#tab-1").css('background-image', 'none');
			$("#tab1-content").css('display', 'none');
			$("#tab2-content").css('display', 'block');		
		}
		
		else {
			tab1OnState = false;
			tab2OnState = false;
			
			$("#tab-2").css('background-image', 'none');
			$("#tab-2").removeClass("tab-2-select");
			$("#tab-2").removeClass("tab-2-hov");
			$("#tab-2").addClass("tab-2-stat");
			
			$("#tab-1").css('background-image', 'none');
			$("#tab1-content").css('display', 'none');
			$("#tab2-content").css('display', 'none');		
		}	
	});	

	$("#tab-3").click(function() {
		window.location.href = 'http://savvis-alliances-portal.com/';
	});



	// initialize submenus	
	$('ul.jd_menu').jdMenu({ showDelay: 20, hideDelay: 20, disableLinks: false });
	
	// homepage tabs
	// Uncomment Lines 8 & 10 when 2nd tab content
	// is ready to be implemented
	$("#tabs div").hide();
	$("h2.tab a").click(function() {
		$("h2.tab").removeClass("active");
		$(this).parent().addClass("active");
		var $tabContent = $(this).attr("href");
		var $visibleContent = $("#tabs div:visible");
		if ("#"+$visibleContent.attr("id") !== $tabContent) {
			if ($visibleContent.length) {
				$visibleContent.hide();
				$($tabContent).toggle();
			} else {
				$($tabContent).toggle();
			}
		}
		return false;
	});
	
	// content tabs
	// hide all tab content
	$("#contentTabsContent div").hide();
	$(".contentTabs a").click(function() {
		// set tab state
		$(".contentTabs a").removeClass("active");
		$(this).addClass("active");
		// get id of clicked tab
		var $content = $(this).attr('href');
		var i = $content.indexOf("#");
		if (i>1)  {
			$content = $content.substring(i);
		}		
		// hide visible content
		$("#contentTabsContent div").hide();
		// show related content
		if (($.browser.msie) && ($.browser.version < 7)) {
			$("#contentTabsContent div"+$content).show();
		} else {
			$("#contentTabsContent div"+$content).fadeIn('normal');
		}
		return false;
	});
	
	// IE6 & general style fixes
	$(".globalNavigation ul li:eq(0)").css("background", "transparent");
	$(".globalNavigation ul li.navLogin a:eq(0)").css("color", "#cc092f");
	$("ul.jd_menu ul li:first-child a").css("border", "none");
	$("ul.jd_menu ul li:last-child a").css("padding-bottom", "0");
	$("#rail a.banner:first img").css("margin-top", "0");
	
	// overlay search input label
	$(".siteSearch label").labelOver('over');
	
	// accordion toggle
	if(!$.browser.msie){
		var accordionHeight = (($("#accordion h2").length * $("#accordion h2").height()) + $(".accordionPanel:first").height());
		$("#accordion").height(accordionHeight);
	}
	$('.accordionPanel').hide();
	$("#accordion h2:first").addClass("first");
	$("#accordion h2:last").addClass("last");
	$("#accordion .accordionPanel:last").addClass("last");
	$("#accordion h2").append($closedArrow);
	
	$('#accordion h2').hoverIntent({
		sensitivity: 1,
		interval: 100,
		over: 	function() {
					if(!$(this).next('.accordionPanel:visible').length) {
						$('.accordionPanel:visible').slideUp();
						$(this).next('.accordionPanel').slideToggle();
						$("#accordion h2").removeClass('active');
						$("#accordion h2 img").replaceWith($closedArrow);
						$(this).addClass('active');
						$(this).children('img').replaceWith($openArrow);
					}
				},
		timeout: 100,
		out: function() {}
	});
	
	// check all checkboxes
	$("a.checkAll").click(function() {
		$("input[@type=checkbox]").attr("checked", true);
		return false;
	});
	
	// uncheck all checkboxes
	$("a.uncheckAll").click(function() {
		$("input[@type=checkbox]").attr("checked", false);
		return false;
	});
	
	// add zebra table row class
	$("table.zebra tbody tr:even").addClass("even");
	
	// adjust overlay opacity for FF 2.x mac
	if (detectMacXFF2()) {
		$('body').addClass('mac-ff2');
	}
	
	// clear feature floats
	$(".featurePod").wrapAll('<div class="wrapper"></div>');
	
	// fix the IE6 background flickr on links
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
});


$(window).load(function() {
	// initialize shadowbox
	var options = {
		flvPlayer: '/assets/flash/flvplayer.swf'
	};
	Shadowbox.init(options);
	
	// justify content containers
	$(".featurePod").vjustify();
	$(".contentTabs a").vjustify();
	$(".manager").vjustify();
	$("ul.videoThumbnails li").vjustify();
	
	// show initial tab content
	$("#tabs h2:first a").trigger('click');
	
	// load initial accordion panel
	$("#accordion h2:first").addClass('active');
	$("#accordion h2:first img").replaceWith($openArrow);
	$(".accordionPanel:first").show();
	
	// load first content tab
	$(".contentTabs a:first").trigger('click');
	
	// fix hyphenated text wrap for FF 2.x
	if (detectFF2()) {
		$("#sectionNavigation a:contains('-')").each(function() {
			var $this = $(this);
			var t = $this.text();
			$this.text(t.replace('-', '- '));
		});
	};
});

// label over
jQuery.fn.labelOver = function(overClass) {
	return this.each(function() {
		var label = jQuery(this);
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);
			this.hide = function() {
				label.css({ textIndent: -10000 })
			}
			this.show = function() {
				if (input.val() == '') label.css({ textIndent: 0 })
			}
			// handlers
			input.focus(this.hide);
			input.blur(this.show);
			label.addClass(overClass).click(function(){ input.focus() });
			if (input.val() != '') this.hide(); 
		}
	});
}

// justify element heights
jQuery.fn.vjustify=function() {
	var maxHeight=0;
	this.each(function() {
		if (this.offsetHeight>maxHeight) { maxHeight=this.offsetHeight; }
	});
	this.each(function() {
		$(this).height(maxHeight + "px");
		if (this.offsetHeight>maxHeight) {
			$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
		}
    });
};

// Isolate Firefox 2.x for mac
function detectMacXFF2() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
		var ffversion = new Number(RegExp.$1);
		if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
			return true;
		}
	}
}

function detectFF2() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
		var ffversion = new Number(RegExp.$1);
		if (ffversion < 3) {
			return true;
		}
	}
}




