// JavaScript Document
function resizeImg(){
	var wheight = $(window).height();
	$('#playbg').height(wheight);
	w = $(window).width();
	h = $(window).height();
	var image_scale = 1680/1050;
	var window_scale = w/h;
	if (image_scale>window_scale){
		var wid = Math.floor(h*image_scale);
		$('#radomimg img').width(wid);
		$('#radomimg img').height(h);
	}else{
		var hei = Math.floor(w/image_scale);
		$('#radomimg img').width(w);
		$('#radomimg img').height(hei);
	}
}
function fadeFocusBg(id, time){
	var box	  = $('#'+id);
	var info  = box.find('div.infobox');
	var text  = box.find('div.numbtn');
	var divs  = box.find('div.imglist div');
	var imgs  = divs.find('img');
	var spans = text.find('span');
	var next  = box.find('.next');
	var lastIndex = divs.last().index();
	var imgCount  = imgs.length;
	setHover();
	addCurrent(0);
	spans.click(function(){
		var n = $(this).index();
		//addCurrent(n);
	})
	box.find('.pre').click(function(){
		var thisIndex = text.find('.hover').index();
		if(thisIndex != 0){
			n = thisIndex-1;
		}else{
			n = lastIndex;
		}
		addCurrent(n);
	})
	next.click(function(){
		var thisIndex = text.find('.hover').index();
		if(thisIndex != lastIndex){
			n = thisIndex+1;
		}else{
			n = 0;
		}
		addCurrent(n);
	})
	function addCurrent(n){
		text.find('.hover').removeAttr('class');
		divs.filter(":visible").hide().end().eq(n).show();
		spans.eq(n).addClass('hover');
		info.html(divs.eq(n).find('img').attr('alt'));
	}
	function showAuto(){
		next.trigger('click');
	}
	function setHover(){
		t = setInterval(showAuto, time);
		box.hover(
			//function(){clearInterval(t)},
			//function(){t = setInterval(showAuto, time)}
		)
	}
}
$(function(){
	fadeFocusBg('playbg',8000);
	resizeImg()
})
