

var featureScrollID, diffBetwnScrollDivs;
var curImgNum=0;
var totalImages = 0;
//var numOfFlash = 0;

function changeBG(id){
/*	if(!($.browser.flash)){
		//alert('flash disable')
		if($.browser.msie){ 
			//alert("ie")
		    $('#visual_wrap').children().eq(curImgNum).hide();
		}
		else{
			$('#visual_wrap').children().eq(curImgNum).fadeOut('fast');
			//alert("not ie")
		}
	}
	else{
		//alert('flash enable')*/
	$('#visual_wrap').children().eq(curImgNum).hide();
	//}
		
	$('#background_change').children().eq(curImgNum).removeClass('active');    
    curImgNum = id - 1;
    rotateImage();     

}

$(document).ready(function(){
		//$(".top_nav > li").hover(
			//function(){$(this).find('ul').stop(true,true).slideDown()},
			//function(){$(this).find('ul').slideUp()}
		//);
		    
		 
		$("ul.top_nav > li, ul.top_nav li li").hover(
			function(){
				$(this).children('ul').stop(true,true).slideDown(); $(this).addClass('slctNav')
			},
			function(){
				$(this).children('ul').slideUp(); $(this).removeClass('slctNav')
			}
		);
		
		/*rotating ramdom image code */
		if($('#visual_wrap').hasClass('homeWrap')){ 
			totalImages=$('#visual_wrap').children().length;

			curImgNum=Math.floor(Math.random()*totalImages);// - numOfFlash;
			rotateImage();    
			setInterval('rotateImage()',80000);
		
		}

           
		//keep it static for divisionhome
		if($('#visual_wrap').hasClass('division_home1')){
			chkImgLoad(0);
		}
		
		//chkImgLoad(0);
		
		/*featureDlWidth=$('#add_contIn ul li:first').outerWidth()*$('#add_contIn ul li').length;
		diffBetwnScrollDivs=featureDlWidth-$('#add_contIn').width(); //alert(diffBetwnScrollDivs);
		$('#add_contIn ul').css('width',featureDlWidth);
		if(diffBetwnScrollDivs > 0){
			$('#add_cont .butn_pre, #add_cont .butn_next').hover(
				function(){
					if($(this).is('#add_cont .butn_next')){
						featureScrollID=setInterval('scrollFeature(-1)',5);}
					else
						featureScrollID=setInterval('scrollFeature(+1)',5);
				},
				function(){clearInterval(featureScrollID)}
			);
		}*/
		
		
		featureDlWidth=$('#add_contIn ul li:first').outerWidth()*$('ul.collection_detail_list li').length;
		diffBetwnScrollDivs=featureDlWidth-$('.collection_detailIn').width(); //alert(diffBetwnScrollDivs); 
		
		if($('#add_contIn ul').length > 0){
			featureDlWidth=$('#add_contIn ul li:first').outerWidth()*$('#add_contIn ul li').length;
			diffBetwnScrollDivs=featureDlWidth-$('#add_contIn').width(); //alert(diffBetwnScrollDivs); 	
			
			total=$('#add_contIn ul li').length;	
			$('#add_contIn ul').css('width',featureDlWidth);
			jq152('#add_cont .butn_pre, #add_cont .butn_next').click(
				function(){
					if(jq152(this).is('#add_cont .butn_next')){
						scrollFeature(-1,238,total);}
					else
						scrollFeature(1,238,total);
				}
			);
		}
		
		
		
		
		$("input.src_butn").hover(
			function(){$(this).css('background-position','left -20px')},
			function(){$(this).css('background-position','left top')}
		);
		
	
	
	/*$('ul.tab_list li').click(
		function() {
			if(!$(this).hasClass('slctTab')){
				$('ul.tab_list li').removeClass('slctTab');
				$(this).addClass('slctTab');

            }
            var link = $(this).children().attr('href');
			var data = link.split('?');
			
			$.ajaxSetup ({cache: false  });
            var ajax_load = "<div id='loadergif'><img src='/images/load.gif' alt='loading...' /></div>";
            $(".tab_contsIn").html(ajax_load).load(data[0] + " .tab_contsIn",data[1]);
            
			return false;  
	}
);

		$('ul.tab_list li').click(
		function() {
			if(!$(this).hasClass('slctTab')){
				$('ul.tab_list li').removeClass('slctTab');
				
				var index = $('ul.tab_list li').index(this);
				var tagDiv = $('.tab_contsIn');
				
				$('.tab_contsIn').hide('');
				
				$(this).addClass('slctTab');
				$(tagDiv[index]).show('');
			}
		}
	);
		

	 */
	 

	/*     product feature navigation   */
		 
	    $('ul.tab_list').children().removeClass('slctTab');
	    
	    var url = window.location.href;
		url = url.split("product.jsp");
	    defVal = true;
	    
	    //loop through all link and find what index link is at
	    $('ul.tab_list li a').each(function(index) {
	    	//just take whats after the page variable in url	
	        temp = $(this).attr('href').split("product.jsp");
	      	if(temp[1] == url[1]){
	      		//alert("temp" + temp[1])
	      		//alert("url" + url[1])
				$('ul.tab_list').children().eq(index).addClass('slctTab');
	           	defVal = false;
		 	}
	  	});
	
		//can't find the link so just default to fist tab
		//if(defVal){
		  // $('ul.tab_list').children().eq(0).addClass('slctTab');
	//	}
		
	/*    end product feature navigation   */


	$('.more-text').click(function(){
	 	$(this).parent().children('.content').css('height', 'auto');
	 	$(this).hide().next('.less-text').show();
	 	return false;
	});
	$('.less-text').click(function(){
	 	$(this).parent().children('.content').css('height', '350px');
	 	$(this).hide().prev('.more-text').show();
	 	return false;
	});
	$('.learn-more').click(function(){
		$(this).parent().children('.more-content').toggle();
		return false;
	});
	
});


