try { document.execCommand("BackgroundImageCache", false, true) } catch (err) { }

function set_column_height() {
	// Column height equalizer -  global  right column
	var col1Height = $('#col1').height();
	var col3Height = $('#col3').height();
	var buffer = (navigator.userAgent.indexOf('MSIE') > -1) ? 0 : 15;
	
	if  ( $('#home').length) {
		$('#col1').height(col3Height);
	} else { // 700			// 400
		if (col1Height >= col3Height) {
			//$('#col1').height(col3Height); // Not needed; if the right column is longer, it's because content is making it so.
		} else {
			$('#col1').height(col3Height + buffer);
		}
	}
	// Box height equalizer - leftBalanceBox
	if  ( $('#leftBalanceBox').length) {
		if  ( $('#rightBalanceBox').length) {
			var box1Height = $('#leftBalanceBox').height();
			var box2Height = $('#rightBalanceBox').height();
			if (box1Height > box2Height) {
				$('#rightBalanceBox').height(box1Height);
			} else {
				$('#leftBalanceBox').height(box2Height);
			}
		}
	}
};


function matchColHeights(col1, col2) {
	var col1Height = $(col1).height();
	var col2Height = $(col2).height();
	if (col1Height > col2Height) {
		$(col2).height(col1Height);
	} else {
		$(col1).height(col2Height);
	}
}

function changeBreadcrumbs(itemName) {
	if(document.getElementById && document.getElementsByTagName) {
		var breadcrumbs = document.getElementById('cs_control_1347');
		var spans = breadcrumbs.getElementsByTagName('span');
		spans[7].innerHTML = itemName;
	}
}


function init_menus() {
	//Dropdown menu config - except IE
	ddsmoothmenu.init({
		mainmenuid: "nav-container", 
		orientation: 'h', 
		classname: 'menu', 
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	})
};


window.onload=function () { 
	set_column_height(); // must run on window.onload since document.ready is too soon.
	if ($(".gmap").length > 0) {
		gmap_initialize(); // slow to load, so best done last
	}
};


