var timer = null;
var offset = 5000;
var index = -1;
var onPage = 0;
var timerc = null;
var yeskss = true;
var is_stop = false;

//´óÍ¼½»ÌæÂÖ»»
function slideImage(i){
	//alert(i);
	if( yeskss ){
		product_show_c_gopage(i);
	}
	//alert(parseInt(23*Math.random()));
	$('#pro_main_img')[0].filters[0].Apply();
	$('#pro_main_img')[0].filters[0].transition =parseInt(23*Math.random());
	$('#pro_main_img')[0].filters[0].Play(2);
    $('#pro_main_img').attr("src",$("#thumb_"+target[i]).attr("tsrc"));
    $('#pro_main_img_link').attr("href",$("#thumb_"+target[i]).attr("thref"));
	$('.pro_smaill_image2').attr("class","pro_smaill_image1");
	$('#thumb_'+target[i]).attr("class","pro_smaill_image2");
}
//bind thumb a
function hookThumb(i){
	index = i;
    if (index >= target.length || index<0){
        index = 0;
    }
            if (timer) {
                clearTimeout(timer);
            }
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();
}
//bind next/prev img
function hookBtn(){
            if (timer){
                clearTimeout(timer);
            }
            var id = this.id;
            if (id == 'play_prev') {
                index--;
                if (index < 0) index = 6;
            }else{
                index++;
                if (index > 6) index = 0;
            }
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
}
function proNextImg(){
    index++;
    if (index >= target.length){
        index = 0;
    }
	if (timer){
		clearTimeout(timer);
	}
    slideImage(index);
	if( !is_stop ) timer = window.setTimeout(auto, offset);
}
function proPrevImg(){
    index--;
    if (index < 0){
        index = target.length-1;
    }
	if (timer){
		clearTimeout(timer);
	}
    slideImage(index);
	if( !is_stop ) timer = window.setTimeout(auto, offset);
}
//get index
function getIndex(v){
    for(var i=0; i < target.length; i++){
        if (target[i] == v) return i;
    }
}
function rechange(loop){
    var id = 'thumb_'+ target[loop];
    $('#thumbs li a.current').removeClass('current');
    $('#'+ id).addClass('current');
}
function auto(){
    index++;
    if (index >= target.length){
        index = 0;
    }
	//alert(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
function main_img_stop(){
	is_stop = true;
	$("#stop_bnt").attr("src","images/product_show_play.gif");
	if( timer ){
		clearTimeout(timer);
	}
}

function main_img_play(){
	is_stop = false;
	$("#stop_bnt").attr("src","images/product_show_step.gif");
	auto();
}


$(function(){    
    auto();
	$("#stop_bnt").click( function(){
		if( is_stop ){
			main_img_play();
		}else{
			main_img_stop();
		}
	});
	
	var page = Math.ceil( target.length/8 );

	$("#pageStr").html("1&nbsp;/&nbsp;"+page);
});


function product_show_c_next(){
	var tabTop = parseInt( $("#product_show_c").css("top") );
	var tabHeight = $("#product_show_c").height();
	var page = Math.ceil( (tabHeight-20) / 324 );
	//alert(tabTop);
	if( tabTop > -(page-1)*324 ){
		onPage ++;
		$("#product_show_c").css("top", tabTop-324+"px");
	}else{
		onPage = 0;
		$("#product_show_c").css("top", "0px" );
	}
	$("#pageStr").html((onPage+1)+"&nbsp;/&nbsp;"+page);
	ic();
}

function product_show_c_prev(){
	var tabTop = parseInt( $("#product_show_c").css("top") );
	var tabHeight = $("#product_show_c").height();
	var page = Math.ceil( (tabHeight-20) / 324 );
	
	if( tabTop <= -324 ){
		onPage --;
		$("#product_show_c").css("top", tabTop+324+"px" );
	}else{
		onPage = page-1;
		$("#product_show_c").css("top", (-(page-1)*324)+"px" );
	}
	$("#pageStr").html((onPage+1)+"&nbsp;/&nbsp;"+page);
	ic();
}

function product_show_c_gopage(i){
	
	var onPagei = Math.floor(i/8);
	if( onPage != onPagei ){
		onPage = onPagei;
		var tabTop = parseInt( $("#product_show_c").css("top") );
		var tabHeight = $("#product_show_c").height();
		var page = Math.ceil( (tabHeight-20) / 324 );
		//alert(onPage);
		if( onPage >= page ){
			onPage = page-1;
		}
		if( onPage < 0 ){
			onPage = 0;
		}
		//alert(tabTop);
		if( tabTop >= -(page-1)*324 ){
			$("#product_show_c").css("top",-onPage*324+"px");
		}else{
			$("#product_show_c").css("top","0px");
		}
		$("#pageStr").html((onPage+1)+"&nbsp;/&nbsp;"+page);
	}
}

function ic(){
	yeskss = false;
	setTimeout("yeskss=true", 4000 );
}










