/*
Initilise our stuff 
*/
//$(function () {
$(window).load(function () {

	
	// =======================================	
	// Expander-collapser
	// =======================================
	var trigger = $('a.expandTrigger');
	trigger.each(function() {
		var link = $(this);
		var wrapper = link.parents('.expanding');
		var content = wrapper.find('.content');
		if (wrapper.hasClass('collapsed')) {
			content.css({display: 'none'});
		} else {
			content.css({display: 'block'});
		}
		
		link.click(function click_expandCollapse(e) {
			content.slideToggle('fast');
			wrapper.toggleClass('collapsed');
			updateLabel();
			e.preventDefault();
		});
		
		var label = link.attr('title').split('|');
		link.attr('title', '');
		
		var updateLabel = function() {
			if (wrapper.hasClass('collapsed')) {
				link.text(label[0]);
			} else {
				link.text(label[1]);
			}
			
		};
		updateLabel();
	});
	

	
	// =======================================	
	// Secondary Indices collapsing and expanding
	// =======================================
	var secondaryIndices = $('li.secondaryIndices');
	if (secondaryIndices.length > 0) {
		secondaryIndices.each(function() {
			var link = $(this).find('> a');
			link.click(function(e) {
				var t = $(this);
				t.parent().toggleClass('active');
				e.preventDefault();
			});
		});
	}
	// =======================================	
	// Clear all fields button in form
	// =======================================
	var clearFields = $('a.clearFields');
	clearFields.each(function() {
		var link = $(this);
		link.click(function click_clearFields(e) {
			var form = $(this).parents('form');
			form.find('input').val('');
			form.find('select option:first-child').attr('selected', 'selected');
			form.find('input:checked').removeAttr('checked');			
			e.preventDefault();
		});
	});



	// =======================================	
	// Aside (RHS) Drop downs
	// =======================================
    var rhsconfig = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 50,  // number = milliseconds for onMouseOver polling interval    
         over: function(){ $(this).find('ul.asideDD').addClass('hover'); },   // function = onMouseOver callback (REQUIRED)    
         timeout: 750,   // number = milliseconds delay before onMouseOut    
         out: function(){ $(this).find('ul.asideDD').removeClass('hover'); }     // function = onMouseOut callback (REQUIRED)    
    };
	$(".asideDDToggle").hoverIntent(rhsconfig);



	// =======================================	
	// FIX IE6 select/z-index issue; Hide select when hovering over #nav. Thanks Moderizr!
	// =======================================
	if ( $('html').attr('class').match('ie6') !== null ) {	
		
		$('#nav .navLevel1, #clientLogin').hover(function () {
			$('.navPageLinks').css('visibility','hidden');	
		},function(){
			$('.navPageLinks').css('visibility','visible');		
		});	
	};
	
	
	
		// =======================================	
		// Accordion
		// =======================================	

		$('.mod.clientServices h3').click(function() {
			$(this).find('span').toggleClass('open');
			$(this).next().toggle();
			
			return false;
		}).next().hide();





	// =======================================	
	// Tabs 
	// =======================================
	var tabContainers = $('div#tabs > div');
	tabContainers.hide().filter(':first').show();

	$('div#tabs ul.tabs a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#tabs ul.tabs a').parent().removeClass('selected');
		$(this).parent().addClass('selected');
		return false;
	}).filter(':first').click();
	


	
	
	// =======================================	
	// Carousel init  
	// =======================================	
	var carConfig = {
        scroll: 3,
		speed: 600,
		circular: false,
        btnNext: ".carouselControl .next",
        btnPrev: ".carouselControl .prev"
    };
	// chinese homepage has static content
	jQuery("#carouselStatic").parent().jCarouselLite(carConfig);
	jQuery("#carousel").parent().jCarouselLite(carConfig);
	if (Math.random() > 0.5) {
	   $('#content .insights .next').click();
   }



	// =======================================	
	// Apply Equal Heights 
	// =======================================

	applyEqualHeights();

	// =======================================	
	// Z-Index fix for IE7 
	// =======================================
	if ($('html').hasClass('ie7')){
		var zIndexNumber = 1000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	}
}); // Ready

	// =======================================	
	// popup for resource center
	// =======================================
    if (((window.location + ' ').indexOf('/resources/research_papers/') > -1) && (document.cookie + ' ').indexOf('MSCI_Overlay_research') == -1) {
        document.cookie = 'MSCI_Overlay_research=1';
        $(document).ready(function() {
            $('<div>' +
              '<h3>New Analytics Research Help Center</h3>' +
              '<p>From 24 February, 2012, the majority of our Analytics ' +
                'Research papers will only be accessible to our clients, ' +
                'via the new Analytics Research Help Center.  A limited ' +
                'number of Analytics Research and ESG Research articles, ' +
                'as well as all Index Research will remain available on ' +
                '<a href="http://www.msci.com">www.msci.com</a>.</p>' +
                '<p><a href="mailto:MarketingTeam@msci.com?subject=Analytics%20Research%20Help%20Center">' +
                'Please let us know if you have any questions.</a></p>' +
              '</div>').prependTo("body").dialog({
                draggable: false,
                modal: true,
                resizable: false,
                title: "Notice",
                width: 500,
                zIndex: 5001
                });
            $(".ui-dialog").css('position','fixed').css('top','300px');
            $(".ui-widget-overlay").css('position','fixed').css('top','0px');
        });

    }


	

