/* Author: 

*/
/**********************
	=Document ready
**********************/
$(function() {
	$("#navprimary").menu();
	
	if( !$('html').hasClass('cssanimations') ){
		if ($("#splashscreen").length) {
			$("#container").hide();
			$("#splashscreen").css('visibility','visible').css('opacity','1').css('z-index','100');
			setTimeout(function() {
				$("#splashscreen").fadeOut(500, function(){
					$('#container').fadeIn(500);
					$(this).css('visibility','hidden').css('opacity','0').css('z-index','0');
				});
			}, 2000);
		}
	}
	
	/* accordion */
	if($("#accordion").length) $("#accordion").accordion({ autoHeight: false,collapsible: true });
	$('#accordion .head').click(function() {
		$(this).next().toggle('slow');
		return false;
	}).next().hide();
	
	/* validate form */
	if($("form[name=frmLogin]").length){	
		$("form[name=frmLogin]").validate();	
	}

	if($("form[name=frmOrder]").length){	
		$("form[name=frmOrder]").validate();	
	}	

	
	$("a.fancylink").fancybox();
	
	//Fade in content
	if ($("html").hasClass("opacity") && !$("html").hasClass("cssanimations")) $("#container").fadeTo(500, 1);
});


/**********************
		=Menu
**********************/
(function( $ ){
	var settings = { speed: 100, active: 2.5, decreaseBy: 0.5, smalest: 1, easing: "swing" };
	var element = '';
	var mouseOutTimer = '';
	var publicmethods = {
    	init: function( options ) {
			settings = $.extend(settings, options);
			element = this;
			$(this).find("a").mouseenter(function() { onMouseOver.call(this) });
			$(this).mouseleave(function() { onMouseOut.call(this); });
			if ($(this).find('.current a').length) setInactive.call($(this).find('.current a').get(0));
	 	}
 	};

	var onMouseOver = function() {
		clearTimeout(mouseOutTimer);
		$(this).stop().animate({fontSize: settings.active + "em"}, settings.speed, settings.easing);
		indexOthers.call(this)
	}

	var indexOthers = function() {
		var heightChange = 0;
		var siblings = $(element).find("a");
		var thisIndex = 0;
		for (var i = 0; i < siblings.length; i++) {
			if (this == siblings[i]) thisIndex = i;
		}
		for (var i = 0; i < siblings.length; i++) {
			var difference = (thisIndex - i < 0) ? (thisIndex - i) / -1 : thisIndex - i;
			var ammount = settings.active - settings.decreaseBy * difference;
			if (ammount < settings.smalest) ammount = settings.smalest;
			$(siblings[i]).stop().animate({fontSize:ammount + "em"}, settings.speed, settings.easing);
		}
	}

	var onMouseOut = function() {
		mouseOutTimer = setTimeout(function() { 
			if ($(element).find('.current a').length) setInactive.call($(element).find(".current a").get(0));
			else $(element).find('a').animate({fontSize: settings.smalest + "em"}, settings.speed, settings.easing);
		},500);
		//$(this).find("a").stop().animate({fontSize: settings.smalest + "em"}, settings.speed, settings.easing);
	}

	var setInactive = function() {
		$(this).stop().animate({fontSize: settings.active + "em"}, settings.speed, settings.easing);
		indexOthers.call(this);
	}

  	$.fn.menu = function( method ) {
	    if ( publicmethods[method] ) {
	      	return publicmethods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
	    } else if ( typeof method === 'object' || ! method ) {
	      	return publicmethods.init.apply( this, arguments );
	    }    
	};
	
	if($.browser.msie && $.browser.version.indexOf("6") != -1) {
		$("#search").click(function(){
			$("form input.text").focus();
		});
	}
})( jQuery );

/* Facebook share button */
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