$(document).ready(function() {

	// Main Nav Dropdowns:
	if ($.browser.msie) {
		var $menu_list = $("#nav-container > ul > li  > a ");
		if ($menu_list.length > 0) {
			$("#nav-container > ul > li ").mouseover(function() { 
			  var hhh = $(this).height();
			  $(this).find(".submenu").each(function($hhh) {  
					 if ( $.browser .msie && $.browser .version <= 6.0 ) $(this).css({ 'top':hhh});
					 $(this).css({ 'display': 'block' });
					 $(this).css({ 'visibility': 'visible' });
					 $(this).parent().find("a:first").addClass('selected');
			 });
			}).mouseout(function() { 
				  $(this).find("a:first").removeClass('selected');
				  $(this).find(".submenu").each(function() {  
						 $(this).css({ 'visibility': 'hidden' });
						$(this).css({ 'display': 'none' });
				 });
			});
		}
	} else {
		init_menus();
	}

	// Header Logo functionality:
	$("#logo").click(function () {document.location='/'});
	$("#logo").mouseover(function() {
		$("#logo").css({ 'cursor': 'pointer' });
	});
	
	//Rounded corners    
	$(function(){
		$("#search-container").corner('bottom, 5px');
		$("#header-links").corner('5px');
		$(".submitButton").corner('3px');
	});

	//Email buttons
	$("img.email-sales-home").hover(
      function () {
		this.src = '/images/email-sales-home-btn-over.jpg';
      }, 
      function () {
       this.src = '/images/email-sales-home-btn.jpg';
      });
	 
	$("img.email-sales").hover(
      function () {
		this.src = '/images/email-sales-btn-over.jpg';
      }, 
      function () {
       this.src = '/images/email-sales-btn.jpg';
      });
	 
	//Generic button hover function -  
	//    img class name must match base file name
	//    outer anchor tag must have one of the following classes:
	//          gbtn - for a GIF button
	//          jbtn - for a JPG button
	//          pbtn - for a PNG button
		$(".jbtn").hover(
			function () {$(this).find("img").each(function() { this.src = '/images/'+$(this).attr("id")+'-over.jpg' });}, 
			function () {$(this).find("img").each(function() { this.src = '/images/'+$(this).attr("id")+'.jpg' });}
		);
		$(".gbtn").hover(
			function () {$(this).find("img").each(function() { this.src = '/images/'+$(this).attr("id")+'-over.gif' });}, 
			function () {$(this).find("img").each(function() { this.src = '/images/'+$(this).attr("id")+'.gif' });}
		);
		$(".pbtn").hover(
			function () {$(this).find("img").each(function() { this.src = '/images/'+$(this).attr("id")+'-over.png' });}, 
			function () {$(this).find("img").each(function() { this.src = '/images/'+$(this).attr("id")+'.png' });}
		);

	//CSS Button hovers
	$(".button").hover(
      function () {
        $(this).css("background-color", "#00a0b2");
      }, 
      function () {
       $(this).css("background-color", "#008998");
      });
      
	$("input.submitButton").hover(
      function () {
        $(this).css({backgroundImage: "url(/images/bg_button_submit-hover.gif)"});
      }, 
      function () {
        $(this).css({backgroundImage: "url(/images/bg_button_submit.gif)"});
      });

	//Success Story module buttons
	if ($("#logoshome").length > 0) {
			$(".logo-client").mouseover(function() { 
				$(this).find("img").each(function() { 
					this.src = '/ce-admin/images/'+$(this).attr("id")+'-over_1.jpg';
				});
			}).mouseout(function() { 
				$(this).find("img").each(function() { 
					this.src = '/ce-admin/images/'+$(this).attr("id")+'_1.jpg';
				});
			});
	}
    
	// setup expandable text blocks
	if ($(".textBlockExpandButton").length > 0) {
		$(".textBlockExpandButton").click(function() {
			if ($(this).parent().find(".textBlockExpansion").css("display") == "block") {
				$(this).parent().find(".textBlockExpandButton").addClass("btnOpen");
				$(this).parent().find(".textBlockExpandButton").removeClass("btnClose");
			} else {
				$(this).parent().find(".textBlockExpandButton").addClass("btnClose");
				$(this).parent().find(".textBlockExpandButton").removeClass("btnOpen");
			}
			$(this).parent().find(".textBlockExpansion").slideToggle("fast",function(){
				var sch = setTimeout(function(){set_column_height()}, 200);  //need delay
			});
		});
	}
	
	/**
	*** TABBED CONTAINERS
	**/
	var tabID = 0;
	if(document.location.hash != '' && document.location.hash.indexOf('panel') > -1) {
		tabID = document.location.hash.substr(1, document.location.hash.length);
		tabID = tabID.replace('panel', '');
	}
	
	if ($("#cp-tabs").length > 0) {
		//Customer Portal Tabbed Container (advanced)
		$(function () {
			var subContainers = $('.panel > div > div');
			$('.sub-links a').click(function () {
				subContainers.hide().filter(this.hash).show(); // show corresponding subpanel
				// menu states:
				$('.sub-links a').removeClass('active');
				$(this).addClass('active');
				var sch = setTimeout(function(){set_column_height()}, 200);  //need delay
				return false;
			}).filter(':first').click();
			
			var tabContainers = $('#cp-tabs > div > div.panel');
			$('#cp-tabs ul.tabNavigation a').click(function () {
				tabContainers.hide().filter(this.hash).show(); // show corresponding main panel
				// menu states:
				$('#cp-tabs ul.tabNavigation li').removeClass('selected');
				$(this).parent('li').addClass('selected');
				// need to open/set defaul subpanel as well...? yes
				var first_one = this.hash+" > div > div:first";
				subContainers.hide().filter(first_one).show(); // show default subpanel
				$('.sub-links a').removeClass('active');
				var first_one = this.hash+" > div.sub-links > a:first";
				$(first_one).addClass('active');
				var sch = setTimeout(function(){set_column_height()}, 200);  //need delay
				return false;
			});
			if(tabID == 0)
				$('div.tabs ul.tabNavigation a').filter(':first').click();
		});
	} else {
		//Tabbed containers (basic)
		$(function () {
			var tabContainers = $('div.tabs > div > div');
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide().filter(this.hash).show();
				$('div.tabs ul.tabNavigation li').removeClass('selected');
				$(this).parent('li').addClass('selected');
				var sch = setTimeout(function(){set_column_height()}, 200);  //need delay
				return false;
			});
			if(tabID == 0)
				$('div.tabs ul.tabNavigation a').filter(':first').click();
			else {
				tabContainers.hide().filter('#panel' + tabID).show();
				$('div.tabs ul.tabNavigation li').removeClass('selected');
				$('div.tabs ul.tabNavigation li#tabHandle' + tabID).addClass('selected');
			}
		});
	}

	/**
	*** MODAL POPUPS
	**/
	
	//try { 
		//popup layer for Login/Register:
		// these parameters specific to the login/register popup:
		$("a.modalLink").colorbox(
			{ iframe:true, scrolling:false, opacity:0.5, width:640, height:600 }, 
			function(){  } // callback function - fires after popup loads
		);
		
		//popup layer for Contact Form:
		// these parameters specific to the login/register popup:
		$("a.modalContact").colorbox(
			{ iframe:true, scrolling:false, opacity:0.5, width:680, height:580 }
		);
	
		//popup layer for Email Page Form:
		// these parameters specific to the login/register popup:
		$("a.modalEmail").colorbox(
			{ iframe:true, scrolling:false, opacity:0.5, width:620, height:500 }
		);
		
		//popup layer for Videos:
		// these parameters specific to the login/register popup:
		$("a.modalVideo").colorbox(
			{ iframe:true, scrolling:false, opacity:0.5, width:592, height:512 }
		);
		
	//} catch (err) { }
	// NOTE: use this to launch the login modal on page load: 
	//   $.fn.colorbox({href:'login.html', open:true, iframe:true, scrolling:false, opacity:0.5, width:640, height:600 })

	//Need to reinit code due to a bug i IE7:
	if ( $.browser .msie && $.browser .version < 8.0 && $.browser .version > 6.0 )  { 
			//Listener for the close event:
			$().bind('cbox_closed',function(){
				//alert( "IE7 modal callback function");
				$('#cboxOverlay, #colorbox').remove(); //really need a callback, since unsure how long this will take
				var cbi = setTimeout(function(){  
						$.fn.colorbox.init(); // creates multiple instances unless you remove the old instance first
         		}, 1000);  //reinit modal box after delay
				//window.location.reload(); // last resort fix for IE7
			});
	} else {
			//Listener for the close event:
			$().bind('cbox_closed',function(){
				//alert( "modal callback function");
			});
	}

	/**
	*** TABLE STRIPING
	**/
	
	$('.pingTable tbody tr:even').addClass('even');
	

	/**
	*** CLICKABLE DIVS
	**/
	
	$('div#osPingFederate').click( function() { 
        document.location = '/our-solutions/pingfederate.cfm';
	}); 
	$('div#osPingFederate').css({ 'cursor': 'pointer' });
	$('div#osPingConnect').click( function() { 
        document.location = '/our-solutions/pingconnect.cfm';
	});
	$('div#osPingConnect').css({ 'cursor': 'pointer' });
	matchColHeights('#osPingFederate', '#osPingConnect');
	
	
}) // end document.ready


