
// Add a cooler easing method in. Taken from jquery easing plugin.

jQuery.extend( jQuery.easing,{
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
});


// add methods for sliding the side panels
// http://www.sitepoint.com/forums/showthread.php?t=597712
/*
jQuery.fn.extend({
	slideRight: function() {
		return this.each(function() {
			jQuery(this).animate({width: 'show'},'slow', 'easeInOutExpo');
		});
	},
	slideLeft: function() {
		return this.each(function() {
			jQuery(this).animate({width: 'hide'},'slow', 'easeInOutExpo');
		});
	},
	slideToggleWidth: function() {
		return this.each(function() {
			var el = jQuery(this);
			if (el.css('display') == 'none') {
				el.slideRight();
			} else {
				el.slideLeft();
			}
		});
	}
});
*/


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}


//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	var pageHeight = $(document).height();
	var pageWidth = $(document).width();



	//alert("height: " + windowHeight + "\nwidth: " + windowWidth + "\nDoc height: " + pageHeight + "\nDocwidth: " + pageWidth);
	//centering
		//"position": "absolute",

	$("#popupContact").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".menu-item-2861").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		return false;
	});
	$(".ConnectPopup").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		return false;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});



	//$(".sidebarTrigger").click(function(){
	//	$slideMe = $(this).prev();
	//	$slideMe.slideToggleWidth();
	//	$(this).toggleClass('sidebarTriggerOpen');
	//});
		//$slideMe.slideToggle();

	// This is the slideshow for the Chic side, handled by Cycle
	//$('#slideshow img:first').fadeIn(1000, function() {
	$('#slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		random: 1
	});
	//});

	// wqe need a different gallery ID here, because we want this slideshow to have
	//   a pager and manual control, and be sequential
	$('#gallery').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		random: 0,
		pager: '#pager',
		next:   '#arrow-next', 
		prev:   '#arrow-prev', 
	});


	
	// This handles the persona switcher
	var navDuration = 150; //time in miliseconds
	$('#switch-chic').hover(function() {
		$(this).animate({ marginTop: 0 }, navDuration);
	}, function() {
		$(this).animate({ marginTop: -25 }, navDuration);
	});
	$('#switch-geek').hover(function() {
		$(this).animate({ marginTop: 0 }, navDuration);
	}, function() {
		$(this).animate({ marginTop: -25 }, navDuration);
	});
}); 

