/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	}
});

 
function countdown() {
	var cd = setInterval(function(){
		$("#loading").fadeOut(50)}, 7000);	
	}
 

// BACKGROUND CHANGE
function changeBg() {
	theImages = new Array();
	theImages[0] = 'lib/images/bg-1-';
	theImages[1] = 'lib/images/bg-2-';
	theImages[2] = 'lib/images/bg-3-';
	theImages[3] = 'lib/images/bg-4-';
	theImages[4] = 'lib/images/bg-5-';
	theImages[5] = 'lib/images/bg-6-';
	theImages[6] = 'lib/images/bg-7-';
	theImages[7] = 'lib/images/bg-8-';
	theImages[8] = 'lib/images/bg-9-';
	theImages[9] = 'lib/images/bg-10-';
	theImages[10] = 'lib/images/bg-11-';
	theImages[11] = 'lib/images/bg-12-';
	theImages[12] = 'lib/images/bg-13-';
	theImages[13] = 'lib/images/bg-14-';
	theImages[14] = 'lib/images/bg-15-';
	theImages[15] = 'lib/images/bg-16-';
	theImages[16] = 'lib/images/bg-17-';
	theImages[17] = 'lib/images/bg-18-';
	theImages[18] = 'lib/images/bg-19-';
	theImages[19] = 'lib/images/bg-20-';
	theImages[20] = 'lib/images/bg-21-';
	theImages[21] = 'lib/images/bg-22-';
	theImages[22] = 'lib/images/bg-23-';
	theImages[23] = 'lib/images/bg-24-';
	theImages[24] = 'lib/images/bg-25-';
	theImages[25] = 'lib/images/bg-26-';

	var p = theImages.length;
	whichImage = Math.round(Math.random()*(p-1));
	
	var winWidth = $(window).width();
	var aa = '1200';
	
	if (winWidth <= 1200) {
		aa = '1200';	
	} else if (winWidth > 1200 && winWidth <= 1600) {
		aa = '1600';	
	} else {
		aa = '1920';	
	}
		
	$('body').css({'background':'url(' + theImages[whichImage]+aa+'.jpg) fixed left top'});
}

//BACKGROUND RESIZE
function resizeBg(){
	var winWidth = $(window).width();
	var aa = '1200';
	
	if (winWidth <= 1200) {
		aa = '1200';	
	} else if (winWidth > 1200 && winWidth <= 1600) {
		aa = '1600';	
	} else {
		aa = '1920';	
	}
		
	$('body').css({'background':'url(' + theImages[whichImage]+aa+'.jpg) fixed left top'});
}

// POSITION FOOTER
function credits(){
	
	var winHeight = $(window).height();
	var docHeight = ($("#content").height() + 30);
	if (winHeight >= docHeight) {
		$("#footer").css({'position':'absolute', 'top':(winHeight - 30) + "px", 'bottom':'auto', 'height':'10px'});
	} else {
	$("#footer").css({'clear':'both','position':'absolute', 'top':(docHeight) + "px", 'height':'10px'});
	}
}

// POSITION #Openingtimes
function openingtimes(){
	
	var winHeight = $(window).height();
	var docHeight = ($("#content").height() + 30);
	if (winHeight >= docHeight) {
		$("#openingtimes").css({'position':'absolute', 'top':(winHeight - 30) + "px", 'bottom':'auto', 'height':'10px'});
	} else {
	$("#openingtimes").css({'clear':'both','position':'absolute', 'top':(docHeight) + "px", 'height':'10px'});
	}
}

//window.onresize = changeBg;
//window.onresize = footer;

$(window).resize(function(){
  resizeBg();
  credits();
});


$(document).ready(function(){
	
	credits();
	changeBg();

	//nascondo appendice link, 
	$("#followus").fadeOut(5);

	//ANIMAZIONE MENU + DIV APPENDICE LINK
 
	$("#menu").css({'left':'130px', 'overflow' : 'hidden', 'width':'0px'}).animate({width:"130px", left: '10px'},400,"easeInQuad", function(){
			$("#menu").fadeOut(50,function(){
				$("#menu").fadeIn(20, function(){
					$("#menu").fadeOut(50,function(){
						$("#menu").fadeIn(20, function(){
								$("#followus").fadeIn(50, function(){
									$("#followus").fadeOut(50,function(){
										$("#followus").fadeIn(50);
									});							
								});
						});
					});							
				});																		  
			 });
	});

	/*
	//ANIMAZIONE INTRO
	if (!$.cookie('anim')) {	
		$("body").append("<div id='loading' ><img alt ='' src='<%baseurl%>/lib/images/intro.gif' onload='javascript:countdown()' height='700px' /></div>");
		$("#loading").css({
			'background':'dd#000',
			'width': '100%',
			'height': $(document).height(),
			'position':'absolute',
			'z-index':100,
			'top':'0',
			'text-align':'left',
			'left':'0',
			'overflow':'hidden'				
		});			
		$("#loading img").css({
			'margin':'10px'				
		});
		$.cookie('anim',true, {expires:0});
	}
	*/
	

	
	
	
	//Animation Content
			
	$("#content").css({'width':'0px', 'overflow':'hidden'}).animate({'width':"600px", 'padding':'0 10px 0 0'},300,"easeInQuad", function(){
		$(this).fadeOut(50,function(){
			$(this).fadeIn(20);
	   });																		  
	});
	
	
	
	var help = setInterval(function(){
		$("#content").css("width","600px");
		$("#menu").css({'left':'10px', 'width':'130px'});
	}, 4000);
		
		
	
	
});