//$ = jQuery.noConflict(); 
$(document).ready(function() {
	icube_slider.init();
	quick_gallery.init();
	// Rozwijane menu
	$("#left-menu li ul").hide(); // ukrywa wszystkie menu	
	$("#left-menu").find(".sec-active").parent().parent().slideDown("normal");	

	$("#left-menu .first-level-item").click(function () {
		if ($(this).hasClass('just-link')) 
			return true;
	 
		if ($(this).hasClass('first-active')) {
			$(this).removeClass('first-active');
		} else {
			$('#left-menu .first-level-item').removeClass('first-active');
			$(this).addClass('first-active');
		}
			
		$('#left-menu .first-level a[class!="first-active"]').parent().find("ul").slideUp("normal");						
		$(this).parent().find("ul").hide();
			
		if ($(this).hasClass('first-active')) {
			$(this).parent().find("ul").slideToggle("normal");
		}
		return false;
	});
	// koniec rozwijanego menu
	
	var inputFocus = function() {
			$(this).removeClass("idleField");
	        if (this.value == this.defaultValue){
	        	this.value = '';
	    	}
	        if(this.value != this.defaultValue){
		    	this.select();
	        }
	    };
	    
	var inputBlur = function() {
	        if (this.value == ''){
	        	$(this).addClass("idleField");
	        	this.value = (this.defaultValue ? this.defaultValue : '');
	    	}
	    };
	
	if ($('#singup-box').length) {
	    $('#singup-box input[type="text"]').addClass("idleField");
		$('#singup-box input[type="text"]').focus(inputFocus);
	    $('#singup-box input[type="text"]').blur(inputBlur);  			 		
	
		$('#quick-submit').click(function(){
			if ($('#z-imie').val() == 'Imię...*') $('#z-imie').val('');
			if ($('#z-nazwisko').val() == 'Nazwisko...*') $('#z-nazwisko').val('');
			if ($('#z-email').val() == 'Email...*') $('#z-email').val('');
			if ($('#z-telefon').val() == 'Numer telefonu...*') $('#z-telefon').val('');
			return true;
		});
	}				
});

var icube_slider = {
	elements_amount : 3, // ilość elementów
	current_element : 1,
	stoped : false,
	run : null, // interval
	speed_time : 6000,
	fade_speed : 800,
	timer_speed : 700,
	
	init: function() {	
		this.elements_amount = $('#slider-nav').children().size();
		this.show(1);
		
		for (var i = 1; i <= this.elements_amount; i++)
		{
			$('#slider-nav-'+i).click(function() {
				var cid = this.id.slice(-1);
				icube_slider.fadeAllOut(cid);
				if (cid != icube_slider.current_element) { // pokaz jeśli nie jest aktualnym
					icube_slider.show(parseInt(cid));
				} else {
					clearInterval(icube_slider.timer);
				}
				
				if (icube_slider.stoped == true && icube_slider.current_element == cid) { // drugi raz kliknięto na ten sam link, uruchom pokaz slajdów	
					icube_slider.stoped = false;
					icube_slider.run = setInterval('icube_slider.runSlider()', icube_slider.speed_time);
				} else {
					icube_slider.stoped = true;	
					clearInterval(icube_slider.run);
				}
				icube_slider.current_element = parseInt(cid);
				
				return false;
		    });
		}		
		this.run = setInterval('icube_slider.runSlider()', this.speed_time); 		
	}, 
	
	fadeAllOut: function(cid) {
		for (var i = 1; i <= this.elements_amount; i++)
			if (i != cid) this.hide(i); 
	},
	
	stop: function() {
		this.stoped = true;
		clearInterval(this.run);	
	},
	
	runslideshow: function() {
		this.stoped = false;
		this.run = setInterval('icube_slider.runSlider()', this.speed_time); 	
	},
	
	show: function(cid) {
		$('#slide_'+cid).fadeIn(this.fade_speed);
		
	//	if ($.browser.msie) {
			//$('#slider-'+cid+' *').fadeIn(this.fade_speed);
	//	}
			
		$('#slider-nav-'+cid).addClass('active');	
	},
	
	hide: function(cid) {
		$('#slide_'+cid).fadeOut(this.fade_speed);	
		//if ($.browser.msie) {
		//	$('#slider-'+cid+' *').fadeOut(this.fade_speed);
		//}		
		$('#slider-nav-'+cid).removeClass('active');
	},	
	
	runSlider: function() {
		if (this.stoped == true) {
			clearInterval(this.run);
			return;
		}
		
		this.hide(this.current_element);
		if (this.current_element == this.elements_amount) {
			this.show(1);
			this.current_element = 1; 
		} else {
			this.show(this.current_element + 1);
			this.current_element++; 
		}		
	}
}
var quick_gallery = {
	current : 0,
	elements_amount : 0,	
	run : null, // interval
	speed : 5000,
	fade_speed : 800,
	
	init: function() {	
		this.elements_amount = $('.gallery-set').size();
		this.next();
		this.run = setInterval('quick_gallery.next()', this.speed); 
	},
	
	next: function() {
		this.current++;
		if (this.current > this.elements_amount) {	
			this.current = 1;
		} 

		this.fadeAllOut(this.current);
		
		$('#quick-gallery-'+this.current).fadeIn(this.fade_speed);
		if ($.browser.msie) {
			$('#quick-gallery-'+this.current+' *').fadeIn(this.fade_speed);
		}

	},
	
	fadeAllOut: function(cid) {
		for (var i = 1; i <= this.elements_amount; i++) {
			if (i != cid) {
				$('#quick-gallery-'+i).fadeOut(this.fade_speed);
				if ($.browser.msie) {
					$('#quick-gallery-'+i+' *').fadeOut(this.fade_speed);
				}
			}
		}				
	}
}

