$(document).ready(function() {
	
	$('#pageSplash img').fadeIn(4000, function () {
    	$('#pageSplash img').fadeOut(2000, function () {
    		//resizeImage();
    		$('#pageSplash').fadeOut(1000, function () {
	    		//end animation chain;
	    	});
    	});     
    });

	$('.share-wrapper').hover(function(){
		$('ul.share').toggleClass('display');  
    });

	Shadowbox.init({
		onOpen: sbOpened,
		onClose: sbClosed
	});
	
	function sbOpened(){
		$('.jcarousel-prev').fadeOut();  
		$('.jcarousel-next').fadeOut();  
	}

	function sbClosed(){
		$('.jcarousel-prev').fadeIn();  
		$('.jcarousel-next').fadeIn();  
	}	

	$('.itemInfo').click(function() {  
		$(this).parent().parent().parent().parent().find('.infoBox').fadeIn("slow");  
	});
	
	$('.jcarousel-next').click(function() {  
		$('.infoBox').fadeOut("slow");  
	});
	
	$('.jcarousel-prev').click(function() {  
		$('.infoBox').fadeOut("slow");  
	});
	
	/*$('.infoClose').click(function() {
		$(this).parent().parent().parent().parent().find('.infoBox').fadeOut("slow");    
	});*/
	
		
	//code for the animation of the collections link in the bottom menu
	var collectionTransition = false;
	$('#menuCollection').click(function() {
		if(!collectionTransition){
			collectionTransition = true;
			var origWidth = $('#collectionli').width();
			if(!$('.menuSub').hasClass('shown')){ 
				$('#collectionli').animate({
				    width: origWidth+$('.menuSub').width()+7+'px',
				  }, 500, function() {
				    $('.menuSub').toggleClass('shown');
					$('.menuSub').animate({
					    opacity: 1.0,
					  }, 500, function() {
					    // Animation complete.
					    collectionTransition = false;
					});
				  });
			}else{ 
				$('.menuSub').animate({
				    opacity: 0,
				  }, 500, function() {
				    $('#collectionli').animate({
					    width: origWidth-$('.menuSub').width()-7+'px',
					  }, 500, function() {
					    // Animation complete.
					    collectionTransition = false;
					  });
					$('.menuSub').toggleClass('shown');
				});
			}
		}
	});  
		
	//chcks for keys pressed
	$(document).keyup(function(e) {
		if(!Shadowbox.isOpen()){
			 var code = (e.keyCode ? e.keyCode : e.which);
			 if(code == 39) { //right key
			   //trigger the next button
			   $('.jcarousel-next').click();
			 }else if(code == 37) { //left key
			   //trigger the prev button
			   $('.jcarousel-prev').click();
			 }
		}
	});
});

SmartAjax_load('/smartajax/', function(){
	SmartAjax.isDebug = false;
	SmartAjax.setOptions({
		cache: true,
		reload: false,
		containers:
		[
			{selector: '#content'}
		],
		
		before: function()
		{
			$('#loading').show();
			
			SmartAjax.proceed();
		},
		success: function()
		{
			$('#contentContainer').fadeOut(500, SmartAjax.proceed);
		},
		done: function()
		{
			$('#loading').hide();
			$('#contentContainer').fadeIn(500);
		}
	});
	
	SmartAjax.bind('a:not(#sb-nav-close)');
	SmartAjax.bindForms('form');
}, true);


(function($){$.fn.clearFields=function(m){var y="oldValue";var z="changed";var t="true";var i="input[type=";var j="text]";var c="textarea";var v="password]";var a={'selector':'*','textFields':true,'textAreas':true,'passwordFields':true};var b={c:function(e){if(e.val().trim()==""){e.val(e.attr(y)).removeAttr(y).removeAttr(z);}else{e.attr(z,t);}},d:function(e){if(e.attr(z)!=t){e.attr(y,e.val()).val("");}},k:function(e){if(g!="*"){e=e.filter(g);}e.focus(function(){b.d($(this));}).blur(function(){b.c($(this));});}};var g;return this.each(function(){if(c){a=$.extend(a,m);}var d=a.textFields;var e=a.textAreas;var f=a.passwordFields;if(!(d||e||f)){return;}g=a.selector;if(d){b.k($(this).find(i+j));}if(f){b.k($(this).find(i+v));}if(e){b.k($(this).find(c));}});};})(jQuery);

$(document).ready(function() {
	$("#contact").clearFields();
});
