/**
 * 
 *  Common used functions for JQuery
 *
 */
 
function gaTagLoader() {
	
	setTimeout("gaTagScript()", 2000);
	
}

function gaTagScript() {
	
	var thescript = document.createElement('script');
	thescript.setAttribute('type','text/javascript');
	thescript.setAttribute('src','http://pyramis.com/scripts/gatag.js');
	document.getElementsByTagName('head')[0].appendChild(thescript);
	
}


$(document).ready(function () {	
							
							
	/* show accordion */
	$(".accordion-col").css("display","block");

							
	/* tabs for equity page */
	$("#tabs").tabs();
							
	/* slider for bios
	$(function(){
		$("#holder").jScrollPane({
			scrollbarWidth: 16
		});
	}); */
	
	/* global landing page interactive map */
	var glpSpeed = 150;
	
	$("#glp-hover-us").hover(
	  function(){ 
		$('#glp-map-us,').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-us,').fadeOut(glpSpeed);
	  } 
	);
	$("#glp-dothover-us").hover(
	  function(){ 
		$('#glp-map-us,').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-us,').fadeOut(glpSpeed);
	  } 
	);
	
	
	
	$("#glp-hover-ca").hover(
	  function(){ 
		$('#glp-map-ca').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-ca').fadeOut(glpSpeed);
	  } 
	);
	$("#glp-dothover-ca").hover(
	  function(){ 
		$('#glp-map-ca').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-ca').fadeOut(glpSpeed);
	  } 
	);
	
	
	
	$("#glp-hover-uk").hover(
	  function(){ 
		$('#glp-map-uk').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-uk').fadeOut(glpSpeed);
	  } 
	);
	$("#glp-dothover-uk").hover(
	  function(){ 
		$('#glp-map-uk').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-uk').fadeOut(glpSpeed);
	  } 
	);
	
	
	
	$("#glp-hover-other").hover(
	  function(){ 
		$('#glp-map-other').fadeIn(glpSpeed);
	  }, 
	  function(){ 
	  	$('#glp-map-other').fadeOut(glpSpeed);
	  } 
	);
	/* end glp landing page interactive map */

	
	
	
	/* investment approach interactive map */
	$("#map-hover-au").hover(
	  function(){ $('#map-au').fadeIn("fast"); }, 
	  function(){ $('#map-au').fadeOut("slow"); } 
	);
			
	$("#map-hover-ca").hover(
	  function(){ $('#map-ca').fadeIn("fast"); }, 
	  function(){ $('#map-ca').fadeOut("slow"); } 
	);
	
	$("#map-hover-de").hover(
	  function(){ $('#map-de').fadeIn("fast"); }, 
	  function(){ $('#map-de').fadeOut("slow"); } 
	);
	
	$("#map-hover-fr").hover(
	  function(){ $('#map-fr').fadeIn("fast"); }, 
	  function(){ $('#map-fr').fadeOut("slow"); } 
	);
	
	$("#map-hover-hk").hover(
	  function(){ $('#map-hk').fadeIn("fast"); }, 
	  function(){ $('#map-hk').fadeOut("slow"); } 
	);
	
	$("#map-hover-in").hover(
	  function(){ $('#map-in').fadeIn("fast"); }, 
	  function(){ $('#map-in').fadeOut("slow"); } 
	);
	
	$("#map-hover-it").hover(
	  function(){ $('#map-it').fadeIn("fast"); }, 
	  function(){ $('#map-it').fadeOut("slow"); } 
	);
	
	$("#map-hover-jp").hover(
	  function(){ $('#map-jp').fadeIn("fast"); }, 
	  function(){ $('#map-jp').fadeOut("slow"); } 
	);
	
	$("#map-hover-sp").hover(
	  function(){ $('#map-sp').fadeIn("fast"); }, 
	  function(){ $('#map-sp').fadeOut("slow"); } 
	);
	
	$("#map-hover-uk").hover(
	  function(){ $('#map-uk').fadeIn("fast"); }, 
	  function(){ $('#map-uk').fadeOut("slow"); } 
	);
	
	$("#map-hover-us").hover(
	  function(){ $('#map-us').fadeIn("fast"); }, 
	  function(){ $('#map-us').fadeOut("slow"); } 
	);
	
	$("#map-hover-ca").hover(
	  function(){ $('#map-ca').fadeIn("fast"); }, 
	  function(){ $('#map-ca').fadeOut("slow"); } 
	);
	
	$("#map-hover-ko").hover(
	  function(){ $('#map-ko').fadeIn("fast"); }, 
	  function(){ $('#map-ko').fadeOut("slow"); } 
	);
	/* investment approach interactive map */


	
	/* preload tabs
	/*$.preloadImages("images/tabs-newsletters-off.gif",
					"images/tabs-newsletters-on.gif",
					"images/tabs-webcasts-off.gif",
					"images/tabs-webcasts-on.gif",
					"images/tabs-whitepapers-off.gif",
					"images/tabs-whitepapers-on.gif"
	);
	end preload tabs */						



	/* dropdown */
	$("#nav-one > li > ul").fadeOut("fast");
	$("#nav-one li").hover(
	  function(){ $(this).find("ul:first").fadeIn("fast"); }, 
	  function(){ $(this).find("ul:first").fadeOut("fast"); } 
	);
	if (document.all) {
	  $("#nav-one li").hoverClass ("sfHover");
	}
	/* end dropdown */

	
	
	/* accordion */
	
	/* trap click event for any accordion and send the id to Google Analytics (pageTracker) for tracking purposes */
	$('.ui-acc-header').click(function(event) {
		accordionID = $(this).attr("title");
		/*alert("title is " + accordionID);*/
		pageTracker._trackEvent('accordion', 'toggle', accordionID);
	});
	
	$('#accordion').accordion({
		autoheight: false,
		active: '.selected',
		header: ".ui-acc-header"
	});	
	
	$('#accordion2').accordion({
		autoheight: false,
		active: '.selected2',
		header: ".ui-acc-header2"
	});	
	/* end accordion */

	
	$('a#test10').click(function (e) {
		e.preventDefault();
		$('#modalContentTest').modal({onClose: modalClose});
	});
	/* end tabs - equity */
	
	
	////////////////////////////////////
	/* panels - fixed income overview */
	////////////////////////////////////
	
	$("#one-text").addClass(".selected");
	
	
	//////////////////////////////////////////////////
	/* window shades marked with class .panel-title */
	//////////////////////////////////////////////////
	
	$(".panel-title").click(function(event) {
		target = "#" + event.target.id + "-text";
		event.preventDefault();
		$(target).slideToggle();
		$(target).addClass(".selected");
		pageTracker._trackEvent('windowshade', 'expand', $(this).html());
	});		
	
	// orginal hard coded version
	/*$("#fip-01").click(function(event) {
		event.preventDefault();
		$("#fip-01-text").slideToggle();
		$("#fip-01-text").addClass(".selected");
		pageTracker._trackEvent('windowshade', 'expand', $(this).html());
	});


	/* panel set up */
	$(".panel-title").click(function(){
			var $this = $(this);
			if( $this.is('.panel-title') ) {
					$this.removeClass('panel-title');
					$this.addClass('panel-title-selected');
			}
			else {
					$this.removeClass('panel-title-selected');
					$this.addClass('panel-title');
			}
			return false;
	});
	/* this gets rid of the annoying dotted outline in IE */
	$(".panel-title").focus(function(){
			var $this = $(this);
			$this.blur();
			return false;
	});
	/* this sets the first item on FI page to animate open */
	$(window).load(function () {
		// run code
		$("#one-text").slideToggle();	
		$("#one").removeClass('panel-title');
		$("#one").addClass('panel-title-selected');
	});	
		
			
	// universal player deep link video catalog
	$("a.button-silver-video").click(function(){
		
		// This function is used with the _video_test.shtml page and simply created deeplinks to paste into the Video spreadsheet in EDMS
		
		var myRel = $(this).attr('rel');
		
		if (myRel == "video_32"){
			value1 = "a20100364_pyr_jtimmer_state_of_market"; 					// name of video at akamai e.g. "a20100364_pyr_jtimmer_state_of_market". no http, no .flv at the end
			value2 = "State of the Market Client Update Q1 2010"; 				// title of video e.g. "State of the Market Client Update Q1 2010"
			value3 = "null";													// name of transcript xml file. use "null" for none. example: "http://pyramis.edgesuite.net/videos/22390_pyr_emerging_markets_equity_and_your_pension_plan_062409_transcript.xml"
			value4 = "null"; 													// name of pdf attachment (downloads/FILENAME.PDF). use "null" if none. make sure is published on pyramis.com first
			value5 = "site"; 													// tracking value. use "site" for internal links. use "us_chin", "uk_chin", "hk_chin" for homepage video. you can use something else for external, but Google Campaigns has this tracked now.
			value6 = "false"; 													// autoplay value. default is "false". use "false" for external deeplinks. use "true" for internal links.  
			tab = "#tabs-1"; 													// tabs-1 is the current tab on the MI page. if you don't set this, user will land on MI boilerplate page with no video

			vidDeepLink = "value1=" + value1 + "&value2=" + value2 + "&value3=" + value3 + "&value4=" + value4 + "&value5=" + value5 + "&value6=" + value6 + tab;

			alert(vidDeepLink);
			ofPopWinVideo(vidDeepLink);		
		}
		
		if (myRel == "video_33"){
			value1 = "a20100966_pyramis_pulse_3_17";		 					// truncated name of video at akamai e.g. "a20100364_pyr_jtimmer_state_of_market". no http, no .flv at the end
			value2 = "Endowment and Foundation Pulse Poll Results"; 			// title of video e.g. "State of the Market Client Update Q1 2010"
			value3 = "null";													// name of transcript xml file. use "null" for none. example: "http://pyramis.edgesuite.net/videos/22390_pyr_emerging_markets_equity_and_your_pension_plan_062409_transcript.xml"
			value4 = "null"; 													// name of pdf attachment (downloads/FILENAME.PDF). use "null" if none. make sure is published on pyramis.com first
			value5 = "site"; 													// tracking value. use "site" for internal links. use "us_chin", "uk_chin", "hk_chin" for homepage video. you can use something else for external, but Google Campaigns has this tracked now.
			value6 = "false"; 													// autoplay value. default is "false". use "false" for external deeplinks. use "true" for internal links.  
			tab = "#tabs-1"; 													// tabs-1 is the current tab on the MI page. if you don't set this, user will land on MI boilerplate page with no video

			vidDeepLink = "value1=" + value1 + "&value2=" + value2 + "&value3=" + value3 + "&value4=" + value4 + "&value5=" + value5 + "&value6=" + value6 + tab;

			alert(vidDeepLink);
			ofPopWinVideo(vidDeepLink);		
		}
		
		if (myRel == "video_34"){
			value1 = "a20101050__pyramis_large_cap_3_19_10";		 					// truncated name of video at akamai e.g. "a20100364_pyr_jtimmer_state_of_market". no http, no .flv at the end
			value2 = "Focused Large Cap Growth Portfolio Manager Interview"; 	// title of video e.g. "State of the Market Client Update Q1 2010"
			value3 = "null";													// name of transcript xml file. use "null" for none. example: "http://pyramis.edgesuite.net/videos/22390_pyr_emerging_markets_equity_and_your_pension_plan_062409_transcript.xml"
			value4 = "null"; 													// name of pdf attachment (downloads/FILENAME.PDF). use "null" if none. make sure is published on pyramis.com first
			value5 = "site"; 													// tracking value. use "site" for internal links. use "us_chin", "uk_chin", "hk_chin" for homepage video. you can use something else for external, but Google Campaigns has this tracked now.
			value6 = "false"; 													// autoplay value. default is "false". use "false" for external deeplinks. use "true" for internal links.  
			tab = "#tabs-1"; 													// tabs-1 is the current tab on the MI page. if you don't set this, user will land on MI boilerplate page with no video

			vidDeepLink = "value1=" + value1 + "&value2=" + value2 + "&value3=" + value3 + "&value4=" + value4 + "&value5=" + value5 + "&value6=" + value6 + tab;

			alert(vidDeepLink);
			ofPopWinVideo(vidDeepLink);		
		}

	});
	
	// universal player deep link launcher
	function ofPopWinVideo(url) {
		location.href=("http://www.pyramis.com/market-insights.shtml?"+url)
		/*location.href=("http://sbos472.fmr.com:8080/FMTC/pyramis_systems/pyramis_public/market-insights.shtml?"+url)*/
	}
		
	/*setTimeout('loadVideo()',2000)*/
	
	
	
	
}); // END document ready

$.fn.hoverClass = function(c) {
   return this.each(function(){
      $(this).hover( 
         function() { $(this).addClass(c);  },
         function() { $(this).removeClass(c); }
      );
   });
};

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}


/* end */
