//home center images
var $d = document;

function $i(s){return $d.getElementById(s);}

var _jsc = {};

_jsc.client = (function(){	
	var t = {};
	var b = navigator.userAgent.toLowerCase();
	t.isOpera = (b.indexOf('opera') > -1);
	t.isIE = (!t.isOpera && b.indexOf('msie') > -1);
	t.isFF = (!t.isOpera &&!t.isIE&&b.indexOf('firefox') > -1);
	return t;
})();

_jsc.util = (function(){
	var t = {};
	t.addEvent = function(o,c,h){
		if(_jsc.client.isIE){
			o.attachEvent('on'+c,h);
		}else{
			o.addEventListener(c,h,false);
		}
		return true;
	};
	return t;
})();

_jsc.evt = (function(){
	var t = {};
	t.gTar = function(oe){
		if(_jsc.client.isIE){
			return oe.srcElement;
		}else{
			return oe.target;
		}
	};
	return t;
})();

function tabswitch(c, config){
	this.config = config ? config : {start_delay:3000, delay:1500};
	this.container = $i(c);
	this.pause = false;
	this.nexttb = 1;
	this.tabs = this.container.getElementsByTagName('dt');
	var _this = this;
	if(this.tabs.length<1){
		this.tabs = this.container.getElementsByTagName('li');
	}
	for(var i = 0; i < this.tabs.length; i++){
		var _ec = this.tabs[i].getElementsByTagName('span');
		if(_ec.length<1){
			_ec = this.tabs[i].getElementsByTagName('a');
		}
		if(_ec.length<1){
			_ec = this.tabs[i];
		}else{
			_ec = _ec[0];
		}
		_ec.onmouseover = function(e) {
			_this.pause = true;
			var ev = !e ? window.event : e;
			_this.start(ev, false, null);
		};
		
		_ec.onmouseout = function() {
			_this.pause = false;
		};
		
		try{
			$i(this.tabs[i].id + '_body_1').onmouseover = function(){
				_this.pause = true;
			};
			
			$i(this.tabs[i].id + '_body_1').onmouseout = function(){
				_this.pause = false;
			};
		}catch(e){}
	}

	if ($i(c + '_sts')) {
		var _sts = $i(c + '_sts');
		var _step = _sts.getElementsByTagName('li');
		if(_step.length<1)_step = _sts.getElementsByTagName('div');
		_step[0].onclick = function() {
			if (_this.tabs[_this.tabs.length-1].className.indexOf('current') > -1) {
				_this.nexttb = _this.tabs.length + 1;
			};
			_this.nexttb = _this.nexttb - 2 < 1 ? _this.tabs.length : _this.nexttb - 2;
			
			_this.start(null, null, _this.nexttb);
		};
		
		_step[1].onclick = function() {
			_this.nexttb = _this.nexttb < 1 ? 1 : _this.nexttb;
			_this.start(null, null, _this.nexttb);
		};
	};
	
	this.start = function(e, r, n){
		if(_this.pause && !e)return;
		if(r){
			curr_tab = $i(_this.container.id + '_' + rand(4));
		}else{
			if(n){
				
				curr_tab = $i(_this.container.id + '_' + _this.nexttb);
			}else{
				curr_tab = _jsc.evt.gTar(e);
				if(curr_tab.id=="")curr_tab = curr_tab.parentNode;
			}
		}
		
		var tb = curr_tab.id.split("_");
		for(var i = 0; i < _this.tabs.length; i++){
			if(_this.tabs[i]==curr_tab){
				_this.tabs[i].className="hot Selected current";
				try{
					
					$i(_this.tabs[i].id + '_body_1').style.display = "block";
				}catch(e){}
			}else{
				_this.tabs[i].className="";
				try{
					$i(_this.tabs[i].id + '_body_1').style.display = "none";
				}catch(e){}
			}
		}
		_this.nexttb = parseInt(tb[tb.length-1]) >= _this.tabs.length ? 1 : parseInt(tb[tb.length-1]) + 1;
	};
}

function init_imh () {
	var _lis = document.getElementsByTagName('li');
	for (var i=0;i<_lis.length;i++) {
		if (_lis[i].getAttribute('jpe') == 'linkto:a') {
			_lis[i].onclick = function(e) {
				var ev = !e ? window.event : e;
				var _target = _jsc.evt.gTar(ev);
				while (_target.tagName.toLowerCase() != 'li') {
					_target = _target.parentNode;
				}
				location.href = _target.getElementsByTagName('a')[0].getAttribute('href');
				return false;
			};
		}
	}
}

