/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.navChange = function(){
	var content = document.getElementsByTagName('body');
	var navid = "#"+content[0].id+"_nav";
	$("#nav").css("visibility" ,"visible");
	$(navid).addClass('live_tab').removeClass('normal_tab');
}

this.imagePreview = function(target){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 60;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	
		
		
	/* END CONFIG */
	$(target+" .list").hover(function(e){
									  
		this.t = this.title;
		this.title = "";
		var offset = $(this).offset();
		var previewLeft = $(this).width()+10;
		var c = (this.t != "") ? "<br/>" + this.t : "";
		var clicked = false;
		$("div.preview_tip").hide();
		$(this).css("font-style", "italic")
				.css("text-decoration", "underline");
		$(this).next("div")
			.css("top", (offset.top - yOffset) + "px")
			.css("left",previewLeft+offset.left + "px")
			.fadeIn("slow");						
    }
	,
	function(){
								   
		this.title = this.t;
		$(this).css("font-style", "normal")
				.css("text-decoration", "none");
		if(clicked = false){
			$("div.preview_tip").hide("fast");
		}
    });	
	$(target+" .list").click(function(){
					$(this).next("div.preview_tip").show();
					clicked = true;
										});
	$(target+" p.close").click(function(){
					$("div.preview_tip").delay(300).hide("fast");
					clicked = false;
													}).hover(function(){
														$(this).css("text-decoration", "underline")}, function(){
															$(this).css("text-decoration", "none")});
		
};

this.tabSlide = function(){
	$('.tab').click(function() {
		var panels = this.parentNode;
		var panelwidth = panels.style.width;
		var panelwidthmin = (panelwidth.substr(0, panelwidth.indexOf('p')))-30;
		var paneloff = $(panels).offset();
		var taboff = $(this).offset();
		//alert(taboff.left);
		if(paneloff.left < 0){
			$(panels).animate({left: '+='+panelwidthmin}, 500);
//turn on and off the div that lays on top of hero image
			$('#float_tab').removeClass('hide').addClass('show');
		} else {
			$('#float_tab').removeClass('show').addClass('hide'); 
			$(panels).animate({left: '-='+panelwidthmin}, 500);
		};
													
	});
	
	$('#float_tab').click(
		function(){					
				$('#pack_panel').animate({left: '-=612'}, 500);									
				$('#float_tab').removeClass('show').addClass('hide');
		});
}
//curios slideviewer popup functions for image expansion
this.panelslide = function(){
var orig_width;
	var div_offsets;
	var containdivs = "div.container div div";
	
	$('.larger').hover(
		
			function(){
//reset to orig width in case of error
			$(this).animate({'width': orig_width}, 1);
				
//set function vars
				var div_pos = $(this).offset();
				var div_pos_left = div_pos.left;
//update parent function vars with target div info
				div_offsets = $(this).children().attr('width');
				orig_width = $(this).css('width');


//check to see if this is the far right div
			var lastdiv = $(containdivs).last().attr('id');
			var thisdiv = $(this).attr('id');
			var right_offset = parseFloat(orig_width) - parseFloat(div_offsets);
			if(lastdiv == thisdiv)	{
			$(this).animate({'width': div_offsets}, 200).animate({'left': right_offset},200);
//If it is the last div, move all divs over the width of the last div's image
				$(containdivs).each(function(i)
								{
								$(this).delay(300).animate({'left': right_offset}, 200);
								});
			} else {
//animate width of target div
			$(this).animate({'width': div_offsets }, 200);
			}
				
			},
//On mouseleave, restore all Divs back to left:0px, and restore the target div back to orig_width
			function(){
				
				$(containdivs).each(function(i)
								{
								$(this).animate({left : '0px' }, 100);
								});
				$(this).animate({ width : orig_width}, 100);
			}
	//end hover function
	);
		
}

// starting the script on page load
$(document).ready(function(){
						 
	navChange();
	tabSlide();	
});
