var ajaxURL = "/ajax/";
var ajaxSeparator=",,,,,"; 
var currentCircle=1;
var myWidth = 0;
var currentSlide=1;
var currentLeft = 0;
var slidingNow = false;

var clickedCircle=false;

$(function(){
	
	
	
	inputShowHideText($("input[type=text]"));
	$("a[rel=_blank]").attr("target","_blank");
	myWidth = $("body").innerWidth();
	
	$(".slide").css("width", myWidth + "px");
	$(".scroll_mask").css("width", myWidth + "px");
	$(".scroll").css("width", myWidth*2 + "px");
	
	$(window).resize(function(){
		myWidth = $("body").innerWidth();
		$(".slide").css("width", myWidth + "px");
		$(".slide").css("background-position", "center top");
		$(".scroll_mask").css("width", myWidth + "px");
		$(".scroll").css("width", myWidth*2 + "px");
	
	});
	
 
	Cufon.replace('.cf_1, .more_header', {fontFamily: 'Avenir Next LT Pro'	});
	Cufon.replace('.cf_3', {fontFamily: 'Chronicle Disp Cond Light'	});
	 
	
	$(".circle").click(function(){
		clickedCircle=true;
		var rel = $(this).attr("rel");
		if (slidingNow){
			return;
		}
		
		temp=currentCircle;
		if (rel==currentCircle){
			return;
		}
		slidingNow=true;
		$(".slider_link").attr("href", link[rel]);
		$(".circles div.dot").fadeOut(function(){
			$("div.circle[rel="+temp+"]").empty();	
		});
		$(this).append("<div class='dot'></div>");
		currentCircle=rel;
		 if (rel>currentSlide){
			// w prawo
			$("div.scroll div.slide[rel="+rel+"]").show();
			newLeft =  -1 * myWidth;
		 } else {
			// w lewo
			newLeft =  0;
			$("div.scroll div.slide[rel="+rel+"]").show();
			$(".scroll").css("left","-"+myWidth+"px");
		 }
		$(".scroll").animate({
			left: newLeft +"px"
		}, function(){
			currentSlide=rel;
			currentLeft = 0;
			$("div.scroll div.slide[rel!="+rel+"]").hide();
			$(".scroll").css("left","0");
			$(".scroll").css("width", myWidth*2 + "px");
			slidingNow=false;
		});
	});
	
		
	$(".newsletter").submit(function(){
		$(".newsletter .hint .info").html("");
		$(".newsletter .submit").fadeOut();
		$(".newsletter .hint .info").removeClass("red");	
		$(".newsletter .hint .info").removeClass("green");	
		
		$.getJSON("/ajax/subscribe" + ajaxSeparator + $("#newsletter").val(), function(result){
		
			$(".newsletter .hint .info").addClass(result.color);	
			$(".newsletter .hint .info").html(result.info);	
			setTimeout(function(){
				$(".newsletter .hint").slideUp(function(){
					$(".newsletter .submit").fadeIn();
					$(".newsletter .text").val("")
					
				});		
			}, 2000);
			
		
		});
		
		$(".newsletter .hint").slideDown();
		return false;
	});	
	
	
	
	
	
	
	
		$(".reccomend").submit(function(){
		//alert("a");
		$(".reccomend .hint .info").html("");
		$(".reccomend .submit").fadeOut();
		$(".reccomend .hint .info").removeClass("red");	
		$(".reccomend .hint .info").removeClass("green");	
		
		$.getJSON("/ajax/recommend" + ajaxSeparator + $(".reccomend input[type=text]:eq(0)").val() + ajaxSeparator + $(".reccomend input[type=text]:eq(1)").val(), function(result){
		
			$(".reccomend .hint .info").addClass(result.color);	
			$(".reccomend .hint .info").html(result.info);	
			setTimeout(function(){
				$(".reccomend .hint").slideUp(function(){
					$(".reccomend .submit").fadeIn();
					$(".reccomend input[type=text]:eq(0)").val("");
					$(".reccomend input[type=text]:eq(1)").val("");
					
				});		
			}, 2000);
			
		
		});
		
		$(".reccomend .hint").slideDown();
		return false;
	});	

	
	
	
	
	
	
	
});








function submitPool(id){
	
	//return;
	z=$("input[name=poll_"+id+"]:checked").val();
	if (z!=undefined){
		$("#main_pool_submit").fadeOut("", function() {
			$("#main_pool_data"+id).slideUp("slow", function(){
				var poolId = id;
				var answerid = z;
				var lang = $("#lang").val(); 
				
				$.getJSON(ajaxURL+"/pollvote"+ajaxSeparator+poolId+ajaxSeparator+answerid+ajaxSeparator+lang, "", function(result){
					
					if (result[1]==1){
					// alert("ok");
					} else {
					//alert("gÅ?osowaÅ?eÅ? wczeÅ?niej!");
					}
					
					for (i in result[2]){
						 $("#td"+i).html(result[2][i]+"%");
					}
					$("label.radio_unchecked, label.radio_checked").css("background", "none");
					$("label.radio_unchecked, label.radio_checked").css("padding-left", "10px");
					
					
					$("#main_pool_data"+id).slideDown("slow","");
				}); 
				
			});
		});
	}
}


function inputShowHideText(jQueryObject) {
   jQueryObject.each(function(i) {
       $(this).attr('defaultValue', $(this).val());
       $(this).blur(function() {
           if (this.value=='') this.value = this.defaultValue;
       });
       $(this).focus(function() {
           if (this.value == this.defaultValue) this.value = '';
       });
    });
}

$(function(){
setInterval(function(){

	if (clickedCircle){
		return;
	}
	
	var rel = 0;
	//this
	if (currentCircle==5){
		rel=1;
	} else {
		rel=currentCircle+1;
	}
	
	
	if (slidingNow){
		return;
	}
	
	temp=currentCircle;
	if (rel==currentCircle){
		return;
	}
	slidingNow=true;
	$(".slider_link").attr("href", link[rel]);
	$(".circles div.dot").fadeOut(function(){
		$("div.circle[rel="+temp+"]").empty();	
	});
	$("div.circle[rel="+rel+"]").append("<div class='dot'></div>");
	currentCircle=rel;
	 if (rel>currentSlide){
		// w prawo
		$("div.scroll div.slide[rel="+rel+"]").show();
		newLeft =  -1 * myWidth;
	 } else {
		// w lewo
		newLeft =  0;
		$("div.scroll div.slide[rel="+rel+"]").show();
		$(".scroll").css("left","-"+myWidth+"px");
	 }
	$(".scroll").animate({
		left: newLeft +"px"
	}, function(){
		currentSlide=rel;
		currentLeft = 0;
		$("div.scroll div.slide[rel!="+rel+"]").hide();
		$(".scroll").css("left","0");
		$(".scroll").css("width", myWidth*2 + "px");
		slidingNow=false;
	});

	 
}, 5000);



$("body").mousemove(function(e){
	/*
	if (!($(e.target).parents('#controller1').length)){
		if (slided1){
			sequence1_off();
		}
	}
	if (!($(e.target).parents('#controller2').length)){
		if (slided2){
			sequence2_off();
		}
	}	
	*/
})


});


