/*

Object Adjective, LLC
650 Delancey St.
Unit 220
San Francisco, CA 94107 US
415-756-5198
http://www.objectadjective.com
http://www.repeatpenguin.com
http://www.twitter.com/repeatpenguin

object-adjective.js

.......................................................*/


//Set ready state.......................................

$(document).ready(function() {

setupLightbox();
initNav();
enablePlaceholder();
setTooltip();

//app icon helper
$('.app-store').hover(
	  function () {
	    $(this).addClass('hover');
	  },
	  function () {
	    $(this).removeClass('hover');
	  }
	);

$('.app-store').click(function(event) {
        window.location = $('.app-button').attr("href");
        event.preventDefault();
});
    
});

//End Ready.............................................

/*------------- Set Hover for tooltip-----------------------------*/

function setTooltip(){
	$('.p-info').hover(
		function(){
			$(this).closest('.p-col-inner').find('.p-infobox').stop(true,true).fadeIn();
		},
		function(){
			$(this).closest('.p-col-inner').find('.p-infobox').stop(true,true).fadeOut();
		}
	)
}



/*------------- Set Up Navigation -----------------------------*/

function initNav(){
	var current = $("nav").find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
				if ( current.length ) {
					current.parent().addClass("current");
				}
}



/*------------- Set Up Lightboxes -----------------------------*/

/* Setup Lightbox Trigger Links */
function setupLightbox(){
	$('body').append('<div id="overlay"></div>')
    $('.lightbox-trigger').click(function(event) {
        var el_show = $(this).attr("href");
        $(el_show).fadeIn('slow').find('.ghinda-video-play').click();
        event.preventDefault();
    popDiv();
    });
    $(".lightbox .close, #overlay").click(function(event){
		closePopDiv();
		event.preventDefault();
	});

}

  

/* Position and Event Handlers for Lightboxes */
function popDiv() {
	$('#overlay').show();
	getHeight();
	if($.browser.msie) {
	    $(".lightbox").css("top", document.documentElement.scrollTop + 50 + 'px');
	}
	else if($.browser.opera) {
	    $('.lightbox').css('top', document.body.scrollTop + 50 + 'px');
	}
	else {
	    $(".lightbox").css("top", window.pageYOffset + 50 + 'px');
	}

}


function closePopDiv(){
    $(".lightbox").fadeOut('slow').find('.ghinda-paused-button').click();
    $("#overlay").hide();
}




/* Overlay Set Up */
function getHeight(){
	if (parseInt(navigator.appVersion)>3) {
 		if($.browser.msie) {
  		wind = document.body.offsetWidth;
  		wind = document.body.offsetHeight;
 		}
		else {
  		wind = window.innerWidth;
  		wind = window.innerHeight;
 		}
	}
	var divh = document.getElementsByTagName('body')[0].offsetHeight;
	var lock = document.getElementById('overlay');
	if (divh >= wind){
	lock.style.height = divh+"px";
	}
	else {lock.style.height =wind +"px";}
}
    
/*------------- /Set Up Lightboxes -----------------------------*/


//Enable Modernizr.......................................

function enablePlaceholder(){

	if(!Modernizr.input.placeholder){
		$("input").each(
		function(){
			if($(this).val()=="" && $(this).attr("placeholder") != null){
				$(this).val($(this).attr("placeholder"));
			}
			if ($(this).attr("placeholder") != null) {  
				$(this).focus(function(){
					if($(this).val()==$(this).attr("placeholder")) $(this).val("");
				});
				$(this).blur(function(){
					if($(this).val()=="") $(this).val($(this).attr("placeholder"));
				});
			}
		});
	
	}



}
