/* ---------------------------- */
/* Image Rollovers
/* ---------------------------- */

$(window).bind('load', function() {
    var preload = new Array();
    $(".img-over").each(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "-on.$1");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});

$(document).ready(function() {
	$(".img-over").each(function() {
        if ($(this).attr("src").match(/-on\.(.+)$/i)) {
            $(this).removeClass("hover");
        }
    });
    $(".img-over").hover(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "-on.$1");
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/-on\.(.+)$/i, ".$1");
        $(this).attr("src", s);
	})
});

/* --------------------*/
/* Menu Dropdowns  
/* --------------------*/

$(document).ready(function() {
	$("ul.obs-menu").superfish({ 
        delay:       300,                            // one second delay on mouseout 
        animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
        speed:       'fast',                          // faster animation speed 
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false,                            // disable drop shadows 
        onBeforeShow:  function(){
			$(this).prev().css('color','#494949');
			$(this).prev().find('.changeMyArrow').attr('src','/skins/obs4/images/nav-arrow-down.png');
		},
		onHide:  function(){
			$(this).prev().css('color','#666');
			$(this).prev().find('.changeMyArrow').attr('src','/skins/obs4/images/nav-arrow.png');
		}
    });
});

/* ---------------------------- */
/* Left Nav Links
/* ---------------------------- */

$(document).ready(function() {
	$("#content-products-left ul li").click(function() {
        var thisURL = $(this).children()[0];
		location.href = thisURL;
    });
});


/* ---------------------------- */
/* Load Video
/* ---------------------------- */

$(document).ready(function() {
	
	$.ajaxSetup ({ 
	    // Disable caching of AJAX responses */ 
	    cache: false 
	}); 
	$(".product-images2").overlay({
		mask: 'black',
		closeOnClick: true,
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find("#product-content-wrap2");
			var productID = this.getTrigger().attr("product2");
			var loadUrl = "/skins/obs4/includes/load-video.asp?video=" + productID;
			wrap.empty().load(loadUrl);
		},
		onClose: function() {
			var wrap = this.getOverlay().find("#product-content-wrap2");
			wrap.empty();
		}
	});
	$(".product-images").overlay({
		mask: 'black',
		closeOnClick: true,
		onBeforeLoad: function() {
			// var wrap = this.getOverlay().find("#product-content-wrap");
			$(this.getOverlay()).remove().appendTo("body");
			var wrap = this.getOverlay().find("#product-content-wrap");
			var productID = this.getTrigger().attr("product");
			var loadUrl = "/skins/obs4/includes/product-detail.asp?product_id=" + productID;
			wrap.load(loadUrl);
			$(".close").click(function () {
				$("#product-detail-window").hide();
				$("#exposeMask").hide();
			})
		},
		onClose: function() {
			var wrap = this.getOverlay().find("#product-content-wrap");
			wrap.empty();
		}
	});

});
