/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// CUSTOM JS


$(document).ready(function() {
						
// $('#postPage .sociable').scrollFollow();
// alert('hi');

// external links
$('a').filter(function() {
    return this.hostname && this.hostname !== location.hostname;
  }).append(' <img src="http://latentmotion.com/wp-content/themes/barecity_1.5/images/external.png" alt="external link" border="0" style="border:0;"/>');			

$('body').append( $('<div style="display:none"><a href="http://www.latentmotion.com/graphics/design/portfolio/neurophysics-max.jpg" rel="shadowbox[Portfolio]"></a><a href="http://www.latentmotion.com/graphics/design/portfolio/iraq-max.gif" rel="shadowbox[Portfolio]"></a><a href="http://www.latentmotion.com/graphics/design/portfolio/ricardo-max.jpg" rel="shadowbox[Portfolio]"></a><a href="http://www.latentmotion.com/graphics/design/portfolio/prex-max.jpg" rel="shadowbox[Portfolio]"></a></div>'));
/*
		$("#portfolioLink").click(function () {
			Shadowbox.open({
				content:    'http://www.latentmotion.com/graphics/design/portfolio/lupovici-max.gif',
				title:      "Latent Motion Portfolio",
				player:     "img",
				gallery:	"Portfolio"
			});
			return false;
		});
*/



$("#contactLink").one("mouseover", function () { 
	$('#contact').prepend( $('<iframe src="/form.html" frameborder="0" scrolling="no" height="174px" width="100%" style="padding:0; margin:0;"></iframe>'));
	return false;
});
								  
$("#contactLink").click(function () { 


      $("#flipShell").slideDown();
	  return false;
    });
/*
$("#servicesLink").click(function () { 
	  $("#flipShell").flip({ 
			direction: 'tb', 
			speed: '10', 
			color: '#B34212' 
			}); 
    });
*/


			$('input[type="text"]').addClass("idleField");
       		$('input[type="text"]').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});





	$("#s").animate( { opacity: '.2' }, 0);
	
	$("#s").hover(
      function () {
            $(this).animate( { opacity: '.8' }, 400);
      }, 
      function () {
		  	$(this).animate( { opacity: '.2' }, 400);
	  }
    );

	$("#header img").animate( { opacity: '1' }, 0);
	
	$("#header img").hoverIntent(
      function () {
            $(this).fadeTo("slow", 0.0);
      }, 
      function () {
		  	$(this).fadeTo("slow", 1.0);
	  }
    );

	$("#logo").animate( { opacity: '0' }, 0);
	
	$("#logoM").hoverIntent(
      function () {
            $("this").animate( { opacity: '1' }, 1200);
            $("#logo").animate( { opacity: '1' }, 1200);
      }, 
      function () {
            $("this").animate( { opacity: '0' }, 1200);
		  	$("#logo").animate( { opacity: '0' }, 1200);
	  }
    );


	var origTop = 60;
	if ($(".breadcrumb").html() == null){
        origTop = 95;
    }

	$(window).scroll(function () { 
	   
       	scrollBump = jQuery(window).scrollTop();
       if (scrollBump > 200){
        $("body.singlePage .sociable, body.postPage .sociable").animate({"top": scrollBump - 100  + "px"}, {queue:false, duration:"slow"});
       }
       else {
       	$("body.singlePage .sociable, body.postPage .sociable").animate({"top": origTop  + "px"}, {queue:false, duration:"slow"});
       }
       
    });


});
		
		
		