/**
 * 
 *  Common used functions for JQuery
 *
 */


$(document).ready(function () {	
							
	/* show accordion */
	$(".accordion-col").css("display","block");

							
	/* tabs for equity page */
	$("#tabs").tabs();
	
	/* show 'contact' accordion panel by default */
	$('#term-of-use #acc-contact-us, #privacy-policy #acc-contact-us, #market-insights #acc-contact-us, #news #acc-contact-us, #us-home #acc-pyramis-glance, #about-us #acc-pyramis-glance, #investment-approach #acc-pyramis-glance').addClass('selected');	
	
							
	/* 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"); } 
	);
	/* 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 */
	$('#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 */
	
	
		/* panel set up */
	$('.panel-title')
		.click(function(){
			if ($(this).parent().is('.panel-title-selected')) {
				$(this).parent().removeClass('panel-title-selected');
			}
			else {
				$(this).parent().addClass('panel-title-selected');
			};
			$(this).next().slideToggle();
			return false;
		})
		.focus(function(){
			$(this).blur();  /* this gets rid of the annoying dotted outline in IE */
		});
	
	/* this sets the first item on FI page to animate open */
	$('.panel-title-selected .panel-item-text').slideToggle();	
		
			
	// universal player deep link video catalog
	$("a.button-silver-video").click(function(){
		
		var myRel = $(this).attr('rel');
						
		if (myRel == "video_01"){
			ofPopWinVideo('value1=22273_chin_4_13_q1_market_outlook&value2=Investment Perspectives: Q1 2009&value3=22273_chin_4_13_q1_market_outlook&value4=null&value5=site');
		}
		
		if (myRel == "video_02"){
			ofPopWinVideo('value1=22275_chiappenelli_4_8_gasb_45&value2=GASB 45: Trillion Dollar Deficits&value3=22275_chiappenelli_4_8_gasb_45&value4=http://www.pyramis.com/downloads/pyramis_gasb_wp_proof_2_26_09.pdf&value5=site');
		}
		
		if (myRel == "video_03"){
			ofPopWinVideo('value1=22274_morgart_3_27_institutionalization_hedge_funds&value2=Institutionalization of Hedge Funds&value3=22274_morgart_3_27_institutionalization_hedge_funds&value4=null&value5=site');
		}
		
		if (myRel == "video_04"){
			ofPopWinVideo('value1=22274_morgart_3_27_market_neutral_investing&value2=Equity Market Neutral Investing&value3=22274_morgart_3_27_market_neutral_investing&value4=null&value5=site');
		}
		
		if (myRel == "video_05"){
			ofPopWinVideo('value1=22324_goolgasian_lifecycle&value2=Lifecycle Perspectives&value3=22324_goolgasian_lifecycle&value4=null&value5=site');
		}
		
		if (myRel == "video_06"){
			ofPopWinVideo('value1=22390_pyr_emerging_markets_equity_and_your_pension_plan_062409&value2=Emerging Markets Equity and Your Pension Plan&value3=22390_pyr_emerging_markets_equity_and_your_pension_plan_062409_transcript&value4=null&value5=site');
		}
		
		if (myRel == "video_07"){
			ofPopWinVideo('value1=22295_pyr_jtimmer_stateofmarket_060509&value2=The State of the Market&value3=22295_pyr_jtimmer_stateofmarket_060509&value4=null&value5=site');
		}
		
		if (myRel == "video_08"){
			ofPopWinVideo('value1=22382_chin_1_26_perspectives08_outlook09&value2=Viewpoint: Perspectives 2008, Outlook 2009&value3=22382_chin_1_26_perspectives08_outlook09&value4=null&value5=site');
		}
		
		if (myRel == "video_09"){
			ofPopWinVideo('value1=22383_pyramis_case_for_intl_value_investing&value2=The Case for International Value Investing&value3=22383_pyramis_case_for_intl_value_investing_transcript&value4=null&value5=site');
		}
		
		if (myRel == "video_10"){
			ofPopWinVideo('value1=22384_pyramis_international_total_market_investing&value2=International Total Market Investing&value3=22384_pyramis_international_total_market_investing_transcript&value4=null&value5=site');
		}
		
		if (myRel == "video_11"){
			ofPopWinVideo('value1=22439_pyr_focus_large_cap_growth_070909_v3&value2=Focused Large Cap Growth&value3=22439_pyr_focus_large_cap_growth_070909_v3_transcript&value4=null&value5=site');
		}
		
		if (myRel == "video_12"){
			ofPopWinVideo('value1=22341_pyramis_small_cap_core_strategy_042709&value2=Small Cap Core Strategy&value3=22341_pyramis_small_cap_core_strategy_042709_transcript&value4=null&value5=site');
		}
		
		if (myRel == "video_13"){
			ofPopWinVideo('value1=22440_pyramis_young_chin_q2_2009&value2=Investment Perspectives: Q2&value3=null&value4=null&value5=site');
		}
		
		if (myRel == "video_14"){
			ofPopWinVideo('value1=22453_pyramis_chris goolgasian_071309&value2=Backtesting Lifecycle Funds&value3=null&value4=downloads/lifecycle_depression_whitepapers.pdf&value5=site');
		}

		if (myRel == "video_15"){
			ofPopWinVideo('value1=22462_pyramis_heffernan_market_neutral_strategies_073109&value2=Y. Chin and T. Heffernan Interview&value3=null&value4=null&value5=site');
		}

		if (myRel == "video_16"){
			ofPopWinVideo('value1=22463_pyramis_hernandez_select_international_073109&value2=Y. Chin and C. Hernandez Interview&value3=null&value4=null&value5=site');
		}

		if (myRel == "video_17"){
			ofPopWinVideo('value1=22466_pyramis_chiappinelli_asset_allocation_client_update_072009&value2=US Pensions Maintain Long Term Investment Views&value3=null&value4=null&value5=site');
		}

		if (myRel == "video_18"){
			ofPopWinVideo('value1=22464_pyramis_jurrien_timmer_state_of_the_market_070909&value2=The State of the Market&value3=null&value4=null&value5=site');
		}
		
		/* moved to uk site 
			if (myRel == "video_19"){
			vidUrl = "value1=22440_pyr_young_chin_q2_UK_ver&value2=Recap: Second Quarter Investment Perspectives&value3=null&value4=null&value5=site"
			alert(vidUrl);
			ofPopWinVideo(vidUrl);
		} */

		if (myRel == "video_20"){
			ofPopWinVideo('value1=a20093885_pyramis_risk_management_baker_part_01&value2=Investment Risk Management Pt I&value3=null&value4=downloads/operational_risk_white_04-17-09.pdf&value5=site');
		}

		if (myRel == "video_21"){
			ofPopWinVideo('value1=a20093885_pyramis_risk_management_baker_part_02&value2=Investment Risk Management Pt II&value3=null&value4=downloads/operational_risk_white_04-17-09.pdf&value5=site');
		}
		
		if (myRel == "video_22"){
			vidUrl = "value1=a20093885_pyramis_risk_management_baker_part_03&value2=Investment Risk Management Pt III&value3=null&value4=downloads/operational_risk_white_04-17-09.pdf&value5=site"
			alert(vidUrl);
			ofPopWinVideo(vidUrl);
		}

		if (myRel == "video_23"){
			ofPopWinVideo('value1=a20093164_pyramis_international_growth_strategy&value2=International Growth Strategy Update Q209&value3=null&value4=null&value5=site');
		}
		
		if (myRel == "video_24"){
			vidUrl = "value1=a20093159_pyramis_small_cap_core_strategy&value2=Small Cap Core Strategy Update Q209&value3=null&value4=null&value5=site"
			alert(vidUrl);
			ofPopWinVideo(vidUrl);
		}
		if (myRel == "video_25"){
			vidUrl = "value1=a20093875_pyramis_credit_in_crisis_senosky_082409&value2=Credit in Crisis&value3=null&value4=null&value5=site"
			alert(vidUrl);
			ofPopWinVideo(vidUrl);
		}
		

	});
	
	// universal player deep link launcher
	function ofPopWinVideo(url) {
		location.href=("http://www.pyramis.com/market-insights.shtml?"+url)
	}
		
	/*setTimeout('loadVideo()',2000)*/
	
});

$.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]);
  }
}
