// Header & Footer JavaScript

jQuery(document).ready(function() {
 
	// Create CSS styled scroll panes
	jQuery('.scroll-pane').jScrollPane({
		enableKeyboardNavigation: false,
		autoReinitialise: true,
		autoReinitialiseDelay:500,
		scrollbarMargin:10
	});
	
	jQuery('#footer .contents-button').bind('click',function(){
		var container = jQuery( ".footer-carousel-container" );
		if (container.css('bottom') != "39px"){
			container.animate({bottom:39},
				{
					duration:500,
					easing:'easeOutQuad',
					complete:function() { Cufon.now(); }
				});	 
		} else {
			container.animate({bottom:-160},500,'easeOutQuad');	 
		}
	});
		
	jQuery(window).resize(function(){
		//var numberOfItems = Math.floor((jQuery("body").width()-160)/190);
		var numberOfItems = 3;
		jQuery(".footer-carousel-container .next").unbind('click touchend');
		jQuery(".footer-carousel-container .prev").unbind('click touchend');
		jQuery(".footer-carousel").jCarouselLite({
			btnNext: ".footer-carousel-container .next",
			btnPrev: ".footer-carousel-container .prev",
			speed: 350,
			easing: 'easeOutQuad',
			visible:numberOfItems,
			circular: false,
			scroll:1,
			start:0
		});
		
	});
	// Runs function once
	jQuery(window).resize();
		
	jQuery("#right-nav").hover(function() {
	  jQuery("#right-nav .right-arrow").toggleClass('entered');
	});
	
	jQuery("#left-nav").hover(function() {
	  jQuery("#left-nav .left-arrow").toggleClass('entered');
	});

	jQuery(".contact-button").bind('click',function() {
		var container = jQuery(".contact-container");
		if (container.css('display') == "none"){
			openContact();
		}
		else {
			closeContact();
		}
	});
	
	var openContact = function() {
		var container = jQuery(".contact-container");
		container.css('opacity',0);
		container.css('display','block');
		container.animate({opacity:1},500);
		prevent_hide_contact=true;
	}

	var closeContact = function() {
		var container = jQuery( ".contact-container" );
		container.animate({opacity:0},
			{
				duration:500,
				complete:function() {
					container.css('display','none');
				}
			}
		);
	}
	
	var prevent_hide_contact = false;
	
	jQuery('.contact-content').hover(function(){ 
        prevent_hide_contact=true; 
    }, function(){ 
        prevent_hide_contact=false; 
    });

	jQuery('#footer').hover(function(){ 
        prevent_hide_contact=true; 
    }, function(){ 
        prevent_hide_contact=false; 
    });
	
	jQuery(".contact-container").bind('click', function() {
		if (!prevent_hide_contact && (jQuery( ".contact-container" ).css('display') != "none")) closeContact();
	});
	
	
	
	

		jQuery(".about-button").bind('click',function() {
		var container = jQuery(".about-container");
		if (container.css('display') == "none"){
			openAbout();
		}
		else {
			closeAbout();
		}
	});
	
	var openAbout = function() {
		var container = jQuery(".about-container");
		container.css('opacity',0);
		container.css('display','block');
		container.animate({opacity:1},500);
		prevent_hide_about=true;
	}

	var closeAbout = function() {
		var container = jQuery( ".about-container" );
		container.animate({opacity:0},
			{
				duration:500,
				complete:function() {
					container.css('display','none');
				}
			}
		);
	}
	
	var prevent_hide_about = false;
	
	jQuery('.about-content').hover(function(){ 
        prevent_hide_about=true; 
    }, function(){ 
        prevent_hide_about=false; 
    });

	jQuery('#footer').hover(function(){ 
        prevent_hide_about=true; 
    }, function(){ 
        prevent_hide_about=false; 
    });
	
	jQuery(".about-container").bind('click', function() {
		if (!prevent_hide_about && (jQuery( ".about-container" ).css('display') != "none")) closeAbout();
	});
	
	
	/*
	// Create Ajax Pagination
	jQuery("#right-nav").hover(function() {
		jQuery(this).addClass('show');
	},
	function() {
		jQuery(this).removeClass('show');
	});
	
	jQuery("#left-nav").hover(function() {
		jQuery(this).addClass('show');
	},
	function() {
		jQuery(this).removeClass('show');
	});

	jQuery('.pagination').bind('click touchend', function(event) {
		var leftlink = "http://podium/?p=8";
		jQuery('#main-right').load(leftlink+' #main');
		jQuery('#main').animate({left:"-100%",right:"100%"},1000);
		jQuery('#main-right').animate({left:0,right:0},1000);
	});
	*/
	
	// selects text when clicking on a form input box
	jQuery("input").focus(function(){
		if(this.value == this.defaultValue){
			this.select();
		}
	});
	jQuery("input").mouseup(function(e){
		e.preventDefault();
	});
	
	// IOS orientation detection
	window.onorientationchange = function() {
		var orientation = window.orientation;
		
		switch(orientation) {
			case 0:
				 break;
			case 90: 
				 break;
			case -90: 
				 break;
			case 180: 
				 break;
		}
	}
		
});