var banners, new_trans, super_rec, crazy_buy, star,bargain_scroll,buy_ok_div;
_jsc.util.addEvent(window, 'load', function() {
		if ($i('banners')) {	
			banners = new tabswitch('banners', {});
			setInterval("banners.start(null, null, 1);", 5000);
		}
		
});

//recent reviews
var Swidth=screen.width;

$(function() {
	$("#recentReviewContent").jCarouselLite({
	        vertical: true,
	        hoverPause: true,
			scroll:1,      
	        visible: 3,
	        start: 1,
	        auto: 1500,
	        speed:2500,
			circular: true
	    });

	});

//assistant
function switchShow(hideDiv,showDiv,typeName,typeValue)
{
	document.getElementById(hideDiv).style.display="none";
	document.getElementById(showDiv).style.display="inline";
	document.getElementById(typeName).value=typeValue;
	
	
	if(typeName =="brandType" && typeValue =='select')
	{
		document.getElementById('defineBrand').value="";
	}
	
	if(typeName =="priceType" && typeValue =='select')
	{
		document.getElementById('minPrice').value="";
		document.getElementById('maxPrice').value="";
	}
}

function resetField(brandList,priceList,brandInput,minPriceInput,maxPriceInput)
{
	document.getElementById(brandList).innerHTML= '<select id="brand" name="brand" ><option value="">所有品牌</option></select>';
	document.getElementById(priceList).innerHTML='<select id="price" name="price"><option value="">价格区间</option></select>';
	
	document.getElementById(brandInput).value="";
	document.getElementById(minPriceInput).value="";
	document.getElementById(maxPriceInput).value="";
	
	if(document.getElementById('assistantBrandContent').style.display=="none")
	{
		switchShow('defineProductBrand','assistantBrandContent');
	}
	
	if(document.getElementById('productPriceContent').style.display=="none")
	{
		switchShow('defineProductPrice','productPriceContent');
	}
}

function getContent(categoryStr,brandSelect,priceSelect)
{
	var categoryLevel = "";
	var categoryID  = "";
	if(categoryStr.indexOf("_") != -1)
	{
		var strArray = categoryStr.split("_");
		categoryLevel = strArray[0];
		categoryID  = strArray[1];
	}
	
	var queryString = "level="+categoryLevel+"&c_id="+categoryID;
	
	jQuery.ajax({
		url: '../home_include/assistant_getContent.php?'+queryString,
		type: 'GET',
		datatype: 'text',
		success: function(string){
			var stringArray = string.split("###RAWR###");
			$('#'+brandSelect).empty();
			$('#'+brandSelect).append(stringArray[0]);
			$('#'+priceSelect).empty();
			$('#'+priceSelect).append(stringArray[1]);
		}
	});
}

