$(document).ready(function() {

	var api_single;
	var api_gallery;
	var first_click_videos = 0;

	$.easing.custom = function (x, t, b, c, d) { 
		var s = 1.70158;  
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	
	api_single = $("#single").scrollable({ 
		size: 1, speed: 700, clickable: false, api: true, items: ".items-single", nextPage: ".nextSingle", prevPage: ".prevSingle"
	});
	
	api_gallery = $("#gallery").scrollable({ 
		size: 5, speed: 700, clickable: false, api: true, items: ".items-gallery", nextPage: ".nextGallery", prevPage: ".prevGallery"
	});
	
	api_videos = $("#videos").scrollable({ 
		size: 1, speed: 700, clickable: false, api: true, items: ".items-videos", nextPage: ".nextVideos", prevPage: ".prevVideos"
	});
	
	$(".galleryView").click(function(){
		$("#single").css({"display": "none"});
		$("#videos").css({"display": "none"});
		$("#gallery").css({"top": -275, "display": "block"}).animate({"top": 0}, 300);
		
		first_click_videos = 0;
	});
	
	$(".gallery-web").click(function(){
		var index_single = $(".gallery-web").index(this);
		
		$("#gallery").css({"display": "none"});
		$("#videos").css({"display": "none"});
		$("#single").css({"top": -275, "display": "block"}).animate({"top": 0}, 300, function() {
			api_single.setPage(index_single);
		});
	});
	
	$(".video-link").click(function(){
		var index_videos = $(".video-link").index(this);
		first_click_videos += 1;
		
		if(first_click_videos == 1){
			$("#single").css({"display": "none"});
			$("#gallery").css({"display": "none"});
			$("#videos").css({"top": -275, "display": "block"}).animate({"top": 0}, 300, function() {
				api_videos.setPage(index_videos);
			});
		}
		else{
			api_videos.setPage(index_videos);
		}
	});
	
	$(".goto-video").click(function(){
		var index_videos = $(this).siblings(".hide").val();
		first_click_videos += 1;
		
		if(first_click_videos == 1){
			$("#single").css({"display": "none"});
			$("#gallery").css({"display": "none"});
			$("#videos").css({"top": -275, "display": "block"}).animate({"top": 0}, 300, function() {
				api_videos.setPage(index_videos);
			});
		}
		else{
			api_videos.setPage(index_videos);
		}
	});
	
	$(".callme").click(function(){
		$("body").prepend('<div id="popup-overlay"></div><div id="popup"><a class="close-popup">X</a><span>Great Click!</span> Though a call would work a lot better. If you call me now, youll have a 98% chance of getting me directly.</div>');
		loadPopup();
		centerPopup();
	});
	
	$(".close-popup").live('click', function(){
		disablePopup();
	});
	
	var popupStatus = 0;
	
	function loadPopup(){
		if(popupStatus==0){
			$("#backgroundPopup").fadeIn("slow");
			$("#popup").fadeIn("slow");
			popupStatus = 1;
		}
	}
	
	function centerPopup(){
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#popup").height();
		var popupWidth = $("#popup").width();

		$("#popup").css({
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2,
			"display": "block"
		});
		$("#popup-overlay").css({
			"height": $(document).height()
		});
		
	}
	
	function disablePopup(){
		if(popupStatus==1){
			$("#popup-overlay").fadeOut("slow");
			$("#popup").fadeOut("slow");
			popupStatus = 0;
		}
	}
	
	$('#expandmural').click(function(){
		$("#muralvideo").show();
	});
	
	
});

$(window).load(function() {

	$(".gallery-web").bind("mouseenter", function(){
		$(this).append('<span class="clickhere">Click Here</span>');
		
		$(this).siblings(".gallery-web").each(function(){
			$(this).css({
				"opacity": 0.5
			}, 500);
		});
		
		$(this).css({
			"opacity": 1
		}, 500);
	});
	
	$(".gallery-web").bind("mouseleave", function(){
		$(".clickhere").remove();
	
		$(this).siblings(".gallery-web").each(function(){
			$(this).css({
				"opacity": 1
			}, 500);
		});
	});

});