$(function(){
    var currentURL = window.location;
    /* Body Load */
    $("#navigation td").each(function(){$(".MainMenuItem_Over",this).css("width",eval($(this).width()-2));$(".MainMenuItem_Normal",this).css("width",eval($(this).width()-2));});
    $("#navigation td:last").each(function(){$(".MainMenuItem_Over",this).css("width",eval($(this).width()));$(".MainMenuItem_Normal",this).css("width",eval($(this).width()));});
    $(".MMDataCaptureForm_Table").vertTable();
    $(".flag_container").children(".image").css({opacity:0.7}).parent().hover(function(){ $(".image",this).stop().animate({opacity:1},250); },function(){ $(".image",this).stop().animate({opacity:0.7},250); });
    $(".flag_container:nth-child(3n)").css("margin-right","0px");
    $("#bookmarks li a").hide();
	$(".order_table").each(function(){
		$("tr:eq(0) td",this).addClass("table_header");
	});
	$("#dgBasket tr:first td").addClass("table_header");
	$(".random .testimonial").hide();
    $(".random .testimonial:eq("+Math.floor(Math.random()*$(".random .testimonial").length)+")").show();
	$(":checked").removeAttr("checked");
    
    //User Interaction
	$(".gallery .photo a").lightBox();
    $(".flag_container,.code_thumb").fullLink();
    $("#delicious").click(function(){ location.href="http://del.icio.us/post?url="+currentURL+"";return false; });
    $("#facebook").click(function(){ location.href="http://www.facebook.com/sharer.php?u="+currentURL+"";return false; });
    $("#stumble").click(function(){ location.href="http://www.stumbleupon.com/submit?url="+currentURL+"";return false; });
    $("#reddit").click(function(){ location.href="http://reddit.com/submit?url="+currentURL+"";return false; });
    $("#twitter").click(function(){ location.href="http://twitter.com/home?status=Currently reading "+currentURL+"";return false; });
    $("#print").click(function(){ window.print(); });
    $("#email").click(function(){ location.href="mailto:?subject=Ensign Flags&body="+currentURL+"";return false; });
    $("#twitter").click(function(){ location.href="http://twitter.com/home?status=Currently reading "+currentURL+"";return false; });
    $("#contact").click(function(){ location.href="http://www.ensignflags.com/contact-us";return false; });
    $("#bookmark").click(function(){
        var bookmark_url = window.location;
        if (window.sidebar) { window.sidebar.addPanel("Ensign Flags", bookmark_url,""); }
        else if (window.external) { window.external.AddFavorite(bookmark_url, "Ensign Flags"); }
        else if (window.opera) { return false; }
        else { alert("Unfortunately, this browser does not support the requested action, please bookmark this page manually."); }
    });
	$("#alphabet_nav .Phuse_SiteMap_UL:eq(0) > .Phuse_SiteMap_LI:gt(0)").hide();
		$("#alphabet_nav .Phuse_SiteMap_UL:eq(0) > .Phuse_SiteMap_LI").each(function(){ $("a:first",this).hide(); });
	$("#alphabet_nav #scroller span").live("click",function(){
		$("#alphabet_nav .Phuse_SiteMap_UL:eq(0) > .Phuse_SiteMap_LI").hide();
		$("#alphabet_nav .Phuse_SiteMap_UL:eq(0) > .Phuse_SiteMap_LI").each(function(){ $("a:first",this).hide(); });
		$("#alphabet_nav .Phuse_SiteMap_UL:eq(0) > .Phuse_SiteMap_LI > a:contains('"+$(this).text()+"')").parent().fadeIn();
	});
	$("#alphabet_nav #right").live("mouseover mouseout",function(event){
		if (event.type=="mouseover") {
			$("#alphabet_nav #scroller p").animate({"left":"-311px"},2000);
		} else {
			$("#alphabet_nav #scroller p").stop();
		}
	});
	$("#alphabet_nav #left").live("mouseover mouseout",function(event){
		if (event.type=="mouseover") {
			$("#alphabet_nav #scroller p").animate({"left":"0px"},2000);
		} else {
			$("#alphabet_nav #scroller p").stop();
		}
	});
});
