// JavaScript Document

// GLOBAL VARIABLES
var navCheck = 0;
var animating = false;

 $(document).ready(function(){
	//DD_belatedPNG.fix('.png_bg, .logo, .foubert, .feature, .shadow, .menu ul, div.shadow');						
   // FUNCTION TO LOAD DEFAULT AND FADE IN
   loadElements();
   // NAVIGATION MOUSEOVER DETECT
   $(".nav_link").mouseover(over);
   $("div.menu div").mouseover(over);
   $(".nav_link").mouseout(out);
   $("div.menu div").mouseout(out);	

   // GALLERY EFFECTS
   $(".smallimg").click(clickLink);
   
   // RESET ANY JS ON BROWSER 'BACK BUTTON'
   $(window).unload(function(){
  		//loadElements();
   });
      
});
 
function clickLink(event) {
	event.preventDefault();
	if (animating == false) {
		animating = true;
		var src = $(this).attr("href");
		 $("#swap_div").css('background-image', 'url(\''+src+'\')');
		 $("#swap_img").fadeOut(300, function() {
			 this.src = src;
			 $(this).show();
			 animating = false;
		 });
	}
}

function over() {
	if($(this).attr('class') == 'nav_link') {
		var menuID = '.' + $(this).attr("id");
		var linkID = this;
	} else {
		var linkID = '#' + $(this).attr("class");
		var menuID = this;
	}
	//alert($(menuID).attr("class")+' '+linkID);
	$(menuID).css('display', 'block');	
	$(linkID).stop().animate({opacity: 1}, 100, 'easeOutCubic');
	$(menuID).stop().animate({opacity: 1}, 500, 'easeInCubic');
}

function out() {
	if($(this).attr('class') == 'nav_link') {
		var menuID = '.' + $(this).attr("id");
		var linkID = this;
	} else {
		var linkID = '#' + $(this).attr("class");
		var menuID = this;
	}
	$(linkID).stop().animate({opacity: 0}, 500, 'easeOutCubic');
	$(menuID).stop().animate({opacity: 0}, 500, 'easeOutCubic', function() {
		$(menuID).css('display', 'none');															 
	});
}
 
function loadElements() {
   // CHANGE HTML CLASS IF JAVASCRIPT ENABLED
   $("body").removeClass("nojs").addClass("js");
   // SET OPACITY AND SHOW FADE ELEMENTS
   $(".nav_link").animate({opacity: 0}, 0);
   $("div.menu div").css('position', 'absolute');
   $("div.menu div").animate({opacity: 0}, 0);
   $(".nav_link").css('visibility', 'visible');
   $("div.menu div").css('display', 'none');

}

function searchGowns() {
	var search_text = $('#search_text').attr('value');
	$.post("code/search.php", { text: search_text }, function(theResponse){
		document.getElementById('results').innerHTML = theResponse;
		enableHover();
	});
}

function enableHover() {
	$('.editgown').hover(
		function() {
			$(this).stop().animate({"opacity": "0.6"}, "fast");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "fast");
		}
	);
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

$(function() {
	$('#scroll_container').jScrollHorizontalPane({scrollbarHeight: 14, dragMinWidth: 80, dragMaxWidth: 80, animateTo:false, animateInterval: 1 });
	if (pos != 'none') {
		$('#scroll_container')[0].scrollTo($('#'+pos).attr('rel'));
	}
});


/* IE PNG fix multiple filters */
/*(function ($) {
    if (!$) return;
    $.fn.extend({
        fixPNG: function(sizingMethod, forceBG) {
                if (!($.browser.msie)) return this;
                var emptyimg = "empty.gif"; //Path to empty 1x1px GIF goes here
                sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
                this.each(function() {
                        var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
                                imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
                                src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
                        this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
                        if (isImg) this.src = emptyimg;
                        else this.style.backgroundImage = "url(" + emptyimg + ")";
                });
                return this;
        }
    });
})(jQuery);*/

