// JavaScript Document
function imageChangeInit()
{
	 $('#util li.hasBorder').filter(':first').mouseover(function(){
																$(this).children('a').children('img').attr('src','images/homeOver.gif');});
	 $('#util li.hasBorder').filter(':first').mouseout(function(){
																$(this).children('a').children('img').attr('src','images/home.gif');});
	 $('#util li.hasBorder').filter(':last').mouseover(function(){
																$(this).children('a').children('img').attr('src','images/wishOver.gif');});
	 $('#util li.hasBorder').filter(':last').mouseout(function(){
																$(this).children('a').children('img').attr('src','images/wish.gif');});
	 
	 $('div.subAdPart div').hover(function(event){
										 if(!$(this).parents('div').filter(':first').children('div.imgBox').children('a').children('img.blackImage').is(':hidden'))
										 	{
											   $(this).parents('div').filter(':first').children('div.imgBox').children('a').children('img.blackImage').hide();
										       $(this).parents('div').filter(':first').children('div.imgBox').children('a').children('img.colorImage').fadeIn('slow');
											}
										},
								  function(event){
									  if(!$(this).parents('div').filter(':first').children('div.imgBox').children('a').children('img.colorImage').is(':hidden'))
									  {
										 $(this).parents('div').filter(':first').children('div.imgBox').children('a').children('img.colorImage').hide();
										 $(this).parents('div').filter(':first').children('div.imgBox').children('a').children('img.blackImage').fadeIn('slow');
									  }
								});
}

function adNavInit()
{
	setPosition();
	$(window).bind('resize',setPosition);
	$('#advertise ul li div').each(function (){$(this).bind('click',changeAdImageByClick)});
	setInterval(adBeggin,3000);
	
}
function setPosition()
{
	/*$('#advertise ul').css('top',$(this).parents('div').children('div:first').position().top + $(this).parents('div').children('div:first').height() - $(this).height() - 15).css('left',$(this).parents('div').children('div:first').position().left + $(this).parents('div').children('div:first').width() - $(this).width() - 15);*/
	$('#advertise ul').css('left',document.body.clientWidth/2 + 130);
}
function adBeggin()
{
	var currentNum = $('#advertise ul li div.current').html();
	if(currentNum == 1)
	{
		changeAdImageAuto(2);
	}
	else if(currentNum == 2)
	{
		changeAdImageAuto(3);
	}
	else if(currentNum == 3)
	{
		changeAdImageAuto(4);
	}
	else if(currentNum == 4)
	{
		changeAdImageAuto(5);
	}
	else if(currentNum == 5)
		changeAdImageAuto(6);
	else
	{
		changeAdImageAuto(1);
	}
	
}
function changeAdImageAuto(nextNum)
{
	$('#advertise ul li div.current').removeClass('current');
	if(nextNum == 1)
	{
		$('#1').addClass('current');
		$('#sixth').hide();
		$('#firstAd').fadeIn('slow');
	}
	else if(nextNum == 2 )
	{
		$("#2").addClass('current');
		$('#firstAd').hide();
		$('#secondAd').fadeIn('slow');
	}
	else if(nextNum == 3 )
	{
		$("#3").addClass('current');
		$('#secondAd').hide();
		$('#thirdAd').fadeIn('slow');
	}
	else if(nextNum == 4 )
	{
		$("#4").addClass('current');
		$('#thirdAd').hide();
		$('#forthAd').fadeIn('slow');
	}
	else if(nextNum == 5 )
	{
		$("#5").addClass('current');
		$('#forthAd').hide();
		$('#fifthAd').fadeIn('slow');
	}
	else
	{
		$("#6").addClass('current');
		$('#fifthAd').hide();
		$('#sixthAd').fadeIn('slow');
	}
}
function changeAdImageByClick(event)
{
	var num = $('#advertise ul li div.current').html();
	switch(num)
	{
		case '1':
			$('#firstAd').hide();
			break;
		case '2':
			$('#secondAd').hide();
			break;
		case '3':
			$('#thirdAd').hide();
			break;
		case '4':
			$('#forthAd').hide();
			break;
		case '5':
			$('#fifthAd').hide();
			break;
		case '6':
			$('#sixthAd').hide();
			break;
	}
	$('#advertise ul li div.current').removeClass('current');
	if($(this).html() == 1)
	{
		$('#1').addClass('current');
		//$('#sixth').hide();
		$('#firstAd').fadeIn('slow');
	}
	else if($(this).html() == 2 )
	{
		$("#2").addClass('current');
		//$('#firstAd').hide();
		$('#secondAd').fadeIn('slow');
	}
	else if($(this).html() == 3 )
	{
		$("#3").addClass('current');
		//$('#secondAd').hide();
		$('#thirdAd').fadeIn('slow');
	}
	else if($(this).html() == 4 )
	{
		$("#4").addClass('current');
		//$('#thirdAd').hide();
		$('#forthAd').fadeIn('slow');
	}
	else if($(this).html() == 5 )
	{
		$("#5").addClass('current');
		//$('#forthAd').hide();
		$('#fifthAd').fadeIn('slow');
	}
	else
	{
		$("#6").addClass('current');
		//$('#fifthAd').hide();
		$('#sixthAd').fadeIn('slow');
	}
}
