jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
    

$(function() {
	
	$("div#slider").toggleClass("hasJs"); /* has js */
	var $curstep = 1; //current step
	var $inProgress = 0;
   	
	setTimeout(fadeSlides, 10000);

	function fadeSlides(){
		setTimeout(fadeSlides,10000);
		if($inProgress == 0){
			$inProgress = 1;
			if($curstep == 4){
				$curstep = 1;
				$prevstep = 4;
			}else{
				$curstep += 1;
				$prevstep = ($curstep - 1);
			}
			
			$('#slide'+$prevstep).removeClass("currentSlide");

			$('#slide'+$prevstep).css("display","none");
			$('#slide'+$curstep).addClass("currentSlide");
			setCurrentTab();
			$('#slide'+$curstep).css("display","block");
			$inProgress = 0;

		}
	}

	
	$("#slideCon a").click(function () { 
		if($inProgress == 0){
			$inProgress = 1;
			targetDiv = $(this).attr("href");
			$curstep = parseFloat(targetDiv.substring(6));
			$(".currentSlide").css("display","none");
			$(targetDiv).css("display","block");
			$inProgress = 0;
			$(targetDiv).addClass("currentSlide");
			setCurrentTab();
		}
		return false;
	});

	
	function setCurrentTab(){
		$('#slideCon li').removeClass("current");
		$('#slideBut'+$curstep).addClass("current");
	}
	

});
