/*chan pin tu pian zui zhong ye yong dao de JS*/
//qie huan tu pian
var pre_url,next_url,ImageList,ImageListDom,ImageCurrent;

function chLR(obj) {
	//var img = document.getElementById("img1"); 
	var L_pic_n = base + "images/list_photo_left.jpg";
	var L_pic_h = base + "images/list_photo_left_hover.jpg";
	if(obj.src == L_pic_n) {
		obj.src = L_pic_h; 
	} else {
		obj.src = L_pic_n; 
	}
}
function chRL(obj) {
	//var img = document.getElementById("img1"); 
	var L_pic_n = base + "images/list_photo_right.jpg";
	var L_pic_h = base + "images/list_photo_right_hover.jpg";
	if(obj.src == L_pic_n) {
		obj.src = L_pic_h; 
	} else {
		obj.src = L_pic_n; 
	}
}
//jian pan fan ye
function init() {
	document.onkeydown = showKeyDown;
}
function showKeyDown(evt) {
	evt = (evt) ? evt : window.event;
	if ( evt.keyCode=='37' ) {//zuo jian tou
		if(pre_url){
			location.href=pre_url;
			location.reload();
		}
	}else if( evt.keyCode=='39') {//you jian tou
		if(next_url){
			location.href=next_url;
			location.reload();
		}
  	}
}							
//tian jia shou cang jia
function add_favorite(){
	var d = new Date();
	var url=document.URL;
	var title=document.title;
	if (document.all) window.external.AddFavorite(url,title);
	else if (window.sidebar) window.sidebar.addPanel(title,url,"");
}
//fu zhi lian jie dao jian tie ban
function copyToClipBoard(){
	var clipBoardContent="";
	clipBoardContent+=window.location.href;
	if (window.clipboardData){
		if(window.clipboardData.setData("Text",clipBoardContent)){
			alert("本页链接已经复制\n\n快去分享给好友吧！^^");   
		}
	}else{
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		clipBoardContent = clipBoardContent.replace(/\"/g,'\'');
		var divinfo = '<embed src="/_clipboard.swf" FlashVars="clipboard='+clipBoardContent+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
		alert("本页链接已经复制\n快去分享给好友吧！^^");
   }
}
/*ju bu da yin*/
function preview(oper)
{
	var prnhtml = '';
	if (oper < 10){
		bdhtml=window.document.body.innerHTML;//huo qu dang qian ye de htmldai ma
		sprnstr="<!--startprint"+oper+"-->";//she zhi da yin kai shi qu yu
		eprnstr="<!--endprint"+oper+"-->";//she zhi da yin jie shu qu yu
		prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //cong kai shi dai ma xiang hou qu HTML
		prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//cong jie shu dai ma xiang qian qu HTML
		window.document.body.innerHTML=prnhtml;
		window.print();
		window.document.body.innerHTML=bdhtml;
	} else {
		window.print();
	}
}
function hash(s){
	var tmp,ret='8',i=0,l=v=s.length,str='0123456789ABCDEF';
	while(i<l)v=(v<<5)|(v>>27)+s.charCodeAt(i++);
	if(v<0){ret='F';v=~v;}
	while(v){
		tmp=v%16;
		v=(v-tmp)/16;
		ret+=str.charAt(tmp);
	}
	return ret;
}
function initImagesList(){
	function Z(o,r){
		var w=80,h=45,x=eval(r.name),y=w/h;
		if(x>y)o.width=80;else o.height=h;
		o.src=r.src;
	}
	function A(o,a){
		o.href=a;
		o.onclick=function(){
			location.href=a;
			location.reload();
			return false;
		}
	}
	var a,b,c=0,g,x,p,z,t=$('#main_content'),u=$('#list_photo_img'),s=$('#list_photo_urls'),v=location.hash.substr(1),h=location.href.substr(0,location.href.length-location.hash.length);
	g=s.find('.img_list_a');
	x=g.find('img');
	ImageListDom=u;
//	for(a=0,b=x.length;a<b;a++)if(v==x[a].src){c=a;break}n=parseInt(n);if(isNaN(n))n=5;
	z=g[0].href;
	for(a=0,b=x.length;a<b;a++){
		p=hash(x[a].src);
		if(v==p){c=a;z=g[c].href;}
		A(g[a],h+'#'+p);
	}
	A(t.find('a')[0],g[c+1==b?0:c+1].href);
	t.find('a')[0].title=t.find('a')[0].title.replace('%s',x[c+1==b?0:c+1].alt);
	t.find('a')[1].href=t.find('img')[0].src=z;
	t.css('display','');
	t=$('#link_table');
	t.find('.f16').append('(<strong>'+(c+1)+'</strong>/'+b+')')
	if(c<3)a=0;else a=c-2;
	if(a+5<b)b=a+5;else if(b-5>0)a=b-5;else a=0;
	ImageCurrent=a;
	p=t.find('.pl5r5');
	Z(p[c?1:0],x[c?(c-1):0]);
	Z(p[c==x.length-1?3:2],x[c==x.length-1?0:(c+1)]);
	x=g;
	p=t.find('a');
	if(c)A(p[0],pre_url=x[c-1].href);
	if(c==x.length-1)A(p[2],x[0].href);else A(p[1],next_url=x[c+1].href);
	p=t.find('td:first');
	if(!c)p=p.next();
	p.remove();
	p=t.find('td:last');
	if(c==x.length-1)p=p.prev();
	p.remove();
	p=s.children(':first');
	if(c>2)A(p.find('a')[0],x[c-5>=0?c-5:0].href);
//	p.find('a').bind('click',function(){moveImageList(-5);return false});
	u.append(u.prev=p);
	ImageList=p=s.find('.img_list');
//	p=p.clone(true);
	p.find('a')[c].className='img_list_hover';
	while(a<b)u.append(p[a++]);
	p=s.children(':last');
	if(c<x.length-3)A(p.prev().find('a')[0],x[c+5<x.length?c+5:x.length-1].href);
//	p.prev().find('a').bind('click',function(){moveImageList(5);return false});
	u.append(u.next=p.prev());
	u.append(u.clear=p);
	t.css('display','');
	$('#list_photo').css('display','');
}
function moveImageList(n){
	var a,b,c=ImageCurrent,s=ImageList,u=ImageListDom;
	b=s.length-1;
	if(c==0&&n<0)return;
	c+=n;
	if(c>b++)return;
	if(c<0)c=0;
	ImageCurrent=c;
	b=c+5>b?b:c+5;
	u.children().remove();alert(u.prev)
	u.append(u.perv);
	while(c<b)u.append(s[c++]);
	u.append(u.next);
	u.append(u.clear);
}