// JavaScript Document

// image preloader
var preload = new Image();
var images = ["/images/bg/bg_body.jpg",
			  "/images/bg/bg_wrapper.jpg",
			 ];

for (i=0; i>images.length; i++) {
	preload.src=images[i];	
}

// cufon
Cufon.replace('h2, #sidebar #s1 h3, #sidebar #s2 h3, .staticpage #content h3, .newsletter #content h3, .checkout-1 #c3 h3, .checkout-1 #c4 h3, .login #c3 h3, .login #c4 h3');	

function pageLoad() {
	$("#productlist li:last").css("border","0").prev().css("border","0");
	Cufon.replace('h2, .checkout-1 #c3 h3, .checkout-1 #c4 h3, .paystatus #content h3, .login #c3 h3, .login #c4 h3, .myaccount ul.tabnav a');
}

// DOM READY
$(function() {
		   
	// header menu hover
	$("#logo ul li a").hover(function() {
		$(this).css("bottom","3px")								  
	},function() {
		$(this).css("bottom","0px")								  
	});
	$("#logo ul").hover(function() {
		$("<li id='choose'>Choose Event</li>").hide().appendTo("#logo ul").fadeIn();	
	},function() {
		$("li#choose").animate({"bottom": "15px", "opacity": 0}, function() {$(this).remove(); });
	});	
		   
	// searchbox onfocus / blur		   
	var searchbox = $("#search input.keyword");		   
	searchbox.focus(function() {
		if (searchbox.val() == "Keyword Search") {
			searchbox.val("");	
		}	
	});
	searchbox.blur(function() {
		if (searchbox.val() == "") {
			searchbox.val("Keyword Search");	
		}
	});
		
	// accordion
	var accordion = $("#menu ul li ul");
	accordion.hide();
	if (accordion.parent("li").hasClass("selected")) {
		accordion.show();	
	}
	
	// in stock sticker
	if ($("table.d-img img").hasClass("instock")) {
		$("img.instock").after("<div class='instock' />");
	};

	// tab navigation on detail page
    var tabs = $('div.tabs > div');
    
    $('div.tabs ul.tabnav a').click(function () {
        tabs.hide().filter(this.hash).show();
        $('div.tabs ul.tabnav a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();	
		
	// style fixes
	$("#menu > ul > li:last").css("border","0");
	$("#productlist li:last").css("border","0").prev().css("border","0");
	
	if ($("#resultsbar").length > 0 ) {
		$("#menu").css("min-height",($("#menu").height() - $("#resultsbar").height()));	
	}
	
	// modal
	$modal = $("#dialog");
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$modal.before("<div id=\"overlay\"><!--[if lte IE 6]><iframe></iframe><![endif]--></div>");
	$overlay = $("#overlay").css({ height: $(document).height(), opacity: "0.6" });

});  // END DOM READY

// modal
modal = function(type,text) {
	if (type == "thanks") {
		$("#dialog").css("background","url(/images/bg/bg_modal_thanks.png) top left no-repeat");
	} else if (type == "info") {
		$("#dialog").css("background","url(/images/bg/bg_modal_info.png) top left no-repeat");		
	}
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	if(text) $modal.find("p").html(text);
	var left = (windowW/2)-(modalW/2);
	var top = ((windowH/2)+$(window).scrollTop())-(modalH/2) - 22;
	$overlay.fadeIn(500);
	$("#overlay iframe").css({ top: top, left: left, width: $modal.outerWidth(), height: $modal.outerHeight() });
	
	$modal
	.css({ top: top, left: left })
	.fadeIn(500)
	.find("a[class='modal-close'], a[class='continue']")
	.click(function(e) {
		e.preventDefault();
		$modal.hide();
		$overlay.fadeOut(750);
	});
}

// modal: on window resize
$(window).resize(function() {
	$modal = $("#dialog");						  
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	var left = (windowW / 2) - (modalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (modalH / 2) - 22;
	if ($modal.is(":visible")) {
		$modal.animate({ top: top, left: left }, 500);
	}
});
/*
$(window).load(function() {
	if ($("#menu").height() > $("#content").height()) {
		$("#menu").height($("#content").height());
	} else {
		$("#content").height($("#menu").height());
	}				
});
*/