//right pictures
/*
var F_delay=5;
var F_timer=null;
var F_img=null;
var F_temp_count=1;
var F_photos=[
	["http://www.kehubaogao.com/pictures/pro/home/car.jpg","","http://www.kehubaogao.com/pro/category/index.php?c_id=16",
"http://www.kehubaogao.com/pictures/pro/home/car.jpg"],
	["http://www.kehubaogao.com/pictures/pro/home/phone.jpg","","http://www.kehubaogao.com/pro/category/index.php?c_id=40",
"http://www.kehubaogao.com/pictures/pro/home/phone.jpg"],
	["http://www.kehubaogao.com/pictures/pro/home/cosmetics.jpg","","http://www.kehubaogao.com/pro/category/index.php?c_id=215",
"http://www.kehubaogao.com/pictures/pro/home/cosmetics.jpg"]
];
var preload=new Array();
for (var i=0;i<F_photos.length;i++){
	preload[i]=new Image();
	if (Swidth>=1280){preload[i].src=F_photos[i][3];}
	else{preload[i].src=F_photos[i][0];}
	preload[i].alt=F_photos[i][1];
}
function strartSlideshow(){
	var imgbarHTML="";
	imgbarHTML+="<ul id='button_image'>";
	for (var i=0;i<F_photos.length;i++){imgbarHTML+="<li id='i"+ i +"'><a href='"+ F_photos[i][2] +"' target='_blank'>"+ (i+1) +"</a></li>"}
	imgbarHTML+="</ul>";
	$("#Focus_Img").get(0).innerHTML+=imgbarHTML;
	$("#Curr_image").get(0).innerHTML="<a href='"+ F_photos[0][2] +"' target='_blank'><img src='"+ preload[0].src +"' alt='"+ preload[0].alt +"' class='photo' style='filter:revealtrans(duration=2,transition=23)' /></a>";
	
	$("#button_image li").get(0).className="curr";
	F_img=$("#Curr_image img").get(0);
	F_timer=setTimeout("cueNextSlide(1)",F_delay*1000);
	for (var i=0;i<F_photos.length;i++){$("#button_image li").get(i).onmouseover=function(){clearTimeout(F_timer);cueNextSlide(this.id.substr(1,1));clearTimeout(F_timer);};$("#button_image li").get(i).onmouseout=function(){F_timer=setTimeout("cueNextSlide("+F_temp_count+")",F_delay*1000);};};
	F_img.onmouseover=function(){clearTimeout(F_timer)};
	F_img.onmouseout=function(){F_timer=setTimeout("cueNextSlide("+F_temp_count+")",F_delay*1000);};
}
function cueNextSlide(F_count){
	clearTimeout(F_timer);
	if ($.browser.msie&&$.browser.version<="7.0"){F_img.filters.revealtrans.transition=23;F_img.filters.revealtrans.Apply();}
	F_img.src=preload[F_count].src;
	if ($.browser.msie&&$.browser.version<="7.0"){F_img.filters.revealtrans.Play();}
	F_img.alt=preload[F_count].alt;
	$("#Curr_image a").get(0).href=F_photos[F_count][2];
	for (var i=0;i<F_photos.length;i++){$("#button_image li").get(i).className="";}
	$("#button_image li").get(F_count).className="curr";
	if (++F_count==F_photos.length){F_count=0;}
	F_timer=setTimeout("cueNextSlide("+F_count+")",F_delay*1000);
	F_temp_count=F_count;
}

// recent products
/*
$(function() {
    $(".recentProductContent").jCarouselLite({
        btnNext: "#arrowR",
        btnPrev: "#arrowL",
		scroll: 4
    });
});

$(document).ready(function(){
	var curRecProStart = 1;
	var curRecProEnd = 4;
	var curSelectedButton = 1;
	$("#arrowR").bind("click", function(e){		
		if(parseInt(curRecProEnd) < 20 )
		{	curSelectedButton +=1;
			selectButton(curSelectedButton);

			curRecProStart +=4;
			curRecProEnd +=4;
			$('#curRecProStart').html(curRecProStart);
			$('#curRecProEnd').html(curRecProEnd);
		}
	});

	$("#arrowL").bind("click", function(e){
		if(curRecProStart > 1)
		{	
			curSelectedButton -=1;
			selectButton(curSelectedButton);
			
			curRecProStart -=4;
			curRecProEnd -=4;
			$('#curRecProStart').html(curRecProStart);
			$('#curRecProEnd').html(curRecProEnd);
		}
	});

	function selectButton(number)
	{
		for(i = 1;i<=5;i++)
		{
			var button  = document.getElementById("curRecProBtn_"+i);
			if($(button).hasClass("selected"))
			{
				$(button).removeClass("selected");
				break;
			}		
		}
		$(document.getElementById("curRecProBtn_"+number)).addClass("selected");
	}
});
*/

$(document).ready(function(){
	var catLen = $('#newest-product .hd ul li').length;

	$('#newest-product .hd li').bind('click',function(){
		var liNum = $('li','#newest-product .hd ul').index($(this));
		if(!$(this).hasClass("on"))
		{
			for(i=0;i<catLen;i++)
			{
				var liObj = $("#newest-product .hd ul li").eq(i);
			
				var contentObj = $("#newest-product .bd").eq(i);
				
				if(liObj.hasClass("on"))
				{
					liObj.removeClass("on");	
				}
				
				if(contentObj.css("display") =="block")
				{
					contentObj.css("display","none");
				}
			}
			
			$('#newest-cate-content'+liNum).css("display","block");			
			$(this).addClass("on");				
		}
				
	})
});

