/**
* 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);


$(document).ready(function() {	

	
	// Preload Images
    var img = new Image();
    $(img).load(function () {
     //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
     $('#loader').hide();
    }).error(function () {
    // notify the user that the image could not be loaded
    }).attr('src', $('img:last').attr('src'));
    $('h2').show();    
	slideShow();
	$("#b_appetant img").hover(function () {
	$("#b_appetant img").attr( 'src' , 'style/images/b_appetant_.jpg');
	},function () {
	$("#b_appetant img").attr( 'src' , 'style/images/b_appetant.jpg');
	});
	$("#b_dystopop img").hover(function () {
	$("#b_dystopop img").attr( 'src' , 'style/images/b_dystopop_.jpg');
	},function () {
	$("#b_dystopop img").attr( 'src' , 'style/images/b_dystopop.jpg');
	});
	
	$("#b_talkbox img").hover(function () {
	$("#b_talkbox img").attr( 'src' , 'style/images/talkbox_.jpg');
	},function () {
	$("#b_talkbox img").attr( 'src' , 'style/images/talkbox.jpg');
	});
	
	$("#b_twitter img").hover(function () {
	$("#b_twitter img").attr( 'src' , 'style/images/twitter_.jpg');
	},function () {
	$("#b_twitter img").attr( 'src' , 'style/images/twitter.jpg');
	});
	
	var default_bubble_msg = $("#tooltip span").html();
	$('a.bubble').each(function(){
	$(this).attr('rel', $(this).attr('title')).removeAttr("title");
	});
	
	/*
	$('a.bubble').hover(function () {
	$("#tooltip span").html($(this).attr('rel'));
	$("#tooltip").animate({top: -34}, 340);
	},function () {
	 $("#tooltip span").html(default_bubble_msg);
	$("#tooltip").animate({top: -150}, 240); 
	});
	*/
	
	 if (document.images)
    {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "style/images/lifestream_bottom_.jpg";
         image_url[1] = "style/images/cv_.png";
      
       var i = 0;
       for(i=0; i<=3; i++) 
         preload_image_object.src = image_url[i];
         
    }
	
	$('a.bubble').hoverIntent({
				sensitivity: 3, 
				interval: 200, 
				over: makeTall, 
				timeout: 0, 
				out: makeShort
	});

	function makeTall(){ 
	$("#tooltip span").html($(this).attr('rel'));
	 $("#tooltip").animate({top: -34}, 340);
	 }
	function makeShort(){ $("#tooltip span").html(default_bubble_msg);
	$("#tooltip").animate({top: -150}, 240);}

	
	
	
	
	
	
	
	$("#next img").hover(function () {
	$("#next img").attr( 'src' , 'style/images/lifestream_bottom_.jpg');
	},function () {
	$("#next img").attr( 'src' , 'style/images/lifestream_bottom.jpg');
	});
	
	$("#next img").click(function () {
	nextt();
	$("#next img").attr( 'src' , 'style/images/lifestream_bottom__.jpg');
	setTimeout(function() { 
	  	$("#next img").attr( 'src' , 'style/images/lifestream_bottom_.jpg');
	  },200);
	});
	
	
	
	$('#twitter_update_list li:first').addClass('show');
	//Set the opacity of all images to 0
$('#twitter_update_list li').css({opacity: 0.0});

//Get the first image and display it (set it to full opacity)
$('#twitter_update_list li:first').css({opacity: 1.0});

//Call the gallery function to run the slideshow
$('#twitter_div li').css('display', 'block');

$('#twitter_is_loading').hide();
	$('#b_talkbox').click(function() { window.location.href = 'mailto:%74%61%6C%6B%40%67%75%69%6C%6C%61%75%6D%65%72%6F%75%6B%68%6F%6D%6F%76%73%6B%79%2E%63%6F%6D' ; });
	
	
});


function nextt() {

//if no IMGs have the show class, grab the first image
var current = ($('#twitter_update_list li.show')?  $('#twitter_update_list li.show') : $('#twitter_update_list li:first'));

//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#twitter_update_list li:first') :current.next()) : $('#twitter_update_list li:first'));           

//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);

//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
}

function slideShow() {

//Set the opacity of all images to 0
$('.marketing h2').css({opacity: 0.0});

//Get the first image and display it (set it to full opacity)
$('.marketing h2:first').css({opacity: 1.0});

//Call the gallery function to run the slideshow
setInterval('main_gallery()',8000); }


function main_gallery() {

//if no IMGs have the show class, grab the first image
var current = ($('.marketing h2.show')?  $('.marketing h2.show') : $('.marketing h2:first'));

//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.marketing h2:first') :current.next()) : $('.marketing h2:first'));           

//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);

//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');

}
