var playdiv_id = "playdiv";	//----- 设置滚动部分的id
var IntagName = "li";	//----- 设置滚动图片框的标签
var btnleft_id = "btnleft" , btnright_id = "btnright";	//----- 设置左右两侧的箭头的id
var picl_1 = "images/cyl.gif" , picl_2 = "images/cyl1.gif";	//----- 设置左侧的箭头的地址
var picr_1 = "images/cyr.gif" , picr_2 = "images/cyr1.gif";	//----- 设置右侧的箭头的地址
var slowspeed = 500 , fastspeed = 100;	//----- 设置滚动速度，越大越慢
var innerspace = 30;	//----- 设置图片间距

var playdiv_id1 = "btmpro";	//----- 设置滚动部分的id
var IntagName1 = "li";	//----- 设置滚动图片框的标签
var btnleft_id1 = "btmleft" , btnright_id1 = "btmright";	//----- 设置左右两侧的箭头的id
var picl_11 = "images/logoleft.jpg" , picl_21 = "images/logoleft.jpg";	//----- 设置左侧的箭头的地址
var picr_11 = "images/logoright.jpg" , picr_21 = "images/logoright.jpg";	//----- 设置右侧的箭头的地址
var slowspeed1 = 500 , fastspeed1 = 100;	//----- 设置滚动速度，越大越慢
var innerspace1 = 35;	//----- 设置图片间距

var playdiv_id2 = "proneipics";	//----- 设置滚动部分的id
var IntagName2 = "li";	//----- 设置滚动图片框的标签
var btnleft_id2 = "proleft" , btnright_id2 = "proright";	//----- 设置左右两侧的箭头的id
var picl_12 = "images/hd_mj_001.png" , picl_22 = "images/hd_mj_001.png";	//----- 设置左侧的箭头的地址
var picr_12 = "images/hd_mj_002.png" , picr_22 = "images/hd_mj_002.png";	//----- 设置右侧的箭头的地址
var slowspeed2 = 500 , fastspeed2 = 100;	//----- 设置滚动速度，越大越慢
var innerspace2 = 50;	//----- 设置图片间距


var indexif = false , proinif = false;
$(document).ready( function() {
	if ( indexif ) {
		scrollpro(playdiv_id,IntagName,btnleft_id,btnright_id,picl_1,picl_2,picr_1,picr_2,slowspeed,fastspeed,innerspace);
		//procard();
	}
	scrollpro(playdiv_id1,IntagName1,btnleft_id1,btnright_id1,picl_11,picl_21,picr_11,picr_21,slowspeed1,fastspeed1,innerspace1);
	if ( proinif ) {
		scrollpro(playdiv_id2,IntagName2,btnleft_id2,btnright_id2,picl_12,picl_22,picr_12,picr_22,slowspeed2,fastspeed2,innerspace2);
		
		var hodethis = $("#proneipics li:first img:first");
		$("#proneipics li img").fadeTo("fast",0.3).click( function() {
			hodethis.fadeTo("fast",0.3);
			hodethis = $(this);
			load_img($(this).attr("src"),"images/load_pic.gif",$("#img"));
		} ).mouseover( function() {
			if ( hodethis.attr("rel") != $(this).attr("rel") ) {
				$(this).fadeTo("fast",1);
			}
		} ).mouseout( function() {
			if ( hodethis.attr("rel") != $(this).attr("rel") ) {
				$(this).fadeTo("fast",0.3);
			}
		} );
		$("#proneipics li:first img:first").fadeTo("fast",1);
	}
} );