function rotateImage(){
	
	var prev=curImgNum;

  	//if((curImgNum + 1) >= (totalImages + numOfFlash)){
  	if((curImgNum + 1) >= totalImages){
      	curImgNum = 0;
      	id="globalhome" + (curImgNum);

  	}else{
      	curImgNum=curImgNum+1;
    	id="globalhome" + (curImgNum);

  	}
//alert(totalImages)
/*	if(!($.browser.flash)){
		//alert('flash disable')
	    if($.browser.msie){
			//alert('ie') 
	        $('#visual_wrap').children().eq(prev).hide();
	    }
		else{
			//alert('not ie')
			$('#visual_wrap').children().eq(prev).fadeOut('fast');
		}
			
		$('#background_change').children().eq(prev).removeClass('active');  
		$('body').attr('id',id);
	
	    if($.browser.msie)
	        $('#visual_wrap').children().eq(curImgNum).show();
		else
			$('#visual_wrap').children().eq(curImgNum).fadeIn('slow');
			
		$('#background_change').children().eq(curImgNum).addClass('active');
	}
	else{*/
		//alert('flash enable')
    $('#visual_wrap').children().eq(prev).hide();
    $('#background_change').children().eq(prev).removeClass('active');  
	$('body').attr('id',id);
	$('#visual_wrap').children().eq(curImgNum).show();
	$('#background_change').children().eq(curImgNum).addClass('active');
	//}
	
//	chkImgLoad(curImgNum);
	 
}

function chkImgLoad(id){
			$('#visual_wrap').children().eq(id).load(function() {
			// Remove attributes in case img-element has set width and height
		
			$(this).removeAttr("width").css({ width: ""}); // Remove css dimensions as well
			
			var imgW = this.width;
			var winW = $(window).width();
			
			//alert(imgW);
			//alert(winW);
		
			if(imgW > winW){
				var a=(imgW - winW)/2;
				$(this).css('left', -a + 'px').css('border', '1px transparent');
			}
			else{
				var a=(winW-imgW)/2;
				$(this).css('left', a+'px').css('border', '1px transparent');
			}
			
		})
		.each(function(){
			if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6))
				$(this).trigger("load");
		});        
}
					  
					  
					  

/*var curPos=0;
function scrollFeature(direction){
	if(0 < curPos || curPos < -diffBetwnScrollDivs){
		clearInterval(featureScrollID);
		if(0 < curPos) curPos=0; else curPos = -diffBetwnScrollDivs;
	}
	else{
		curPos+=(4*direction);
		$('#add_contIn ul').css('left', curPos+'px');
	}
}*/



var curPos=0;
function scrollFeature(direction,width,total){
	var total_width=width*total;
	if(direction == -1){
		if((total_width-(width*4)) > -curPos){
			curPos=curPos-width;
			$('#add_contIn ul').animate({'left' : curPos+'px'});
		}
	}
	else{
		if(-curPos > 0){
			curPos=curPos+width;
			$('#add_contIn ul').animate({'left' : curPos+'px'});
		}
	}
	
}