////////// Additional JS functions here //////////

function kc_checkall() {
	// Knowledge Ctr - Select all button
	$(".kc_checkbox").each(function() {this.checked = true;});
};

function kc_uncheck() {
	// Knowledge Ctr - Reset button
	$(".kc_checkbox").each(function() {this.checked = false;});
};

/*
** Dynamically inject code for Printer-friendly header and footer:
*/

function print_header_footer() {
	//dynamic code for custom header + footer for printed pages:
	$pheader=$('<div class="print-only"><div class="print-logo"><img src="/images/ping-logo-ie.png" alt="logo" /></div><h1>Ping Identity<sup>&reg;</sup> &mdash; One password is all it takes.</h1><div style="clear:both"></div></div>');
	$pfooter=$('<div class="print-only"><hr /><div class="print-footer">&copy;2009 Ping Identity Inc.</div></div>');
	$('#page').prepend($pheader); // write the header
	$('#footer-container').append($pfooter); //write the footer
};

/*
** Google Maps for Contact Us page:
*/

var latDenver = 39.749617;
var lonDenver = -104.992792;
var latBoston = 42.403499;
var lonBoston = -71.273498;
var latVancouver = 49.283823;
var lonVancouver = -123.105414;

function gmap_initialize() {
	if (GBrowserIsCompatible()) {
		
		var map1, map2, map3;
		map1 = new GMap2(document.getElementById("map1"));
		map2 = new GMap2(document.getElementById("map2"));
		map3 = new GMap2(document.getElementById("map3"));
		
		map1.setUIToDefault();
		map2.setUIToDefault();
		map3.setUIToDefault();

		// Set up our GMarkerOptions object
        var pingIcon = new GIcon(G_DEFAULT_ICON);
        pingIcon.image = "/images/ping_location_icon.png";
        pingIcon.iconSize = new GSize(33, 50);
        pingIcon.iconAnchor=new GPoint(17,50);
		markerOptions = { icon:pingIcon };

		// load the lat lon for each position
		var point1 = new GLatLng(latDenver, lonDenver);	
		var point2 = new GLatLng(latBoston, lonBoston);	
		var point3 = new GLatLng(latVancouver, lonVancouver);	
		
		map1.addOverlay(new GMarker(point1,markerOptions));
		map1.addOverlay(new GMarker(point2,markerOptions));
		map1.addOverlay(new GMarker(point3,markerOptions));
		map2.addOverlay(new GMarker(point1,markerOptions));
		map2.addOverlay(new GMarker(point2,markerOptions));
		map2.addOverlay(new GMarker(point3,markerOptions));
		map3.addOverlay(new GMarker(point1,markerOptions));
		map3.addOverlay(new GMarker(point2,markerOptions));
		map3.addOverlay(new GMarker(point3,markerOptions));
		
		var latlngbounds1 = new GLatLngBounds( );
		var latlngbounds2 = new GLatLngBounds( );
		var latlngbounds3 = new GLatLngBounds( );
		latlngbounds1.extend(point1);		
		latlngbounds2.extend(point2);		
		latlngbounds3.extend(point3);		
	
        map1.setCenter( latlngbounds1.getCenter( ), map1.getBoundsZoomLevel( latlngbounds1 ) - 3 );
        map2.setCenter( latlngbounds2.getCenter( ), map2.getBoundsZoomLevel( latlngbounds2 ) - 3 );
        map3.setCenter( latlngbounds3.getCenter( ), map3.getBoundsZoomLevel( latlngbounds3 ) - 3 );

	}
};

