/* main page doc.ready */
$(document).ready(function(){
	// initialize scrollable
	$(".scrollable").scrollable({circular:true});
	

});

/* rotator main page */
function ZmienZakladke(t,s) {
	rotator_hold = 0;
	var currentIdTab = $(t).prop("id");
	/*Natychmiastowee dokonczenie wszystkich rozpoczetych animacji*/
	$("#Rotator #RightCol .Tab").stop(false,false);
		
	/*Przełączenie zakładki z animacją*/
	if (s == null || s == 'slow') {
			$("#Rotator #RightCol .Tab.On").animate({opacity:0.4, width:150, left:0},35, function(){
			$("#Rotator #RightCol .Tab").css({"background-image":"url(/img/tab_bg.gif)","width":"253px","left":"0", "opacity":"1"});
			$("#Rotator #RightCol .Tab").removeClass('On').addClass('Off');
			$("#Rotator #RightCol .Tab .Txt").css({"color":"#666666"});
			$('#Rotator #Container').empty();
			$('#Rotator #Con' + currentIdTab).children().clone().appendTo('#Container');
			$('#Rotator #Container .Img').css({"opacity":"0"}).animate({"opacity":"1"},1200);
			$("#Rotator #Container .Info").css({"top":"0"}).delay(1000).animate({"top":"-40"});
			$(t).removeClass('Off').addClass('On');
			$(t).css({"background-image":"url(/img/tab_act_bg.gif)","background-position":"right top","opacity":"0"}).animate({width:284, left:-30, opacity: 1},200).children().css({"color":"white"});
		});
	}
	/*Szybkie przelaczenie zakladki bez animacji*/
	else if (s == 'fast') {
			$("#Rotator #RightCol .Tab").css({"background-image":"url(/img/tab_bg.gif)","width":"253px","left":"0", "opacity":"1"});
			$("#Rotator #RightCol .Tab").removeClass('On').addClass('Off');
			$("#Rotator #RightCol .Tab .Txt").css({"color":"#666666"});
			$('#Rotator #Container').empty();
			$('#Rotator #Con' + currentIdTab).children().clone().appendTo('#Container');
			$("#Rotator #Container .Info").css({"top":"0"}).delay(1000).animate({"top":"-40"});
			$(t).removeClass('Off').addClass('On');
			$(t).css({"background-image":"url(/img/tab_act_bg.gif)","background-position":"right top","opacity":"0","width":"284px","left":"-30px","opacity":"1"}).children().css({"color":"white"});
	}
}

$(document).ready(function(){
	/*Załadowanie pierszej zakładki do Container'a*/
	ZmienZakladke($("#Rotator #RightCol .Tab:first"));

	/*Podswietlanie zakladki po najechaniu*/
	$("#Rotator #RightCol .Tab").mouseenter(function(){
		if ($(this).is(".Off")) {
			ZmienZakladke(this,'fast');
		}
	});
	
	/*Zatrzymanie Timera po najechaniu muszka na Rotator*/
	$('#Rotator').mouseenter(function(){
		stan_timera = 0;
		clearTimeout(rotator_t);
		clearTimeout(rotator_t2);
	});
	/*Ruszenie Timera po zjechaniu muszka z Rotatora*/
	$('#Rotator').mouseleave(function(){
		if (rotator_hold == 0 && stan_timera == 0) {
			rotator_t2 = setTimeout("timedCount()",4000);
			stan_timera = 1;
		}
	});
});

function timedCount() {
	var a;
	var TabId = $("#Rotator #RightCol .On").prop("id");
	if ( TabId == 'Tab3') {
		a = $("#Rotator #RightCol .Tab:first");
	}
	else {
		a = $("#Rotator #RightCol .Tab.On").next();
	}
	ZmienZakladke(a);
	rotator_t = setTimeout("timedCount()",4000);
}

/*Zmienne globalne*/
var rotator_t,rotator_t2;
var rotator_hold = 0;
var stan_timera = 1;

/*Uruchomienie rotatora*/
timedCount();





$(document).ready(function(){
	$('#cat_menu_pomieszczenia').click(function(){
		$(this).addClass('active');
		$('.'+$(this).prop('id')).show();
		$('#cat_menu_produkty').removeClass('active');
		$('.cat_menu_produkty').hide();
	});
	$('#cat_menu_produkty').click(function(){
		$(this).addClass('active');
		$('.'+$(this).prop('id')).show();
		$('#cat_menu_pomieszczenia').removeClass('active');
		$('.cat_menu_pomieszczenia').hide();
	});

});




$(document).ready(function(){
	//INI
		//Count divs
	var rotator = $("#rotator > div").size();
		//First picture to show
	var now = 1;
		//Speed in milliseconds
	var speed = 5000;
	
	//Hide all except first
	$("#rotator > div").each(function(){
		if($(this).prop("id") == "rot"+now){
			$(this).show();
		} 
	});
	
	//The picture changer mechainsm
	var nextOne = setInterval (function(){
		now++
		if(now>rotator){
			now = 1;
		}
		$("#rotator > div").each(function(){
			if($(this).prop("id") != "rot"+now){
				$(this).hide();
			} else {
				$(this).show();
			}
		});
	
		$("#rot_buttons > img").each(function(){
			if($(this).prop("class") != "rot"+now){
				$(this).attr("src","/img/informacje/unselected.png");
			} else {
				$(this).attr("src","/img/informacje/selected.png");
			}
		});
	}, speed );
	
	//Manual change
	$("#rot_buttons > img").click(function(){
		var Class = $(this).prop("class");
		$("#rot_buttons > img").attr("src","/img/informacje/unselected.png");
		$(this).attr("src","/img/informacje/selected.png");
		
		$("#rotator > div").each(function(i){
			if($(this).prop("id") != Class){
				$(this).hide();
			} else {
				now = i;
				$(this).show();
			}
		});
		
	});

});
