// JavaScript Document
$(document).ready(function(){

// Description panels expand/contract
$("#panel, .panel").toggle(function(){
	if( this.id == "panel" ){ var height_is = "195px"; }
	else{ var height_is = "195px"; }
	$(this).animate({ height: height_is	}, 800, "easeOutQuint");
	$(this).find('h2 a').addClass('act');
	$(this).css('cursor','pointer');
},function(){
	if( this.id == "panel" ){ var height_is = "32px"; }
	else{ var height_is = "32px"; }
	$(this).animate({ height: height_is }, 500, "easeOutQuint");
	$(this).find('h2 a').removeClass('act');
});

// ScrollTo functions
jQuery(function( $ ){
					 
// Borrowed from jQuery easing plugin http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};
	$('a.back').click(function(){
		$(this).parents('div.pane').scrollTo( 0, 800, { queue:true } );
		$(this).parents('div.section').find('span.message').text( this.title );
		return false;
	});

// Just for the example, to stop the click on the links.
	$('ul.links').click(function(e){
		e.preventDefault();
		var link = e.target;
		link.blur();
		if( link.title )
			$(this).parent().find('span.message').text(link.title);
	});

// By default, the scroll is only done vertically ('y'), change it to both.
$.scrollTo.defaults.axis = 'y'; 			

// This one is important, many browsers don't reset scroll on refreshes
$('div.content').scrollTo( 0 );// reset all scrollable panes to (0,0)
$.scrollTo( 0 );// reset the screen to (0,0)

// Target examples bindings
var $paneTarget = $('#pages');			

$('.top').click(function(){
	$paneTarget.stop().scrollTo( '0px', 800 );
});
$('#top').click(function(){
	$paneTarget.stop().scrollTo( '0px', 800 );
});
$('.about').click(function(){
	$paneTarget.stop().scrollTo( '409px', 450);
});
$('.print-work').click(function(){
	$paneTarget.stop().scrollTo( '818px', 450);
});
$('.web-work').click(function(){
	$paneTarget.stop().scrollTo( '1227px', 450);
});
$('.contact').click(function(){
	$paneTarget.stop().scrollTo( '1636px', 450);
});
$('#options-onAfter').click(function(){
	reset_o(); $paneOptions.scrollTo( 'li:eq(15)', 2000, { 
		onAfter:function(){
			$('#options-message').text('Got there!');
		}
	});
});
$('#options-onAfterFirst').click(function(){ // onAfterFirst exists only when queuing
	reset_o(); $paneOptions.scrollTo( 'li:eq(15)', 800, { 
		queue:true,
		onAfterFirst:function(){
			$('#options-message').text('Got there horizontally!');
		},
		onAfter:function(){
			$('#options-message').text('Got there vertically!');
		}
	});
});
});

// Remove link background images since we're re-doing the hover interaction below 
// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
// We also want to only remove the image on non-selected nav items, so this is a bit more complicated
$(".nav").children("li").each(function() {
var current = "nav current-" + ($(this).attr("class"));
var parentClass = $(".nav").attr("class");
if (parentClass != current) {
	$(this).children("a").css({backgroundImage:"none"});
}
});	


// Create events for each nav item
attachNavEvents(".nav", "home");
attachNavEvents(".nav", "about");
attachNavEvents(".nav", "print");
attachNavEvents(".nav", "web");
attachNavEvents(".nav", "contact");


function attachNavEvents(parent, myClass) {
$(parent + " ." + myClass).mouseover(function() {
	$(this).append('<div class="nav-' + myClass + 
	'"></div>');
	$("div.nav-" + myClass).css({display:"none"}) 
	.fadeIn(100);
}).mouseout(function() {
	// fade out & destroy pseudo-link
	$("div.nav-" + myClass).fadeOut(200, function() {
		$(this).remove();
	});
	
});
}

// Generates tab pop-up for navigation
generateSprites(".nav", "current-", true, 150, "animate");


// Easy Slider 1.5 - jQuery plugin
//	written by Alen Grakalic	
//	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
//
//	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
//	Dual licensed under the MIT (MIT-LICENSE.txt)
//	and GPL (GPL-LICENSE.txt) licenses.
//
//	Built for jQuery library
//	http://jquery.com

(function($) {

$.fn.easySlider = function(options){
  
// Default configuration properties
	var defaults = {			
		prevId: 		'prevBtn',
		prevText: 		'Previous',
		nextId: 		'nextBtn',	
		nextText: 		'Next',
		controlsShow:	true,
		controlsBefore:	'',
		controlsAfter:	'',	
		controlsFade:	true,
		firstId: 		'firstBtn',
		firstText: 		'First',
		firstShow:		false,
		lastId: 		'lastBtn',	
		lastText: 		'Last',
		lastShow:		false,				
		vertical:		false,
		speed: 			800,
		auto:			false,
		pause:			2000,
		continuous:		false
	}; 
	
	var options = $.extend(defaults, options);  
			
	this.each(function() {  
		var obj = $(this); 				
		var s = $("li", obj).length;
		var w = $("li", obj).width(); 
		var h = $("li", obj).height(); 
		obj.width(w); 
		obj.height(h); 
		obj.css("overflow","hidden");
		var ts = s-1;
		var t = 0;
		$("ul", obj).css('width',s*w);			
		if(!options.vertical) $("li", obj).css('float','left');
		
		if(options.controlsShow){
			var html = options.controlsBefore;
			if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
			html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
			html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
			if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
			html += options.controlsAfter;						
			$(obj).after(html);										
		};
	
		$("a","#"+options.nextId).click(function(){		
			animate("next",true);
		});
		$("a","#"+options.prevId).click(function(){		
			animate("prev",true);				
		});	
		$("a","#"+options.firstId).click(function(){		
			animate("first",true);
		});				
		$("a","#"+options.lastId).click(function(){		
			animate("last",true);				
		});		
		
		function animate(dir,clicked){
			var ot = t;				
			switch(dir){
				case "next":
					t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;						
					break; 
				case "prev":
					t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
					break; 
				case "first":
					t = 0;
					break; 
				case "last":
					t = ts;
					break; 
				default:
					break; 
			};	
			
			var diff = Math.abs(ot-t);
			var speed = diff*options.speed;						
			if(!options.vertical) {
				p = (t*w*-1);
				$("ul",obj).animate(
					{ marginLeft: p }, 
					speed
				);				
			} else {
				p = (t*h*-1);
				$("ul",obj).animate(
					{ marginTop: p }, 
					speed
				);					
			};
			
			if(!options.continuous && options.controlsFade){					
				if(t==ts){
					$("a","#"+options.nextId).hide();
					$("a","#"+options.lastId).hide();
				} else {
					$("a","#"+options.nextId).show();
					$("a","#"+options.lastId).show();					
				};
				if(t==0){
					$("a","#"+options.prevId).hide();
					$("a","#"+options.firstId).hide();
				} else {
					$("a","#"+options.prevId).show();
					$("a","#"+options.firstId).show();
				};					
			};				
			
			if(clicked) clearTimeout(timeout);
			if(options.auto && dir=="next" && !clicked){;
				timeout = setTimeout(function(){
					animate("next",false);
				},diff*options.speed+options.pause);
			};
			
		};
		// init
		var timeout;
		if(options.auto){;
			timeout = setTimeout(function(){
				animate("next",false);
			},options.pause);
		};		
	
		if(!options.continuous && options.controlsFade){					
			$("a","#"+options.prevId).hide();
			$("a","#"+options.firstId).hide();				
		};				
		
	});
  
};
	
// This controls the works sliders	
	$("#slider").easySlider({
			controlsBefore:	'<p id="controls">',
			controlsAfter:	'</p>', 
			continuous: true,	
			prevId: 'prevBtn',
			nextId: 'nextBtn'
		});
		$("#slider2").easySlider({
			controlsBefore:	'<p id="controls2">',
			controlsAfter:	'</p>',
			continuous: true,		
			prevId: 'prevBtn2',
			nextId: 'nextBtn2'	
		});

// Show hide input copy
	$('#contact-form input:text, #contact-form textarea').focus(function() {
		if ($(this).hasClass("required") == false){
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
		}
	})
	.blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	
	});

// This controls the zoom on works images
$(function() {
	var options =
		{
			 zoomWidth: 300,
			 zoomHeight: 245,
			 position : 'left',
			 yOffset :0,
			 xOffset :-44,
			 title :true

		}
		$(".jqzoom").jqzoom(options);
});		
		
})(jQuery);

});// end document.ready

