// JavaScript Document


$(document).ready(function(){
	
	
	/* (function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

*/
	

	$('#billboard .spot').hide();
	$('#billboard #ad1').show();
	$('#billboard #ad1').addClass('current');
	$('#que a[href=#ad1]').addClass('selected');
	
	$("#que a").click(function(event){
		event.preventDefault();
		
		clearInterval(play);
		
		$('#billboard .nextup').removeClass('nextup');
		
		$($(this).attr('href')).addClass('nextup').show(0,function(){
			// after show
			$('#billboard .current').fadeOut(1000,function(){
				$('billboard .current').removeClass('current');
			 	$($(this).attr('href')).removeClass('nextup').addClass('current');
			});	
			
			
		});
		
		
		
		/* $('#billboard ' + $(this).attr('href')).addClass('nextup').show();
		$('#billboard .current').fadeOut(1500,function(){$('#billboard ' + $(this).attr('href')).removeClass('nextup').addClass('current');}).removeClass('current');
		*/
		
		
		$('#que .selected').removeClass('selected');
		$(this).addClass('selected');
		
		rotateSwitch();
	});
	
	/* 
	$('#up').click(function(event){
		event.preventDefault();
		$('#que').css('margin-top','0');
	});
	
	$('#down').click(function(event){
		event.preventDefault();
		$('#que').css('margin-top','-86px');
	});
	*/

	rotateSwitch = function(){
		play = setInterval(function(){
			
			
			
			var cur = $('#billboard .current').attr('id');
			cur = cur.replace('ad','');
			var n = parseInt(cur);
			n = (n % 4) + 1;
			
			$('#ad' + n).addClass('nextup').show(0,function(){
					// after show
					$('#billboard .current').fadeOut(1000,function(){
							// after fadeout
							$('#billboard .current').removeClass('current');
							$('#ad' + n).removeClass('nextup').addClass('current');
							
							
						});
				});
			
			
		/* 	var cur = $('#billboard .current').attr('id');
			cur = cur.replace('ad','');
			var n = parseInt(cur);
			n = (n % 4) + 1;
		
			$('#ad' + n).addClass('nextup').show();
			$('#billboard .current').fadeOut(1500,function(){$('#ad' + n).removeClass('nextup').addClass('current');}).removeClass('current');
			*/
			
		
			$('#que .selected').removeClass('selected');
			$('#que a[href=#ad' + n + ']').addClass('selected');
			/* if (n == 5){
				$('#que').css('margin-top','-86px');
			}
			if (n == 1){
				$('#que').css('margin-top','0');
			} */
			
			
		}, 7000);
	};
	
	rotateSwitch();
	
	/* $('.current *').hover(function(){
		clearInterval(play);
	},function(){
		rotateSwitch();
	})
	*/
	
});