function scrollpro(p_id,tagName,left_id,right_id,picl_1_src,picl_2_src,picr_1_src,picr_2_src,slowspeeds,fastspeeds,innerspaces) {
	var playdiv = $("#" + p_id);
	var btnleft = $("#" + left_id) , btnright = $("#" + right_id);
	var maxlength = 0 , marqing , type = "left";
	for ( var i = 0 ; i < playdiv.find(tagName).length ; i++ ) {
		maxlength += playdiv.find(tagName)[i].offsetWidth + innerspaces;
	}
	playdiv.append(playdiv.html()).css( { width : (maxlength * 2) + "px" } );
	
	/*---------- 向左滚动 ----------*/
	btnleft.mouseover( function() {
		$(this).attr("src",picl_2_src);
		if ( type != "left" && type != "bigleft" ) {
			type = "left";
			clearInterval(marqing);
			putleft();
			marqing = setInterval(putleft,slowspeeds*6);
		}
	} ).mousedown( function() {
		if ( type != "bigleft" ) {
			type = "bigleft";
			clearInterval(marqing);
			putleft1();
			marqing = setInterval(putleft1,fastspeeds+10);
		}
	} ).mouseup( function() {
		if ( type == "bigleft" ) {
			type = "left";
			clearInterval(marqing);
			putleft();
			marqing = setInterval(putleft,slowspeeds*6);
		}
	} ).mouseout( function() {
		$(this).attr("src",picl_1_src);
	} );

	/*---------- 向右滚动 ----------*/
	btnright.mouseover( function() {
		$(this).attr("src",picr_2_src);
		if ( type != "right" && type != "bigright" ) {
			type = "right";
			clearInterval(marqing);
			putright();
			marqing = setInterval(putright,slowspeeds*6);
		}
	} ).mousedown( function() {
		if ( type != "bigright" ) {
			type = "bigright";
			clearInterval(marqing);
			putright1();
			marqing = setInterval(putright1,fastspeeds+10);
		}
	} ).mouseup( function() {
		if ( type == "bigright" ) {
			type = "right";
			clearInterval(marqing);
			putright();
			marqing = setInterval(putright,slowspeeds*6);
		}
	} ).mouseout( function() {
		$(this).attr("src",picr_1_src);
	} );
	
	/*---------- 控制滚动 ----------*/
	playdiv.mouseover( function() {
		clearInterval(marqing);
		$("#" + p_id + " " + tagName + ":first").stop();
	} ).mouseout( function() {
		clearInterval(marqing);
		switch (type) {
			case "left":
				putleft();
				marqing = setInterval(putleft,slowspeeds*6);
				break;
			case "bigleft":
				putleft();
				marqing = setInterval(putleft,slowspeeds*6);
				break;
			case "right":
				putright();
				marqing = setInterval(putright,slowspeeds*6);
				break;
			case "bigright":
				putleft();
				marqing = setInterval(putright,slowspeeds*6);
				break;
		}
	} );
	
	
	
	function putleft() {
		$("#" + p_id + " " + tagName + ":first").stop().animate( { "marginLeft" : "-" + ( playdiv.find(tagName)[0].offsetWidth + innerspaces ) + "px" } , { queue: false, duration: slowspeeds, complete:function() {
			$("#" + p_id + " " + tagName + ":first").appendTo( playdiv );
			$("#" + p_id + " " + tagName + ":last").css( "marginLeft" , "0" );
		} } );
	}
	
	function putright() {
		$("#" + p_id + " " + tagName + ":first").stop().animate( { "marginLeft" : "0" } , { queue: false, duration: slowspeeds, complete:function() {
			$("#" + p_id + " " + tagName + ":last").css( "marginLeft" , "-" + ( playdiv.find(tagName)[playdiv.find(tagName).length-1].offsetWidth + innerspaces ) + "px" );
			$("#" + p_id + " " + tagName + ":last").prependTo( playdiv );
		} } );
	}
	
	
	
	function putleft1() {
		$("#" + p_id + " " + tagName + ":first").stop().animate( { "marginLeft" : "-" + ( playdiv.find(tagName)[0].offsetWidth + innerspaces ) + "px" } , { queue: false, duration: fastspeeds, complete:function() {
			$("#" + p_id + " " + tagName + ":first").css( "marginLeft" , "0" );
			$("#" + p_id + " " + tagName + ":first").appendTo( playdiv );
		} } );
	}
	
	function putright1() {
		$("#" + p_id + " " + tagName + ":first").stop().animate( { "marginLeft" : "0" } , { queue: false, duration: fastspeeds, complete:function() {
			$("#" + p_id + " " + tagName + ":last").css( "marginLeft" , "-" + ( playdiv.find(tagName)[playdiv.find(tagName).length-1].offsetWidth + innerspaces ) + "px" );
			$("#" + p_id + " " + tagName + ":last").prependTo( playdiv );
		} } );
	}
	
	clearInterval(marqing);
	putleft();
	marqing = setInterval(putleft,slowspeeds*6);
}

function load_img(url,s_url,obj) {
	var img = new Image();
	img.src = url;
	obj.attr("src",s_url);
	var width = 0 , height = 0;
	if ( img.complete ) {
		if ( img.width / img.height > 520 / 389 ) {
			if ( img.width > 520 ) {
				obj.attr("width",520);
			}
		}
		else {
			if ( img.height > 389 ) {
				obj.attr("height",389);
			}
		}
		obj.hide().attr("src",img.src);
		obj.fadeIn("fast");
		return;
	}
	img.onload = function () {
		obj.hide().attr("src",img.src);
		obj.fadeIn("fast");
		if ( img.width / img.height > 520 / 389 ) {
			if ( img.width > 520 ) {
				obj.attr("width",520);
			}
		}
		else {
			if ( img.height > 389 ) {
				obj.attr("height",389);
			}
		}
	};
}
