// JavaScript Document
	/*$('#s1').cycle({ 
		fx:     'scrollRight',  
		delay:  -2000 
	});*/
	jQuery(function(){  

		$('a[rel*=fancybox]').fancybox();
		//Get our elements for faster access and set overlay width  
		var div = jQuery('div.sc_menu');             
		ul = jQuery('ul.sc_menu');
		var ulWidth = 0;
		var i=0;
		$('ul.sc_menu img').each(function() {
			ulWidth += $(this).width();
			i++;
		});
	//	alert(i);
	//	alert(ulWidth);
		ul.css('width',9273+'px');

		// unordered list's left margin               
		ulPadding = 0;  
		//Get menu width  
		var divWidth = div.width();  
		//Remove scrollbars  
		div.css({overflow: 'hidden'});  
		//Find last image container  
		var lastLi = ul.find('li:last-child');  
		//When user move mouse over menu  
		div.mousemove(function(e){    
			//As images are loaded ul width increases,    
			//so we recalculate it each time    
			var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;    
			var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;    
			div.scrollLeft(left);  
		});
		//ipad only touch function
		/*
		div.bind('touchmove',function(e){
			  e.preventDefault();
			  var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
			  var elm = $(this).offset();
			  var x = touch.pageX - elm.left;
			  var y = touch.pageY - elm.top;
			  if(x < $(this).width() && x > 0){
				  if(y < $(this).height() && y > 0){
						  //CODE GOES HERE
						  //console.log(touch.pageY+' '+touch.pageX);
						  
						  var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;    
							var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;    
							div.scrollLeft(left); 
				  }
			  }
		});
		*/


$('#goRight').bind('mousedown touchstart',function(e) {
  	e.preventDefault();
	div.animate({scrollLeft : "+="+9273+"px"},
		{step: function(now, fx) {
		  },
		  duration:3000,
		  easing:"swing",
		  complete: function () {}
		}); //end animate 
}).bind('mouseup touchend',function() {
	div.stop(true,false);
});

$('#goLeft').bind('mousedown touchstart',function(e) {
  	e.preventDefault();
	div.animate({scrollLeft : "-="+9273+"px"},
		{step: function(now, fx) {
		  },
		  duration:3000,
		  easing:"swing",
		  complete: function () {}
		}); //end animate 
}).bind('mouseup touchend',function() {
	div.stop(true,false);
});



		
		//-----------map functions--------------
		 var id;
		 var pinId;
		$('area').mouseenter(function(event) {
			 // createTooltip.call(this, event);
			id=$(this).attr('id');
			pinId=id.replace("area", "")
			 $('#'+pinId).show();
			// $('.mapPin').show();
		
		 })
		 $('area').mouseleave(function(){
			// create a hidefunction on the callback if you want
			 $('#'+pinId).hide();
		 });
		 $('area').click(function(event) {
			$('#belowMap').show();
			$('.info').hide();
			id=$(this).attr('id');
			infoId=id.replace("area", "info");
			
			
			var arrayAllROW = allROWmapkeys.split(",");
			
			/*if(infoId=="SAinfo" || infoId=="Asiainfo" || infoId=="Centinfo" || infoId=="MidEasinfo"){
				infoId="ROWinfo";
			}*/
			if(jQuery.inArray(infoId, arrayAllROW) > -1){
				infoId="ROWinfo";
			}
			$('#'+infoId).show();
			// $('.mapPin').show();
		
		 });
		 // this ones for teh pins
		 $('.mapPin').click(function(event) {
			$('#belowMap').show();
			$('.info').hide();
			id=$(this).attr('id');
			infoId=id+"info";
			
			if(infoId=="SAinfo" || infoId=="Asiainfo" || infoId=="Centinfo" || infoId=="MidEasinfo"){
				infoId="ROWinfo";
			}
			$('#'+infoId).show();
			// $('.mapPin').show();
		
		 });
		 $('#showAll').click(function(event) {
			 $('#belowMap').show();
			$('.info').show();
		 });
		
		//----------expandable headings --------------

		  
		  jQuery("ul#Links > li").click(function(){
		
			 
				jQuery(this).children("ul").slideToggle(400);
				
			jQuery(this).toggleClass('expanded')
		
		  });
		  //close all
		  //jQuery("ul#Links > li").click();
		  		  //expand first one
		 // jQuery("ul#Links > li:first").click();
		  	//start header slidshow
		startHead=setInterval( "headSwitch()", 4000 );   
	});

	
	var startHead;
	function headSwitch(slideNo) {
	//alert ("headSwitch srunning");
		var $active = jQuery('#header span.active');
	   
		if ( $active.length == 0 ){
			$active = jQuery('#header span:last');
		}
		
		if(slideNo==null){
			var $next =  $active.next('span').length ? $active.next('span')
				: jQuery('#header span:first');
			
		}else{
			if($active.attr('id')!="header"+slideNo){
				clearInterval(startHead);
				var $next = jQuery('#header span#header'+slideNo);
				
			}
		}
		$active.addClass('last-active');
		
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
	   $active.removeClass('active last-active');
			});
		
	}
