var interval, position = 0, filter = 100, interout, interin;

$(document).ready(function()
{
	$(".jq_tab").mouseover(video_change);
	interval = setInterval("start()", 8000);
	$(".jq_img").mouseover(set_img);
	$(".jq_card").mouseover(card_change);
	$(".jq_card").click(function(){return false;});
	$(".logout").click(slogout);
	$(".soso").click(soso);
});


function video_change()
{
	$(".jq_tab").each(function(i)
	{
		var tab = parseInt($(this).attr("tab"));
		$(".jq_video_"+tab).hide();
		$(this).html('<img src="images/t'+(tab+3)+'.png" width="49" height="31" />');
	});
	var tab = parseInt($(this).attr("tab"));
	$(".jq_video_"+tab).show();
	$(this).html('<img src="images/t'+tab+'.png" width="49" height="31" />');
	correctPNG();
	return false;
}

function set_img()
{
	clearInterval(interval);
	position = $(this).attr("position");
	var img = $(".img" + position).attr("img");
	var href = $(".img" + position).attr("href");
	$(".box8a").css("background-image", "url(" + img + ")");
	$(".jq_href").attr("href", href);
	$(".box8a").css("filter", "alpha(opacity=100)");
	interval = setInterval("start()", 8000);
	return false;
}

function start()
{
	if(++position == 4)
		position = 0;
	var img = $(".img" + position).attr("img");
	var href = $(".img" + position).attr("href");
	$(".box8a").fadeOut(1000, function()
	{
		$(".box8a").css("background-image", "url(" + img + ")");
		$(".jq_href").attr("href", href);
		$(".box8a").fadeIn();
	});
//	interout = setInterval("fadeout()", 100);
//	setTimeout('$(".box8a").css("background-image", "url(' + img + ')");', 800);
//	setTimeout('interin = setInterval("fadein()", 100)', 1100);
//	setTimeout('$(".box8a").fadeOut(1000);', 800);
}
function fadeout()
{
	filter -= 10;
	$(".box8a").css("filter", "alpha(opacity="+ filter +")");
	if(filter == 0)
		clearInterval(interout);
}

function fadein()
{
	filter += 10;
	$(".box8a").css("filter", "alpha(opacity="+ filter +")");
	if(filter == 100)
		clearInterval(interin);

}


function card_change()
{
	var tab = $(this).attr("card");
	var img = $(this).attr("img");
	$(".card_select").html("&nbsp;");
	$(".select_" + tab).html('<img src="images/p151.gif" width="8" height="14" />');
	$(".card_img").html('<img src="'+img+'" width="211" height="74" />');
}

function slogout()
{
	$.post("/login/logout",
	null,
	function (html)
	{
		$(".logout").html(html);
		window.location.reload();
	});

}
String.prototype.Trim = function()
{
		    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
		    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function()
{
		    return this.replace(/(\s*$)/g, "");
}
function soso()
{
	var val = $(".sosobox").val().Trim();
	if(val == "")
	{
		return false;
	}
	else
	{
		$(this).attr("href", "/search?word="+encodeURI(val)+"&type=1");
	}
}
