/*  ================================
     Sitewide JavaScript
    ================================ */

	function menuLeave()
	{
		this.src = "images/" + this.getAttribute("thunder:item") + ".gif";
	}
	
	function menuEnter()
	{
		this.src = "images/" + this.getAttribute("thunder:item") + "-over.gif";
	}
	
	function clearImage()
	{
		this.src = "images/clear.gif";
	}

	function textEnter(e, t)
	{
		if(t==undefined) t = this;
		t.parentNode.style.backgroundImage = "url(images/field.gif)";
	}

	function textLeave(e, t)
	{
		if(t==undefined) t = this;
		if(t.value=="") t.parentNode.style.backgroundImage = "url(images/" + t.parentNode.getAttribute("thunder:item") + ".gif)";
	}

	function sitewidePageLoaded()
	{
		textLeave(0, $('.username').children()[0]);
		textLeave(0, $('.password').children()[0]);
		$('.username').children().focus(textEnter).blur(textLeave);
		$('.password').children().focus(textEnter).blur(textLeave);
		$('.menu-item').mouseenter(menuEnter).mouseleave(clearImage);
	}
	
	function showProduct()
	{
		var product = this.getAttribute("thunder:item");
		$('.product-preview').children('img').each(
			function(ei, el)
			{
				if(el.getAttribute('thunder:item')==product)
				{
					el.style.display="block";
				}
				else
				{
					el.style.display="none";
				}
			}
		);
	}
	
	///function called to open the traditional order form MODAL
	function openTraditional(){
	    var width = $(window).width()-50;
	    var height = $(window).height()-50;
	    var myBox = $(this).jBox().showWindow('<iframe src="/traditional-form.aspx" frameborder="0" height="' + height + '" width="' + width + '" ></iframe>', true);
//        myBox.close(); //will close it manually

	}
	function showImage(el){
	    var id = $(el).attr("id");
	    $(".product-preview").find('img').each(function(){
				$(this).attr("class","");
	    });
	    if($(".product-preview").find("#image_" + id)){
	        $(".product-preview").find("#image_" + id).attr("class","first");
	    }else{}
	}
	
	function describeProduct()
	{
		var d;
		d = document.createElement('strong');
		d.innerHTML = this.getAttribute('alt');
		$(this).parent().append(d);
	}
	
	function undescribeProduct()
	{
		$('.products-display').children('tbody').children('tr').children('td').children('a').children('strong').remove();
	}

/*  ================================
     Template 1 JavaScript
    ================================ */

	function template1Loaded()
	{
		sitewidePageLoaded();
		$('.home-navigation a img').mouseenter(menuEnter).mouseleave(menuLeave);
	}

	function template2Loaded()
	{
		sitewidePageLoaded();
	}
	
	function template3Loaded()
	{
		sitewidePageLoaded();
		$('.products-display').children('tbody').children('tr').children('td').children('a').children('img').mouseenter(describeProduct).mouseleave(undescribeProduct);
	}
	
	function template4Loaded()
	{
		sitewidePageLoaded();
		$('.product-sidebar').children('li').mouseenter(showProduct);
	}

	function template5Loaded()
	{
		sitewidePageLoaded();
	}

	function template6Loaded()
	{
		sitewidePageLoaded();
	}

var partyanimal = [];

partyanimal.onready = function () {




}
var paCss = {
    padding: 0,
    margin: 0,
    width: '30%',
    top: '40%',
    left: '35%',
    textAlign: 'center',
    color: '#000',
    border: '0px',
    backgroundColor: 'transparent',
    cursor: 'wait'
};
var paMessage = '<img src="/images/logo-single.png"/>';
var display;
var league;
var team;
var product;

partyanimal.clearBrowse = function () {
    if (league != null) {
        league.val('');
        team.val('');
        product.val('');
        display.html('');
       
    }
}

partyanimal.loadText = function (league) {
    var instruct = $("#instructions");
    if (league != '') {
        if ($("#" + league).length > 0) {

            instruct.html($("#" + league).html());

        }
    }
}

partyanimal.loadProduct = function (leagueid, teamid, productid) {
    
    display = $("#product-results");
    league = $('#' + leagueid);
    team = $('#' + teamid);
    product = $('#' + productid);

    if (league.val() != '' || team.val() != '' || product.val() != '') {
        partyanimal.loadText(league.val());
 
        $.blockUI({ css: paCss, message: paMessage });
        if (league.val() == 'Party Signs') { //we need to change term for searching
            $('#' + teamid + '>option:eq(0)').text('All Categories');
            
        } else {
            $('#' + teamid + '>option:eq(0)').text('All Teams');
        };
      
        $.ajax({
            type: "GET",
            url: '/product.ashx?league=' + league.val() + '&team=' + team.val() + '&product=' + product.val(),
            cache: false,
            success: function (xml) {
                display.html(xml);

            },
            complete: function () {

                $.unblockUI();
            }
        });

    }


}


$(document).ready(partyanimal.onready());

