
$j(document).ready(function() {
	
	var pages_path = "images/pages/"
	var gallery_path = "images/gallery/"
	var gallery_big_path = "images/gallery/big/"
	
	//prepareGalleryContent()
	
	$j('#bottom_btt_enter').click(function() {
		$j("#bottom_payoff").fadeOut(500)
		$j("#bottom_btt_enter").delay(250).fadeOut(500)
		$j("#bottom_btt_blog").delay(250).fadeOut(500)
		$j("#bottom_logo").delay(500).fadeOut(700)
		$j("#bottom_bar").delay(1000).animate({},{duration:1200,easing:"easeOutQuart"});
		$j("#bottom_bar").delay(1000).animate({height:"68px",top:"+=318px","background-size":"-=318px"},{duration:1200,easing:"easeOutQuart",complete:function(){
			$j("#bottom_bar").css("z-index","1")
			$j("#top_payoff").fadeIn(600)
			$j("#footer_home").fadeIn(600)
		}});
		return false;
    });

	/*$j('#menu_container').click(function() {
		$j("#menu_bar").animate({top:"+=216px"},{duration:1400,easing:"easeOutQuart"});
		$j("#menu_container").animate({top:"+=100px"},{duration:1400,easing:"easeOutQuart"})
		$j("#menu_logo").fadeOut(400)
		$j("#top_logo").delay(400).fadeIn(500)
		$j('#menu_container').unbind("click")
    });*/
		
	/*$j('#menu_container div').click(function() {
		if (this.id.search("_sel") == -1) {
			if (this.id != "btt_gallery") {
				loadContent(this);
				if ( $j("#slider_gallery").css('display') != "none" ) {
					$j("#slider_gallery").fadeOut(400);
				}
			} else {
				var dy=1200;
				if ( $j("#pages_content").css('display') != "none" ) {
					$j("#pages_content").fadeOut(400);
					dy=1;
				}
				loadGallery(dy);
			}
			changeBG(this);
			changeSel(this);
		}
//		return false;
    });*/
	
	function loadGallery(d) {
		sb = new SlidingStrip(2, 'slider_container', false, '');
		sb.animate();
		$j("#slider_gallery").delay(d).fadeIn(600)
	}
	
	function prepareGalleryContent() {
		var imgContainer;
		for (var i=0; i<galleryThumbs.length;i++) {
			imgContainer = '<div class="slidingElement" id="'+i+'" style="float: left;">\n'+
			'<a href="" style="background-attachment:scroll;background-color:#FFFFFF;background-image:url('+gallery_path+galleryThumbs[i]+');'+
			'background-position:center center;background-repeat:no-repeat;border:0 none;display:block;height:70px !important;margin-right:25px;width:136px !important;"></a>\n'+
			'</div>';
			$j("#slider_container").append(imgContainer);
		}
	}
			
	function loadContent(selBtt) {
		var str = selBtt.id.split("btt_")
		$j("#pages_content").fadeOut(400,function() {
			$j("#pages_container").append($j("#content_holder *"))
			$j("#content_holder").html($j("#pg_"+str[1]))
			$j("#pages_content").fadeIn(400)
			$j('#content_holder').jScrollPane();
//			$j('#content_holder').jScrollPane({scrollbarOnLeft:true});
		});
	}
			
	function changeSel(selBtt) {
		var bttDivs = document.getElementById("menu_container").getElementsByTagName('div');
		$j("#menu_bar").data("section",selBtt.id)
		selBtt.id = selBtt.id + '_sel';
		var tmp;
		for (var i=0; i<bttDivs.length;i++) {
			if (bttDivs[i].id != selBtt.id) {
				tmp = bttDivs[i].id.split("_",2)
				bttDivs[i].id = tmp[0]+"_"+tmp[1]
			}
		}
	}

	function changeBG(selBtt) {
		var imgA;
		var imgB;
		var str = selBtt.id.split("_")

		if ( $j("#bg_photo_front").css('display') == "none") {
			imgA = "#bg_photo_front";
			imgB = "#bg_photo_back";
		} else {
			imgA = "#bg_photo_back";
			imgB = "#bg_photo_front";
		}
		
		$j(imgA).attr("src", pages_path+str[1]+".jpg"); 

		$j(imgA).fadeIn(1200,function() { 
			$j(imgA).load(function() { $j(imgB).fadeOut(1000); }); 
		});
	}
		
	function changeImage(selBtt) {
		var imgA;
		var imgB;
		var str = parseInt(selBtt.id)

		if ( $j("#bg_photo_front").css('display') == "none") {
			imgA = "#bg_photo_front";
			imgB = "#bg_photo_back";
		} else {
			imgA = "#bg_photo_back";
			imgB = "#bg_photo_front";
		}

		$j(imgA).attr("src", gallery_big_path+galleryImages[str]); 

		$j(imgA).fadeIn(1200,function() { 
			$j(imgA).load(function() { $j(imgB).fadeOut(1000); }); 
		});
	}
});

function PopupContattiCentrata(email) {
	var w = 400;
	var h = 500;
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	if (email ==  'info@veronicaolivier.it' || email == 'info@alessandropellegrinimanagement.com' || email == 'info@damianopetrelli.it')
	{	
		window.open("popup_email.php?e="+email,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	}
}
