/* -------------- jQuery */

var $j = jQuery.noConflict();
     
$j(document).ready(function(){

	var nw = $j("#nav").width();
	var w = 0;
	var n = 0;
	var margin = 0;
	
	$j("#nav li").map(function(){
		w = w + $j(this).width();
		n = n + 1;
	})	
	margin = (nw - w)/(n-1);
	margin = parseInt(margin);
	
	$j("#nav li:last").prevAll().css("margin-right", margin);
	
	$j("#pl.active").mouseenter(function(){
		$j(this).find("img").attr('src','http://teatrfigur.pl/public/images/pl-active.png');
	}).mouseleave(function(){
		$j(this).find("img").attr('src','http://teatrfigur.pl/public/images/pl.png');
	});
	
	$j("#en.active").mouseenter(function(){
		$j(this).find("img").attr('src','http://teatrfigur.pl/public/images/en-active.png');
	}).mouseleave(function(){
		$j(this).find("img").attr('src','http://teatrfigur.pl/public/images/en.png');
	});

	$j("#sidebar li").mouseover(function(){
		$j(this).addClass("current");
	});	
	$j("#sidebar li:has(a)").mouseout(function(){
		$j(this).removeClass("current");
		});
	$j("#sidebar li:has(a)").click(function(){
		window.location=$j(this).attr("title");
	});
	$j("#sidebar li:has(a)").click(function(){
		window.location=$j(this).attr("title");
	});
	
	$j("#galeria .box").addClass("blue");
	$j("#photos .box").addClass("blue");
	$j("#linki .box").addClass("blue");
	$j("#links .box").addClass("blue");
	
	$j("#recenzje .box").addClass("black");
	$j("#reviews .box").addClass("black");
	$j("#kontakt .box").addClass("black");
	$j("#contact .box").addClass("black");
	
	$j("#spektakle #content > div").addClass("black");
	$j("#warsztaty #content > div").addClass("black");
	
	$j("#shows #content > div").addClass("black");
	$j("#workshops #content > div").addClass("black");
	
	// $j("#warsztaty .box:has(h2)").addClass("black");
	
	$j("#repertuar #sidebar").addClass("blue");
	$j("#repertoire #sidebar").addClass("blue");
	
	$j(".box:not(:has(h2)) p:first").addClass("lower");
	
	$j("#recenzje #content p").eq(1).addClass("info");
	$j("#reviews #content p").eq(1).addClass("info");
	
	$j("#o-zespole img").mouseenter(function(){
		if($j(this).attr("title")) {
			var src = $j(this).attr("src");
			var title = $j(this).attr("title");
			$j(this).attr("src", title);
			$j(this).attr("title", src);
		}
	});
	
	$j("#o-zespole img").mouseleave(function(){
		if($j(this).attr("title")) {
			var src = $j(this).attr("src");
			var title = $j(this).attr("title");
			$j(this).attr("src", title);
			$j(this).attr("title", src);
		}
	});
	
	$j("#about-us img").mouseenter(function(){
		if($j(this).attr("title")) {
			var src = $j(this).attr("src");
			var title = $j(this).attr("title");
			$j(this).attr("src", title);
			$j(this).attr("title", src);
		}
	});
	
	$j("#about-us img").mouseleave(function(){
		if($j(this).attr("title")) {
			var src = $j(this).attr("src");
			var title = $j(this).attr("title");
			$j(this).attr("src", title);
			$j(this).attr("title", src);
		}
	});
	
});;