var hp = '';
$(document).ready(function(){
	hp = $('#canvas').attr('name');
	checkCookie();
	
	$(this).find('div.item').each(function(){
		
		$(this).find('img').each(function(){
			m = $(this).attr('height');
		});
		
		$(this).find('div.over').each(function(){
			var t = (m - 160)/2;
			$(this).css('top',t);
		});
		
	});
		

	
	$('div.item').mouseover(function(){
		$(this).find('div.over').each(function(){
			$(this).css('visibility','visible');
		})
	}).mouseout(function(){
		$(this).find('div.over').each(function(){
			$(this).css('visibility','hidden');
		})
	});
	
	var intro = $('div#intro').html();
	if(intro){
		$('div#intro').click(function(me){
			me.preventDefault();
			$(this).fadeOut(300);
		});
	}
	
	
	Shadowbox.init();
	
	
});

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	//console.log(document.cookie);
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function checkCookie(){
	var cookieActive = readCookie('ep_cookie');
	if(!cookieActive){
		if(hp != '' && hp != undefined){
			//console.log(hp+"--hp");
			createCookie('ep_cookie','edoardo_pasero',0);
			$('body').append('<div id="intro"><a href="#"><span>Edoardo Pasero - Photographs, fotografie. Enter</span></a></div>');
		}else{
			createCookie('ep_cookie','edoardo_pasero',0);
		}
	}
}
