var screenWidth = 0;
var screenHeight = 0;
var openedGallery = null;
var openedPhoto = null;
var openedIndex = null;

var addEvent = function(elem, type, eventHandle) {
    if (elem == null || elem == undefined) return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    }
};

//addEvent(window, "resize", function() { alert('a'); } );

function getDrawableSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  screenWidth = myWidth;
  screenHeight = myHeight;
}

function openGallery(gallery, photo, index, category)
{
	//Settings for window resize
	openedGallery = gallery;
	openedPhoto = photo;
	openedIndex = index;
	
	getDrawableSize();
	var gallerycontainer = document.getElementById("cover_gallery");
	gallerycontainer.style.height = screenHeight + 'px';
	gallerycontainer.style.display = 'block';
	//gallerycontainer.innerHTML = "<div id='loading'><img class='loading_img' src='pics/loading.gif' /></div>";
	$('#cover_gallery').load('include/gallery.php?gallery='+gallery+'&photo='+photo+'&index='+index+'&w='+screenWidth+'&h='+screenHeight+'&category='+category);
}

function closeGallery()
{
	var gallerycontainer = document.getElementById("cover_gallery");
	gallerycontainer.innerHTML = "";
	gallerycontainer.style.display = 'none';
}

function sendMail(gallery, photo)
{
	if (document.getElementById('email').value != "email address...") {
		var email = document.getElementById('email').value;
		document.getElementById('email_field').innerHTML = "Sending Mail...";
		$('#email_field').load('include/mail_to_friend.php?email=' + email + '&gallery=' +gallery+ '&photo=' + photo);
	}	
}

function sendContactMail(form,field)
{
	if (form.email.value != "") {
		var request = "";
		request=form.request.value.replace(/\\/g,'\\\\');
		request=request.replace(/\'/g,'\\\'');
		request=request.replace(/\"/g,'\\"');
		request=request.replace(/\0/g,'\\0');
		$('#'+field).load("include/mail_contact.php",{email:form.email.value, request:form.request.value});
		//$('#'+field).load("include/mail_contact.php?email=" + form.email.value + "&request=" +request);
	}
	else
		document.getElementById(field).innerHTML = "Insert Mail Address";	
}

function openEmailDiv(gallery, photo)
{
	document.getElementById('email_field').innerHTML = "<input onclick='clearFieldEmail()' class='email_text' type='text' id='email' name='email' value='email address...' /><a class='email_button' href=\"javascript:sendMail('"+gallery+"','"+photo+"');\">send</a>";
}

function clearFieldEmail()
{
	if(document.getElementById('email').value == "email address...")
		document.getElementById('email').value = "";
}

//Inizio Contact Page Block
var a = false;
var b = false;
var c = false;

function outOfImage()
{
	if (!a && !b && !c) {
		$(".c1").stop().animate({
			width: "200px"
		}, "slow");
		$(".c2").stop().animate({
			width: "198px"
		}, "slow");
		$("#c2").stop().animate({
			marginLeft: "-200px"
		}, "slow");
		$(".c3").stop().animate({
			width: "200px"
		}, "slow");
		$("#c3").stop().animate({
			marginLeft: "-400px"
		}, "slow");
	}
}
			
function setUpSlideImages()
{
	$(".c1").hover(
		function() {
			a = true;
			$(".c1").stop().animate( { width: "540px" }, "slow");
			$(".c2").stop().animate( { width: "30px" }, "slow");
			$(".c3").stop().animate( { width: "30px" }, "slow");
		},
		function() {
			a = false;
			outOfImage();
		});
	$(".c2").hover(
		function() {
			b = true;
			$(".c2").stop().animate( { width: "540px" }, "slow");
			$("#c2").stop().animate( { marginLeft: "0px" }, "slow");
			$(".c1").stop().animate( { width: "30px" }, "slow");
			$(".c3").stop().animate( { width: "30px" }, "slow");
		},
		function() {
			b = false;
			outOfImage();
		});
	$(".c3").hover(
		function() {
			c = true;
			$(".c1").stop().animate( { width: "30px" }, "slow");
			$(".c2").stop().animate( { width: "30px" }, "slow");
			$(".c3").stop().animate( { width: "540px" }, "slow");
			$("#c3").stop().animate( { marginLeft: "0px" }, "slow");
		},
		function() {
			c = false;
			outOfImage();
		});
}
//Fine Contact page Block

var delay = (function(){   var timer = 0;   return function(callback, ms){     clearTimeout (timer);     timer = setTimeout(callback, ms);   }; })(); 

