$(document).ready(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
	var locationPath = filterPath(location.pathname);
  	$('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
	   $(target).children('.animation').hide();
	   $(target).children('.animation').animate({width:'+=1',opacity:'0.0'},1);
	   $(this).parents('.animation').children('.animation_div_table').hide();
        $(this).click(function(event) {
          event.preventDefault();
		var w_table = $('#main_table').width();
		 var tar = this.hash;
		 var fc = tar.substr(2,1);
		 var lc = tar.substr(tar.length-1,2);
		 var nt = tar.substr(3,tar.length);
		 //var fc = tar.substr(1,1);
		 //var lc = tar.substr(tar.length-1,1);
		 //var nt = tar.substr(2,tar.length);
		 nt = '#'+nt;
		var x = $(this).parents('div.scroller_data');
		$(this.hash).children('.animation').animate({width:'+=1'},1);
		$(this.hash).children('.animation').children('.animation_div_table').show();
		var _anim_width =  $(this.hash).children('.animation').children('.animation_div_table').width();
		var _anim_height =  $(this.hash).children('.animation').children('.animation_div_table').height();
		$(this.hash).children('.animation').animate({height: _anim_height ,opacity: "1.0", marginLeft:'3px', width:'10px'}, 200);
		$(this.hash).children('.animation').queue(function () {
				var p = $(target);
				var position = p.position();
      			 $('.scrollWrapper:not(:animated)').animate({scrollLeft: position.left}, 800, function() {
          			  location.hash = target;
		 		 });
				 x.hide();
			   	$('.animation').dequeue();
					isScrollBottom(position.left,w_table+(_anim_width-432));		
		});
		$(this.hash).children('.animation').animate({width:_anim_width}, 500);
		$(this.hash).children('.animation').queue(function () {
				var p = $(target);
				var position = p.position();
      			 $('.scrollWrapper:not(:animated)').animate({scrollLeft: position.left}, 300, function() {
          			  location.hash = target;
		 		 });
			   	$('.animation').dequeue();
					isScrollBottom(position.left,w_table+(_anim_width-432));		
		});	
		if(fc==lc)
		 {
			var pgwidth = document.body.clientWidth;
			pgwidth -= 432;
			pgwidth /=2;
			var _anim_width =  $(nt).children('.animation').children('.animation_div_table').width();
			if(_anim_width>0)
				pgwidth = 0;
			$(nt).children('.animation').queue(function () {
				var p = $(nt);
				var position = p.position();
      			 $('.scrollWrapper:not(:animated)').animate({scrollLeft: position.left-pgwidth}, 300, function() {
          			  location.hash = nt;
		 		 });
			   	$('.animation').dequeue();
					isScrollBot(position.left-pgwidth,w_table);
			});
		}
		/*else if(target == '#article8')
			$('.contact_us').attr('href','#8article8');*/
		else if(target == '#article12')
			$('.contact_us').attr('href','#12article12');
	});
	}}
  });
});
function showWidth(ele, w) {return w; }

$(document).ready(function() {
   $("a.link").click(function() {
	var divlength= $('.main_table').width();
	var divlength2= $('.scrollWrapper').width();
	var maindiv = $(".main_table").innerWidth();
   });
   $('.contact_us').click(function(){
				 $('#contact').hide();
	});
   $('.new_div_close').click(function() {
		/*if(this.hash == '#close_id8')
			$('.contact_us').attr('href','#article8');*/
		if(this.hash == '#close_id12')
			$('.contact_us').attr('href','#article12');
		var y = $(this.hash).children('.scroller_data');
		$(this.hash).children('.scroller_data').animate( {opacity:'0.0'}, 1 , function() { y.show();  } );
		$(this).parents('.animation').animate({width:'0px'}, 100);
		var pr = $(this).parents('.animation');
	   	var positionr = pr.position();
		BrowserDetect.init();
		var browserVersion = BrowserDetect.version;
		var browserName = BrowserDetect.browser;
		if((browserVersion < 3.2 && browserName == 'Safari') || (browserName != 'Safari'))
		{
			$(this).parents('.animation').animate({height:'0', marginLeft:'0px'}, 100);
		}
		var scrollAmt = 100;
		if(browserName == 'Safari' )
			scrollAmt = 50;
		if(browserName == 'Explorer')
		{
			scrollAmt = 100;
		}
		$(this).parents('.animation').animate({opacity: "0.0"},100);
		var x = $(this).parents('.animation').children('.animation_div_table');
		$(this.hash).children('.scroller_data').animate( {opacity:'1.0'}, 1); 
		$(this.hash).children('.scroller_data').animate( {width:'436px'}, 100 );
		$('.scrollWrapper:not(:animated)').animate({scrollLeft: positionr.left - 200 }, scrollAmt, function()
		{	x.hide(0);	});
		var w_table = $('#main_table').width();
		isScrollBot(positionr.left-200,w_table);
		
	});
});
$(document).ready(function () {
    $(".scrollingHotSpotLeft").css({opacity: "0.0"});
});
$(document).ready(function(){
	$(".image_footer_logo").hover(function() {
		$(this).find("img").animate({opacity: "0.0"}, 500);
		}, function() {
		$(this).find("img").animate({opacity: "1.0"}, 300);
	});
});
$(document).ready(function(){
	$(".scrollingHotSpotLeft").hover(function(){
		$(this).animate({opacity: "0.9"}, 100)
	},
	function () {
        $(this).animate({opacity: "0.0"}, 100)
	});
});
$(document).ready(function () {
    $(".scrollingHotSpotRight").css({opacity: "0.0"});
});
$(document).ready(function(){
	$(".scrollingHotSpotRight").hover(function(){
		$(this).animate({opacity: "0.9"}, 200)
	},
	function () {
        $(this).animate({opacity: "0.0"}, 200)
	});
});
$(document).ready(function(){
	$(".scroll_arw a.arw").hover(function() {
		$(this).find("span").animate({opacity: "show", top: "-78"}, "slow");
		}, function() {
		$(this).find("span").animate({opacity: "hide", top: "-95"}, "fast");
	});
});

function isScrollBot(wd,tw) 
{
	if(wd<0)
		wd = 0;
	var obj = document.getElementById('scroll_footer');
	var pgwidth = document.body.clientWidth;
	var pgW = pgwidth;
	$('#scroll_footer').css('width',(pgwidth/10)+'px');
	pgwidth /= 2;
	pgwidth -= (pgW/10)+10;
	wd1 = (wd/(tw-pgW))*pgwidth;
	var scrollWidth = obj.style.left;
	scrollWidth = scrollWidth.substr(0,scrollWidth.length-2);
	if(scrollWidth=='')
		scrollWidth = 0;
	if((scrollWidth-wd1) > 5 ||  (wd1-scrollWidth) > 5)
	{
		if(wd1 < pgwidth)
			$("#scroll_footer").animate({left:wd1+'px'},100);
		else
			$("#scroll_footer").animate({left:pgwidth+'px'},100);
	}
} 
