$(document).ready(function() {
	$(".lightBox1 a").lightBox();
	$(".lightBox2 a").lightBox();
	$(".lightBox3 a").lightBox();
	$(".lightBox4 a").lightBox();
	$(".lightBox5 a").lightBox();
	$(".lightBox6 a").lightBox();
	$(".lightBox7 a").lightBox();
	$(".lightBox8 a").lightBox();
	$(".lightBox9 a").lightBox();
	$(".lightBox10 a").lightBox();
	$(".lightBox11 a").lightBox();
	$("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag
	$("#topnav li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
		$(this).find("span").show().html(linkText); //Add the text in the <span> tag
	}); 
	$("#topnav li").css({opacity: "1"}); 
	$("#topnav li").hover(function() {	//On hover...
		$(this).find("span").stop().animate({
			marginTop: "-70" //Find the <span> tag and move it up 70 pixels
		}, 250);
		$("#topnav li a").animate({
			backgroundColor:"#4E1402"
		}, 400);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			marginTop: "0" //Move the <span> back to its original state (0px)
		}, 250);
		$(this).animate({
			opacity: "1"
		}, 400);
	});
	
	$(".label_design").hover(function() {
		$(this).animate({
			opacity: .7 
		}, 250);
	} , function() { //On hover out...
		$(this).animate({
			opacity: 1
		}, 250);
	});
	
	$("a #footer").hover(function() {
		$(this).animate({
			bottom: "1.5em" 
		}, 250);
	} , function() { //On hover out...
		$(this).animate({
			bottom: "1em"
		}, 250);
	});
	
	$(".contact_boxes").hover(function() {
		$(this).animate({
			opacity: .5
		}, 250);
	} , function() { //On hover out...
		$(this).animate({
			opacity: 1
		}, 250);
	}); 
	
	$("a #ok").hover(function() {
		$(this).animate({
			marginLeft: "14px"
		}, 250);
	} , function() { //On hover out...
		$(this).animate({
			marginLeft: "2px"
		}, 250);
	}); 
	$('.over_image_label').css({opacity: "0"});
    $('.work_explanation').css({opacity: "0"});
	$(".work a").hover(function() { 
		$(this).find(".over_image_label").animate({
			opacity: ".8" 
		}, 300);
		
	} , function() { //On hover out...
		$(this).find(".over_image_label").animate({
		opacity: "0" 
		}, 300);	
	});
	
	/*$(".work").hover(function() { 
		$(this).find("img").animate({
			marginLeft: "11em",
		}, 300);
		$(this).find(".work_explanation").animate({
		   marginLeft:"47.5em",
		   opacity: "1"
		}, 300);	
		$(this).find(".work_station").animate({
		   backgroundPosition: "0px 15px"
		}, 300);	
		
	} , function() { //On hover out...
		$(this).find("img").animate({
			marginLeft: "10.3em"
		}, 300);
		$(this).find(".work_explanation").animate({
		   opacity: "0",
		   marginLeft:"50em"
		}, 300);
		$(this).find(".work_station").animate({
		   backgroundPosition: "0px 75px"
		}, 300);
	});*/
	
	
	$(".work").bind("mouseenter",function() { 
		$(this).find("img").animate({
			marginLeft: "11em",
		}, 300);
		$(this).find(".work_explanation").animate({
		   marginLeft:"47.5em",
		   opacity: "1"
		}, 300);	
	});

	$(".work").bind("mouseleave",function() { 
		$(this).find("img").animate({
			marginLeft: "10.3em"
		}, 300);
		$(this).find(".work_explanation").animate({
		   opacity: "0",
		   marginLeft:"50em"
		}, 300);
	});
	
});

(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			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);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	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;
		}
		//return;
		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);
