var intervalt = 3500;
var banner_click = false;
banner_click_allow = false;

var active_slide = 1;
var animate_slide = false;
var clicked = false;

$(document).ready(function() {
	var t=setTimeout("fadeThrough(1, 2)",intervalt);
	
	$(".right_content_box").hover(function () {
		if ($('#right_content_box_more'+$(this).attr('id').substring($(this).attr('id').length-1)).length > 0) 
		{
			$('#right_content_box_more'+$(this).attr('id').substring($(this).attr('id').length-1)).slideDown('fast', function() {});
		}
	}, function() { 
		if ($('#right_content_box_more'+$(this).attr('id').substring($(this).attr('id').length-1)).length > 0) 
		{
			$('#right_content_box_more'+$(this).attr('id').substring($(this).attr('id').length-1)).slideUp('fast', function() {});
		}
	});
	
	
	$("#slider_right").click(function() {
		clicked = true;
		adSlide("next");
	});
	
	$("#slider_left").click(function() {
		clicked = true
		adSlide("prev");
	});
	
	$("#search_text").click(function() {
		
		$("#search_text").css('color', 'black');
		$("#search_text").css('font-style', 'normal');
		$("#search_text").focus();
		$("#search_text").select();
	});
	
	
	$('.main_ad').each(function(intIndex) {
		var item_id = ($(this).attr('id').substring($(this).attr('id').length-1));
		$('#main_ad_links').append('<div class="main_ad_link" id="main_ad_link'+item_id+'">&nbsp;</div>');
	
	});
	// fade out 1
	
	$('#main_ad_link1').css('background-color','#9B009B');
	
	$('.main_ad_link').click(function(e){
		e.preventDefault();
		var item_id = ($(this).attr('id').substring($(this).attr('id').length-1));
		banner_click = true;
		banner_click_allow = true;
		
		if (active_slide != item_id) {
			 fadeThrough(active_slide, item_id);
		}
	});
	
	
	
});

function slideLoop() {
	
	if (clicked == false) {
		adSlide('next');
	}


}


function adSlide(direction) {

	if (direction == "prev") {
		
		newSlide = (active_slide-1);
		
		if (($('#main_advert'+newSlide).length > 0) && (animate_slide == false)) {
			animate_slide = true;
			
			$('#slider_content').animate({
				left: '+=550',
				}, 500, function() {
					animate_slide = false;
					active_slide = (active_slide-1);
					if (clicked == false) {
						var t=setTimeout("slideLoop()",intervalt);
					}
					
				});
		
		} else if (animate_slide == false){

			animate_slide = true;		
			$('#slider_content').animate({
				left: '-'+(550*3),
				}, 500, function() {
					animate_slide = false;
					active_slide = 4;
					if (clicked == false) {
						var t=setTimeout("slideLoop()",intervalt);
					}
			});
		
		}
		
		
		
	}
	
	if (direction == "next") {
		
	
	
		newSlide = (active_slide+1);
		
		if (($('#main_advert'+newSlide).length > 0) && (animate_slide == false)) {
			animate_slide = true;
			
			$('#slider_content').animate({
				
				left: '-=550',
				
			}, 500, function() {
				animate_slide = false;
				active_slide = (active_slide+1);
				if (clicked == false) {
					var t=setTimeout("slideLoop()",intervalt);
				}
			});
			

			
		} else if (animate_slide == false){
			animate_slide = true;		
			$('#slider_content').animate({
				left: '0',
				}, 1000, function() {
					animate_slide = false;
					active_slide = 1;
					if (clicked == false) {
						var t=setTimeout("slideLoop()",intervalt);
					}
			});
		
		}	
		
	}
	
	
	
	
	

}



		function fadeThrough(from, advertno) {
			
		 if (banner_click == false || (banner_click_allow == true && banner_click == true)) {	
			
			if (banner_click == true) {banner_click_allow = false} ;
			
			if ($('#main_advert'+advertno).length > 0) {
				$('#main_advert'+from).fadeOut('slow'); 					
				$('#main_ad_link'+from).animate({backgroundColor:'#5B005B'}, 1000, function() {});
				$('#main_advert'+(advertno)).fadeIn('slow');
				$('#main_ad_link'+advertno).animate({backgroundColor: '#9B009B'}, 1000, function() {});
				
				active_slide = advertno;
				
				if (banner_click == false) {
					var t=setTimeout("fadeThrough("+advertno+", "+(advertno+1)+")",intervalt);
				}
			}
			else {
				$('#main_advert'+from).fadeOut('slow'); 
				$('#main_ad_link'+from).animate({backgroundColor:'#5B005B'}, 1000, function() {});				
				$('#main_advert1').fadeIn('slow');
				$('#main_ad_link1').animate({backgroundColor: '#9B009B'}, 1000, function() {});
				
				active_slide = 1;
				
				if (banner_click == false) {
				var t=setTimeout("fadeThrough(1, 2)",intervalt);	
				}
				
			}
			}
		}
