var t = n = count = 0;
$(function(){
	initPic();
	
	count = $("#play_list a").size();
	$("#play_list a:not(:first-child)").hide();
	$("#play_text li:first-child").addClass('on');
	$("#play_text li").each(function(i,n){
	    $(this).mouseover(function(){
	        n = i;
		    if (n >= count) return;
		    $("#play_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
		    $(this).addClass('on').siblings().removeClass('on');
	    });
	});
	t = setInterval("showAuto()", 3000);
	$("#play").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 3000);});
})

function showAuto(){
	n = n >= (count - 1) ? 0 : n + 1;
	$("#play_text li").eq(n).trigger('mouseover');
}

function initPic(){
    var imgs = $('#pics').text();
    var links = $('#piclinks').text();
    var imghtml = '';
    var indexhtml = '';
    if(imgs != ''){
        var imgArry = imgs.split('|');
        var linkArry = links.split('|');
        $.each(imgArry,function(i,n){
            if($.trim(linkArry[i]) == ''){
                imghtml += '<a><img src="' + n + '" alt="" /></a>';
            }else{
                imghtml += '<a href="' + linkArry[i] + '" target="_blank"><img src="' + n + '" alt="" /></a>';
            }
            indexhtml += '<li>' + (i+1) + '</li>';
        });
    };
    $('#play_list').html(imghtml);
    $('#play_text ul').html(indexhtml);
};
