$(document).ready(function(){
	$("#butterfly").hover(
		function(){
			$("#header").stop().animate({
				backgroundPosition: "(-1000px 0px)"
			}, 80000, 'linear');
		
		},
		function(){
		
		}
	);
	
	

	$("ul.nav ul ul").addClass("noshow");

	
	//work magic on nav dropdowns that are too long
	//var maxHeight = 0;
	
	$("#subheader .nav:last > li:last").addClass("last");
	$("#subheader .nav a[href='/shop/designer/']").parent().addClass("newSpring");
	$("#subheader .nav a[href='/shop/girls/']").parent().addClass("double")
		//find max height for grid
	/*
	.find("li").each(function(){
			if ($(this).height() > maxHeight){
				var maxHeight = $(this).height();
				alert(maxHeight);
			}
		 });
*/
	
		 
	//sitemap toggle
	$("a#sitemap_toggle").click(function(){
		$("ul#sitemap").slideToggle("normal");
		return false;
	});
	
	$("h1, h2").wrap("<div class='heading_bg'></div>");
	
	/*description image animations*/
	
	$(".description").each(function(){
		$(this).hover(
			function(){
				if( $(this).is(":has('.description_text p')") ) {
					var height = $(this).find(".description_text").height();
					$(this).find(".description_photo").stop().animate({bottom: height }, "slow")								   
				}
			},
			function(){
				$(this).find(".description_photo").stop().animate({bottom: "0"}, "slow")								   
			}	
		);
	});
	
	
	/*start sidebar animation */
	
	$("#sidebar_toggle").toggle(
		function(){
			$("#sidebar").animate({
				width: "239"
			});
			$("#sidebar_elements").animate({
				left: "0"
			});
			
			$("#sidebar_toggle").css(
				"background-position", "right bottom"
			);
			
			return false;
		},
		function(){
			$("#sidebar").animate({
				width: "26" 
			});
			$("#sidebar_elements").animate({
				left: "-214"
			});
			$("#sidebar_toggle").css(
				"background-position", "right top"
			);
			return false;
		}
	);
});

/*disable right click*/

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
    	alert("this content is protected")
        return false;
    });
});


(function($){
	
	if(!document.defaultView || !document.defaultView.getComputedStyle){
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
})(jQuery);

(function($) {
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			
			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);