$(document).ready(function(){

/*
$('#mainMenu li, .frontRightMenuBlack ul li').hover(function(){
		$(this).addClass('hover');			 
	},function(){				
		$(this).removeClass('hover');	
})
*/


$("ul.mainMenu > li").hover(function(){

			$(this).children().next().css("display","block");

		},function(){
		
			$(this).children().next().css("display","none");
	});

	
	
$("#mainContent #contentDownload input.ButtonSubmit").click(function(){
      if(Page_IsValid){
        $(this).attr("disabled", "disabled");
        }
});


	
	
$("#sitemap ul li img").click(function(){

		if($(this).attr('src')=='/images/maximise.gif'){
			$(this).attr('src','/images/minimise.gif');
			$(this).next().next().css("display","block");
		
		}
		else{
		 if($(this).next().next().css("display") == "block"){
			$(this).attr('src','/images/maximise.gif');
			$(this).next().next().css("display","none");
			}
		}

});

//$("input.searchText").click(function(){
//       $(this).select();
//});

 $(".hightLigh a.randomHL").each(function(){
                $(this).trigger('click');
        });

//this is for seasrch
var searchTxtValue =  jQuery('#querySearch').val();

jQuery('#querySearch').focus(function () {	 
	 jQuery(this).attr("value","");
	
});


jQuery("#querySearch").keypress(function (e) {
	if (e.which == 13) {
		return false;
	 	document.location.replace("/search.aspx?cx=006471719688142198866%3Aihmg_8q2czc&cof=FORID%3A11%3BNB%3A1&q="+ jQuery('#querySearch').val() + "&sa.x=26&sa.y=9&sa=submitname");	
	} 
});



jQuery("#querySearch").blur(function () {
	if ( jQuery(this).val() == "" ){
		jQuery(this).attr("value",searchTxtValue)
	}
});



/*
// This is the older, ordered syntax
	sIFR.replaceElement("h5#pullquote", "tradegothic.swf", "#000000", "#000000", "#FFFFFF", "#FFFFFF", 0, 0, 0, 0);
	sIFR.replaceElement("h2", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0);
	sIFR.replaceElement("h4.subhead", "tradegothic.swf", "#660000", null, null, null, 0, 0, 0, 0);
	sIFR.replaceElement("h3.sidebox","tradegothic.swf","#000000", "#000000", "#DCDCDC", "#DCDCDC", 0, 0, 0, 0, null);
	sIFR.replaceElement("h3", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0, null);
*/

jQuery(".templateAjax").each(function() {

   //different position and different timeout for highlights from different location
   var position ="leftColumn";
   var timeOutDelay = new Array();
   var pos = 0;
   if(jQuery(this).parent().parent().attr("class") == "frontPageMiddleCol"){
    position = "centralColumn";
    pos=1;
   }
   else if (jQuery(this).parent().parent().attr("class") == "frontPageRightCol"){
    position = "rightColumn";
    pos=2;
   }
   
   
   
   jQuery(this).load(document.location.pathname +"?p=3&position="+ position,function(){
   //jQuery(".highlightList").append(jQuery(".highlightItem:first").html())
    var highlight = "." + position + " .highlightItem";
    var highlightFirst = "." + position + " .highlightItem:first";
    var highlightList = "." + position + " .highlightList"; 
    
    var bntPrev = "." + position + " .bntPrev"; 
    var bntNext = "." + position + " .bntNext"; 
    var bntPause = "." + position + " .bntPause"; 
    var bntPlay = "." + position + " .bntPlay"; 
    
    //the first highlight is clonned and added at the end
    
    var lastOne = jQuery(highlightFirst).clone().appendTo(highlightList).attr("class","highlightItem lastOne");

    //I read the highlights controls from hiddenfield
    var sitecoreText = jQuery("#htextandinterval").val().split('|');
	jQuery(this).append('<div class="btnHighlights"><span class="bntPrev">'+sitecoreText[0]+'</span> <span class="bntPause">'+sitecoreText[3]+'</span><span class="bntPlay">'+sitecoreText[2]+'</span> <span class="bntNext">'+sitecoreText[1]+'</span></div>');
	
    // apply the sIFR for ie6 after the data is loaded
    
  // 27.04.2010   <!-- APE disable siFR for zh-CN  -->
            if (!(sIFR ==null)) {

 sIFR.replace(centurygothic, {
  selector: '#frontPageContent .frontPageRightCol h2',
  css: '.sIFR-root { background-color: #FFFFFF; color: #ea7b04; font-weight: bold; text-align: right; line-height: 20px;}',
  wmode: 'transparent'
});

sIFR.replace(centurygothic, {
  selector: '#frontPageContent .frontPageRightCol h3',
  css: '.sIFR-root { background-color: #FFFFFF; color: #ea7b04; text-align: right; text-transform: uppercase; line-height: 20px;}',
  wmode: 'transparent'
});
   
    
  sIFR.replace(centurygothic, {
      selector: '#frontPageContent h2',
      css: '.sIFR-root { background-color: #FFFFFF; color: #000000; font-weight: bold; line-height: 20px;}',
      wmode: 'transparent'
    });
    sIFR.replace(centurygothic, {
      selector: '#frontPageContent h3',
      css: '.sIFR-root { background-color: #FFFFFF; color: #4D9EEC; font-weight: bold; line-height: 1em; line-height: 20px;}',
      wmode: 'transparent'
    });

}

	//read the script for animation from hiddenfield
	var sitecoreAnimate = jQuery("#hanimatescript").val();
	
	jQuery(bntPlay).hide();
	var listItemsTotalNr = Number( jQuery(highlight).size());	
	var highlightWidth = 300;

	var currentItemPos = 0;
	var listItemsWidth = listItemsTotalNr * highlightWidth;
	var nextPos = 0;
	jQuery(highlightList).css({width: listItemsWidth + "px"})


	jQuery(bntNext).click(function(){	
		var rightVarNr = parseInt(jQuery(highlightList).css("right"));
		currentItemPos = parseInt(rightVarNr/highlightWidth + 1);
		
		if(currentItemPos == listItemsTotalNr){
			jQuery(highlightList).css({right: "0"})
		   	currentItemPos = 1;
		}
		jQuery(bntPause).hide();
		jQuery(bntPlay).show();
		clearTimeout(timeOutDelay[pos]);
		animateHighlight(currentItemPos);
	})
	
	jQuery(bntPrev).click(function(){

		var rightVarNr = parseInt(jQuery(highlightList).css("right"));
		if((rightVarNr/highlightWidth >=0) && (rightVarNr/highlightWidth < 1)){
		     currentItemPos = parseInt(rightVarNr/highlightWidth - 1);
		}
		else
		currentItemPos = parseInt(rightVarNr/highlightWidth - 0.5);
		
		if(currentItemPos == -1){
			jQuery(highlightList).css({right: (listItemsWidth-highlightWidth)+"px"})
			currentItemPos = listItemsTotalNr - 2;
		}							
		jQuery(bntPause).hide();
		jQuery(bntPlay).show();	
		clearTimeout(timeOutDelay[pos]); 
		animateHighlight(currentItemPos);
	})


    jQuery(bntPause).click(function(){
		clearTimeout(timeOutDelay[pos]); 
		jQuery(bntPause).hide();
		jQuery(bntPlay).show();
    })
    
    jQuery(bntPlay).click(function(){
        
		jQuery(bntPause).show();
		jQuery(bntPlay).hide();
		clearTimeout(timeOutDelay[pos]); 
		var rightVarNr = parseInt(jQuery(highlightList).css("right"));
		currentItemPos = parseInt(rightVarNr/highlightWidth + 1);
		if(currentItemPos == listItemsTotalNr){
			jQuery(highlightList).css({right: "0"})
		   	currentItemPos = 1;
		}
		animateHighlightAutoSlide(currentItemPos);
    })
    
	//the highlids will slide on click
	function animateHighlight(currentItemPos){
	    animateHighlights(highlightList, currentItemPos, highlightWidth)
	/*	jQuery(highlightList).stop().animate({ 
			right: (currentItemPos * highlightWidth) +"px"							 
		}, sitecoreText[5]) */
	}

	//the highlids will slide automatically
	function animateHighlightAutoSlide(currentItemPos){
       animateHighlights(highlightList, currentItemPos, highlightWidth)
	/* 	jQuery(highlightList).stop().animate({ 
			right: (currentItemPos * highlightWidth) +"px"							 
		}, sitecoreText[5]);*/
		timeOutDelay[pos] = setTimeout(function () {
			currentItemPos ++;
			if (currentItemPos==listItemsTotalNr){
				jQuery(highlightList).css({right: "0"})
		   		currentItemPos = 1;
			}
			animateHighlightAutoSlide(currentItemPos)
		}, sitecoreText[4]); 

	}
	
	//after the page is loaded, the autoSlide will play	
	timeOutDelay[pos] = setTimeout(function () {
		currentItemPos ++;
		animateHighlightAutoSlide(currentItemPos)
	}, sitecoreText[4]); 

	
})

});
   
});
