/*
 * --------------------------------------------------------------------
 * Simple Scroller
 * by Siddharth S, www.ssiddharth.com, hello@ssiddharth.com
 * Version: 1.0, 05.10.2009
 * --------------------------------------------------------------------
 */

$(document).ready(function() {

	var slider = $("#slider");
	var images = $("#slider div");
	var index = 0;
	var lindex = images.length-1;

	slider.prepend('<a href="/" class="btn prev"></a><a href="/" class="btn next"></a>');

	slider.find(".next").click( function(){showOn(""); return false; } );
	slider.find(".prev").click( function(){showOn("prev"); return false; } );
	showOn("start");

	function showOn(direction) {
		if (direction == "" || !direction) {
			lindex = index;
			if ( index<(images.length-1)){index = index+1; }
			else { index=0; }
			//alert ( "Убираем "+lindex+", ставим "+index );
			//console.log(">> Убираем "+lindex+", ставим "+index);
		}
		if (direction == "prev") {
			lindex = index;
			if (index-1<0) { index = images.length-1; }
			else {index=index-1;}
			//console.log("<< Убираем "+lindex+", ставим "+index);
		}

		if ( $.browser.msie ) {
			$(images[lindex]).css("display", "none");
			$(images[index]).css("display", "block");
			setTimeout( showOn, 6000);
		}
		else {
			$(images[lindex]).fadeOut(500,
											function() {
												$(images[index]).fadeIn(800,
													function() { setTimeout( showOn, 4500); } );
												}
									  );
		}

	}
	if ( $.browser.msie ) {
		$("#header").hover( function(){ $(this).find(".btn").css("display", "inline-block"); }, function(){ $(this).find(".btn").css("display", "none"); });
	}
	else {
		slider.hover( function(){ $(this).find(".btn").fadeIn(300); }, function(){ $(this).find(".btn").fadeOut(300); });
	}

});
