/*
Salvo l'istanza di jQuery con tutti i plugin che ho caricato in modo che anche
se django-cms inserisce la sua barra si vedono tutti gli script perch io salvo un'istanza della 
mia 
*/
$_theme = $;

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $_theme(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.css('min-height',tallest);
}

$_theme(document).ready(function() {
	
	equalHeight($_theme("#content .column"));
	
	var SiteSwitcher=function(){
	var f,d,g;
	f=$_theme(window).width();
	d=$_theme(window).height();
	g=$_theme("<div class='trans'></div>");
	g.css("height",d);
	g.css("width",f);
	g.hide();
	
	$_theme("#site-switcher").click(function(){
	$_theme("#site-panel").show();
	g.css("width",$_theme(document).width());
	g.css("height",$_theme(window).height());
	g.show()});
	
	g.click(function(){
	$_theme("#site-panel").hide();
	g.hide()});
	
	$_theme("body").append(g)
	
	};
	
	$_theme(document).ready(function(){
	var b=new SiteSwitcher()
	});
	
$_theme(document).ready(function() {
	
	var h1 = $_theme('h1');
	var menu = $_theme('#menu li');
	var menuactive = $_theme('#menu li a.active, #menu li a:hover.active');
	var date = $_theme('.date');
	var btn = $_theme('.btn');
	Cufon.replace(h1, { fontFamily: 'AvantGarde LT Medium', hover: true });
	Cufon.replace(menu, { fontFamily: 'AvantGarde LT Medium', hover: false, textShadow: '1px 1px #181818' });
	Cufon.replace(menuactive, { fontFamily: 'AvantGarde LT Medium', textShadow: '1px 1px #0e445e' });
	Cufon.replace(date, { fontFamily: 'AvantGarde LT Medium' });
	Cufon.replace(btn, { fontFamily: 'AvantGarde LT Medium' });
	
	function default_navigation(carousel, selector){
		$_theme(selector).bind('click', function() {
			var index = $_theme(this).html();
			carousel.scroll($_theme.jcarousel.intval(index));
			$_theme(selector).removeClass("active");
			$_theme(this).addClass("active");
			return false;
		});
	}
	
	function slider_navigation(carousel) {
		default_navigation(carousel, '#main-navigation a');
	};
	
	function news_navigation(carousel) {
		default_navigation(carousel, '#news-navigation a');
	};
	
	function link_navigation(carousel,selector) {
		$_theme(selector).removeClass("active");
		$_theme(selector + '.' + carousel.last).addClass("active");
	}
	
	function services_navigation(carousel) {
		default_navigation(carousel, '#services-navigation a');
	};
	
	function work_navigation(carousel) {
		default_navigation(carousel, '#work-navigation a');
	};
		
	$_theme('#slider-content').jcarousel({
		wrap:'last',
		initCallback: slider_navigation,
		scroll:1,
		itemLoadCallback:{ 
			onAfterAnimation: function(carousel){
				link_navigation(carousel,"#main-navigation a");
			},
		},
		auto:5,
		buttonPrevHTML:null,
		buttonNextHTML:null
	});
	
	$_theme('#last-news').jcarousel({
		wrap:'last',
		initCallback: news_navigation,
		scroll:1
	});
	
	$_theme('#services').jcarousel({
		wrap:'last',
		initCallback: services_navigation,
		scroll:1
	});
	
	$_theme('#last-work').jcarousel({
		wrap:'last',
		initCallback: work_navigation,
		scroll:1
	});
	
});

$_theme("#portfolio-item img").lazyload({   
	effect: "fadeIn"
});

$_theme("#portfolio-item-small img").lazyload({   
	effect: "fadeIn"
});

$_theme("#tab a").click(function(){
	$_theme("#tab a").removeClass("active");
	var rel = $_theme(this).addClass("active").attr("rel");
	$_theme("#most-read-comment > div:not(#tab)").removeClass("active");
	$_theme("#most-read-comment ."+rel).addClass("active");
});

if( $_theme("a[rel='prettyPhoto']").length ){
	$_theme("a[rel='prettyPhoto']").prettyPhoto();
}

});
