$(document).ready(function() {

    //Show correct item total in cart    
    $("#numItems").text( getItemCount() );

    loadSplashSide();

});


//////////////////////////////////////////////////////////
//
// Ack/Error Functions 
//
//////////////////////////////////////////////////////////

function showError()
{
   if(window.location.href.indexOf('error.html?') >= 0)
    {
	var which = window.location.href.substring(window.location.href.indexOf('?') + 1);
	switch(which)
	{
	case 'cart_add_item_error' :
	    $("#error").text('Cannot add to shopping bag - item not found.');
	    break;
	case '500' :
	    $("#error").text('500 Internal Server Error');
	    break;
	}
	
    }

}

function showAck()
{
    if(window.location.href.indexOf('ack.html?') >= 0)
    {
	var which = window.location.href.substring(window.location.href.indexOf('?') + 1);
	switch(which)
	{
	case 'order' :
	    $("#ack").text('Your order has been received by ZiGi.  Please check your email for confirmation and receipt.');
	    $.cookies.del("cart");
	    break;
	}
    }
}



//////////////////////////////////////////////////////////
//
// Cart Functions 
//
//////////////////////////////////////////////////////////

//Cart object a JSON array of the form:
// [
//   { upc : "upcCode1" , qty : "x" } , 
//   { upc : "upcCode2" , qty : "y" } , 
//   { upc : "upcCode3" , qty : "z" } , 
//   ...
// ]

//Cart cookie is stored as
// upcCode1###x!upcCode2###y!upcCode3###z


//Create a cookie from a cart object
function createCart(c)
{
    var now = new Date();
    var options = 
	{
	    expiresAt: now.setFullYear(now.getFullYear() + 1)
	};

    $.cookies.del("cart");

    if(!c) return;

    var cString = "";
    for(var i = 0; i < c.length; i++)
    {
	cString += c[i].upc + "###" + c[i].qty;
	if(i < c.length - 1 ) cString += "!";
    }
    if(cString != "") $.cookies.set("cart", cString, options);
}


//Return a cart object from the cookie
function getCart()
{
    var cString = $.cookies.get('cart');

    if(cString)
    {
	var cart = [];
	var cItems = [];
	if(cString.indexOf("!") < 0) cItems = [ cString ];
	else cItems = cString.split('!');
	for(var i = 0; i < cItems.length; i++)
	{
	    var thisItem = cItems[i].split("###");
	    cart.push({ upc : thisItem[0] , qty : thisItem[1] });
	}
	return cart;
    }

    else return [];
}


function addItem(upc, qty)
{
    //Check if upc is the the DB first
    $.ajax({
	url : "/cgi/item_lookup.cgi?" + upc , 
	success : function(d)
	{
	    var res = eval(d);
	    if(res.length > 0)
	    {
		var cart = getCart();
		//Check if this item is already in cart - if so, just update qty
		var currqty = isInCart(upc);
		if(currqty > 0)
		{
		    updateQty(upc, parseInt(currqty) + parseInt(qty));
		}
		else
		{
		    cart.push({ upc : upc , qty: qty });
		    createCart(cart);

		    //Show correct item total in cart
		    $("#numItems").text( getItemCount() );
		}
	    }
	    else
	    {
		//window.location="error.html?cart_add_item_error";
	    }
	},
	error: function(d)
	{
	    //window.location="error.html?500";
	}
    });
}


function getItemCount()
{
    var cart = getCart();
    return cart.length;
}


//Check if item is in cart- if so return the quanity, otherwise return 0
function isInCart(upc)
{
    var cart = getCart();

    for(var i = 0; i < cart.length; i++)
    {
        if(cart[i].upc == upc)
        {
	    return cart[i].qty;
	}
    }

    return 0;
}


function deleteItem(upc)
{
    var cart = getCart();

    for(var i = 0; i < cart.length; i++)
    {
	if(cart[i].upc == upc)
	{
	    cart.splice(i, 1);
	    createCart(cart);
	    
	    //Show correct item total in cart
	    $("#numItems").text( getItemCount() );
	}
    }
}


function updateQty(upc, qty)
{
    if(isNaN(parseInt(qty))) return false;

    var cart = getCart();

    for(var i = 0; i < cart.length; i++)
    {
	if(cart[i].upc == upc)
	{
	    cart[i].qty = parseInt(qty);
	    createCart(cart);
	    return true;
	}
    }

    return false;
}


function updateQtyInCart(upc, field, origqty)
{
    if(!updateQty(upc, field.value))
    {
	field.value = origqty;
    }
    else
    {
	viewCart();
    }
}



function viewCart()
{
    $("#cart").empty();
    $("#cartLoading").show();

    //Build a shopping cart
    var cart = getCart();

    //If nothing in cart exit early
    if(cart.length == 0)
    {
	$("#cartCallout").text("Your shopping bag is empty.");
	$("#cartLoading").hide();
	return;
    }

    //Get a list of items in cart
    var itemStr = ''
    for(var i = 0; i < cart.length; i++)
    {
	itemStr += cart[i].upc;
	if(i < cart.length -1)
	{
	    itemStr += '+';
	}
    }

    //Lookup info on them
    $.ajax({
	url : "/cgi/cart_lookup.cgi?" + itemStr , 
	success : function(d)
	{
	    var newcart = eval(d);

	    //Copy qty values into newcart from original cart object
	    for(var i = 0; i < newcart.length; i++)
	    {
		for(var j =0; j < cart.length; j++)
		{
		    if(cart[j].upc == newcart[i].upc)
		    {
			newcart[i].qty = cart[j].qty;
		    }
		}
	    }


	    //Paint cart based on newcart
	    var cartTable = '<table id="cartTable"><tr><th></th><th>Item</th><th>Color</th><th>Size</th><th>Qty.</th><th>Price</th><th></th></tr>';
	    var subTotal = 0;

	    for(var i = 0; i < newcart.length; i++)
            {
		cartTable += '<tr>' +
		    '<td><img class="cartThumb" src="images/shoes/thumbs/' + newcart[i].image + '" /></td>' +
		    '<td><strong>' + newcart[i].name + '</strong></td>' +
		    '<td>' + newcart[i].color + '</td>' +
		    '<td>' + newcart[i].size + '</td>' +
		    '<td>x <input class="qtyField" type="text" onChange="updateQtyInCart(\'' + newcart[i].upc + '\', this, \''+ newcart[i].qty +'\');" value="' + newcart[i].qty + '" /></td>' +
		    '<td>$' + formatPrice(newcart[i].price) + '</td>' +
		    '<td><a class="hoverLink" onclick="deleteItem(\'' + newcart[i].upc + '\'); viewCart();">Remove</a></td>' +
		    '</tr>';
		subTotal += parseFloat(newcart[i].price * newcart[i].qty);
	    }

	    if(B2B)
	    {
		subTotal = subTotal - (subTotal * DISCOUNT);
	    }

            cartTable += '<tr><td colspan="6"><div id="cartSubtotal">Subtotal: $' + formatPrice(subTotal) + '</div><div id="cartCheckout"><a href="checkout.html">Checkout &raquo;</a></div></td></tr></table>';

	    $("#cart").html(cartTable);
	    $("#cartLoading").hide();

	},
	error: function(d)
	{
	    window.location="error.html?500";
	}
    });
}


function formatPrice(p)
{
    p = p.toString();
    if(p.indexOf('.') < 0) return p + '.00';
    else
    {
	if(p.substring(p.indexOf('.')).length == 3) return p;
	else if(p.substring(p.indexOf('.')).length == 2) return p + '0';
	else if(p.substring(p.indexOf('.')).length == 1) return p + '00';
	else return(Math.round(p * 100) / 100);
    }
}




//////////////////////////////////////////////////////////
//
// Checkout Functions 
//
//////////////////////////////////////////////////////////

function initCheckout()
{
    changeStateOptions('bill');
    changeStateOptions('ship');
}


function sameInfo()
{
    if(document.checkout.same.checked == true)
    {
	document.checkout.ship_first.value = document.checkout.bill_first.value;
	document.checkout.ship_last.value = document.checkout.bill_last.value;
	document.checkout.ship_address1.value = document.checkout.bill_address1.value;
	document.checkout.ship_address2.value = document.checkout.bill_address2.value;
	document.checkout.ship_city.value = document.checkout.bill_city.value;
	document.checkout.ship_zip.value = document.checkout.bill_zip.value;
	document.checkout.ship_phone.value = document.checkout.bill_phone.value;
	document.checkout.ship_fax.value = document.checkout.bill_fax.value;
	document.checkout.ship_country.selectedIndex = document.checkout.bill_country.selectedIndex;
	changeStateOptions('ship');
	document.checkout.ship_state.selectedIndex = document.checkout.bill_state.selectedIndex;
    }
}

function changeStateOptions(which)
{
    //which should be either 'bill' or 'ship'
    if(which != 'bill' && which != 'ship') return;

    var country;
    if(which == 'bill') country = document.checkout.bill_country.options[document.checkout.bill_country.selectedIndex].value;
    else if(which == 'ship') country = document.checkout.ship_country.options[document.checkout.ship_country.selectedIndex].value;

    if(country == 'US' || country == 'CA')
    {
	$("#" + which + "_state_td").empty().append( $("#" + country + "_state_select").clone()[0] );
	$("#" + which + "_state_td select").attr('name', which + "_state");
    }

    else
    {
	$("#" + which + "_state_td").empty().append( $("#other_state_select").clone()[0] );
	$("#" + which + "_state_td select").attr('name', which + "_state");
    }
}


function validateForm() {
    var res = true;
    var why;

    if(getCart().length == 0)
    {
	alert("You haven't added any products to your shopping bag!");
	return false;
    }

    //Append cart cookie so we know which items this user purchased
    document.checkout.cart.value = $.cookies.get('cart');

    if(document.checkout.bill_first.value == '') { res = false; why = 'first name (billing)'; }
    else if(document.checkout.bill_last.value == '') { res = false; why = 'last name (billing)'; }
    else if(document.checkout.bill_address1.value == '') { res = false; why = 'address (billing)'; }
    else if(document.checkout.bill_city.value == '') { res = false; why = 'city (billing)'; }
    else if(document.checkout.bill_zip.value == '') { res = false; why = 'zip (billing)'; }
    else if(document.checkout.bill_phone.value == '') { res = false; why = 'phone (billing)'; }
    else if(document.checkout.email.value == '' || document.checkout.email.value.indexOf('@') < 0) { res = false; why = 'email'; }
    else if(document.checkout.bill_state.selectedIndex == 0 && (document.checkout.bill_country.selectedIndex == 1 || document.checkout.bill_country.selectedIndex == 2)) { res = false; why = 'state (billing)'; }
    else if(document.checkout.bill_country.selectedIndex == 0 || document.checkout.bill_country.selectedIndex == 3) { res = false; why = 'country (billing)'; }
    else if(document.checkout.ship_first.value == '') { res = false; why = 'first name (shipping)'; }
    else if(document.checkout.ship_last.value == '') { res = false; why = 'last name (shipping)'; }
    else if(document.checkout.ship_address1.value == '') { res = false; why = 'address (shipping)'; }
    else if(document.checkout.ship_city.value == '') { res = false; why = 'city (shipping)'; }
    else if(document.checkout.ship_zip.value == '') { res = false; why = 'zip (shipping)'; }
    else if(document.checkout.ship_phone.value == '') { res = false; why = 'phone (shipping)'; }
    else if(document.checkout.ship_state.selectedIndex == 0 && (document.checkout.ship_country.selectedIndex == 1 || document.checkout.ship_country.selectedIndex == 2)) { res = false; why = 'state (shipping)'; }
    else if(document.checkout.bill_country.selectedIndex == 0 || document.checkout.bill_country.selectedIndex == 3) { res = false; why = 'country (shipping)'; }
    else if(!document.checkout.cc_type[0].checked && !document.checkout.cc_type[1].checked && !document.checkout.cc_type[2].checked) { res = false; why = 'card type'; }
    else if(document.checkout.cc_num.value == '') { res = false; why = 'credit card number'; }
    else if(document.checkout.cv_num.value == '') { res = false; why = 'card verification number'; }
    
    if(!res) alert('You must enter your ' + why + '.');
    else document.checkout.submit();
}


//////////////////////////////////////////////////////////
//
// Login Functions 
//
//////////////////////////////////////////////////////////

function login()
{
    var username = $("#username").val();
    var password = $("#password").val();
    var dataString = 'username='+ username + '&password=' + password;

    $("#loginBtn").hide();
    $("#loginLoading").show();
    
    $.ajax({
	type: "POST",
	url: "/cgi/login.cgi",
	data: dataString,
	success: function(d)
	{
	    var key = d;
	    $.cookies.del("username");
	    $.cookies.del("key");

	    var now = new Date();
	    var options = 
		{
		    expiresAt: now.setFullYear(now.getFullYear() + 1)
		}
	    
	    $.cookies.set("username", username, options);
	    $.cookies.set("key", key, options);

	    $("#loginLoading").hide();
	    $("#loginResults").html('<span class="green">You have sucessfully logged in.</span>');
	    
	},
	error: function(d)
	{
	    $.cookies.del("username");
	    $.cookies.del("key");
	    $("#password").val('');
	    $("#loginBtn").show();
	    $("#loginLoading").hide();
	    $("#loginResults").html('<span class="red">Login error.</span>');
	}
    });  
}


//////////////////////////////////////////////////////////
//
// Product Page Functions 
//
//////////////////////////////////////////////////////////

var B2B = false;
var DISCOUNT = 0;

function checkB2B()
{
    var dataString = 'username='+ $.cookies.get('username') + '&key=' + $.cookies.get('key');
    
    $.ajax({
	type: "POST",
	url: "/cgi/b2b_check.cgi",
	data: dataString,
	success: function(d)
	{
	    DISCOUNT = d;
	    B2B = true;

	    if(window.location.href.indexOf('view-cart.html') >= 0)
	    {
		viewCart();
	    }
	    else
	    {
		loadB2BInfo();
	    }
	},
	error: function(d)
	{

	}
    });  
}


var PRODUCT;

function loadProductInfo()
{
    $.ajax({
	//NAME is a 'global' set in <body> (see /page_builder/products/includes/product.frm)
	url : "/cgi/name_lookup.cgi?" + NAME , 
	success : function(d)
	{
	    PRODUCT = eval( "(" + d + ")" );
	    populateColors();
	},
	error: function(d)
	{
	    
	}
    });

    //Setup the rollovers here too
    $("#controlImages img").hover(
	function()
	{
	    var which = $(this).attr("id").replace("pc-","");
	    $("#ps-" + which).show();
	} ,

	function()
	{
	    $(".prodHoverDetail").hide();
	}
    );
}

var B2B;

function loadB2BInfo()
{
    $.ajax({
	//STYLE is a 'global' set in <body> (see /page_builder/products/includes/product.frm)
	url : "/cgi/b2b_lookup.cgi?" + STYLE , 
	success : function(d)
	{
	    B2B = eval( "(" + d + ")" );
	    $("#b2b").html('Valid B2B Customer - Discount:' + DISCOUNT + '<br />');
	    var selString = '<select id="b2b_list">';
	    for(var i in B2B)
	    {
		selString += '<option value="' + B2B[i].upc + '">' + B2B[i].name + ' - ' + B2B[i].color + ' ' + B2B[i].size + '</option>';
	    }
	    selString += '</select>';
	    $("#b2b").append(selString + '<input type="button" value="Order B2B Case" onClick="addItem($(\'#b2b_list\').val(), 1);" />');
	},
	error: function(d)
	{
	    
	}
    });
}


function populateColors()
{
    $("#color").empty();
    $("#color").append('<option value="">Select a color...</option>');

    var colors = [];
    for(var i in PRODUCT)
    {
	if($.inArray(PRODUCT[i].color, colors) < 0)
	{
	    if(PRODUCT[i].color != null)
	    {
		colors.push(PRODUCT[i].color);
	    }
	}
    }

    for(var i = 0; i < colors.length; i++)
    {
	$("#color").append('<option value="' + colors[i] + '">' + colors[i] + '</option>');
    }

    $("#color").attr('disabled', false);
}


function populateSizes()
{
    $("#size").empty();
    $("#size").append('<option value="">Select a size...</option>');

    var sizes = [];
    for(var i in PRODUCT)
    {
	if($.inArray(PRODUCT[i].size, sizes) < 0)
	{
	    if(PRODUCT[i].size != null && PRODUCT[i].color == $("#color").val())
	    {
		sizes.push(PRODUCT[i].size);
	    }
	}
    }

    sizes.sort( 
	function(a, b)
	{
	    return (a-b); 
	}
    );
    
    for(var i = 0; i < sizes.length; i++)
    {
	$("#size").append('<option value="' + sizes[i] + '">' + sizes[i] + '</option>');
    }

    $("#size").attr('disabled', false);
}


function showPrice()
{
    $("#price").text('$' + getPrice());
}


function getPrice()
{
    for(var i in PRODUCT)
    {
	if(PRODUCT[i].size == $("#size").val() && PRODUCT[i].color == $("#color").val())
	{
	    if(B2B)
	    {
		return formatPrice( PRODUCT[i].price - (PRODUCT[i].price * DISCOUNT) )
	    }

	    else
	    {
		return formatPrice(PRODUCT[i].price);
	    }
	}
    }
}


function getUPC()
{
    for(var i in PRODUCT)
    {
	if(PRODUCT[i].size == $("#size").val() && PRODUCT[i].color == $("#color").val())
	{
	    return PRODUCT[i].upc;
	}
    }
}


function getB2BUPC()
{
    if(B2B)
    {
	for(var i in PRODUCT)
	{
	    if(PRODUCT[i].upc < 10000)
	    {
		return PRODUCT[i].upc;
	    }
	}
    }
}


var lastQty = 1;

function checkQty()
{
    if(isNaN(parseInt($("#qty").val()))) $("#qty").val(lastQty);
    else lastQty = $("#qty").val();
}


function addCurrentItem()
{
    if($("#color").val() == '') alert('Please select a color');
    else if($("#size").val() == '') alert('Please select a size');
    else addItem(getUPC(), $('#qty').val());
}



//////////////////////////////////////////////////////////
//
// Category Page Functions
//
//////////////////////////////////////////////////////////

var numPages = 1;
var currentPage = 1;

function loadPagination()
{
    //This function checks the number of item lists on a category page and sets up a pagination counter at the bottom
    //Counters here start at "1" to keep things simple (pages 1 ... n)

    numPages = $(".item_list").length;

    if(numPages > 1)
    {
	//Setup unique IDs
	$(".item_list").each( 
	    function(index)
	    {
		var num = index + 1;
		$(this).attr("id", "item_list_" + num);
	    }			     
	);

	//Create pagination links
	var code = '<a href="javascript:gotoPage(1);">&laquo;</a>';
	code += '<a href="javascript:gotoPage(currentPage - 1);">&lt;</a>';

	for(var i = 1; i <= numPages; i++)
	{
	    code += '<a href="javascript:gotoPage(' + i + ');">' + i + '</a>';
	}

	code += '<a href="javascript:gotoPage(currentPage + 1);">&gt;</a>';
	code += '<a href="javascript:gotoPage(numPages);">&raquo</a>';
	
	$("#pagination").html(code);
    }


}

function gotoPage(which)
{
    if(which > 0 && which <= numPages)
    {
	/*
	$("#item_list_" + currentPage).fadeOut(
	    'fast',
	    function()
	    {
		$("#item_list_" + which).fadeIn('fast');
		currentPage = which;
	    }
	);
        */

	//Fading too buggy here so KISS

	$("#item_list_" + currentPage).hide();
	$("#item_list_" + which).show();
	currentPage = which;
    }
}










//////////////////////////////////////////////////////////
//
// Splash / Banner Functions
//
//////////////////////////////////////////////////////////

function loadSplashCat(which)
{
    //Show the appropriate splash image for this category

    if(which != '1999-mens' &&
       which != 'handbags' &&
       which != 'apparel' &&
       which != 'accessories' &&
       which != 'kids' &&
       which != 'beach' &&
       which != 'best-sellers' &&
       which != 'booties' &&
       which != 'boots' &&
       which != 'clearance' &&
       which != 'dress' &&
       which != 'flats' &&
       which != 'platforms' &&
       which != 'pre-order' &&
       which != 'pumps' &&
       which != 'sales' &&
       which != 'sandals' &&
       which != 'slippers' &&
       which != 'sneakers' &&
       which != 'special-occasion' &&
       which != 'wedges' &&
       which != 'womens-shoes'
      )
    {
	which = 'default';
    }
    
    $("#splash_category").append('<img class="splash_category_img" src="images/splash/categories/' + which + '.jpg" />');

    //This crappy settimeout gives the images time to load - need to add a real preloader here someday
    setTimeout(
	function()
	{
	    $("#splash_category_loading").remove();
	    $(".splash_category_img").fadeIn();
	}, 1000
    );
}

function loadSplashSide()
{
    //Setup the rotating banner ads on the side of the page

    if($("#splash_side").length > 0)
    {
	//The only reason the display:none is inline here is because IE8 needs .splash_side_img declared as 'block' in the main CSS file
	//Otherwise the fades don't work.  Spectacular.
	$("#splash_side").append(
	    '<a href="grizzleex-breakout.html" style="display:none;" class="splash_side_img"><img src="images/splash/side1.jpg" /></a>' +
	    '<a href="1999-mens-breakout.html" style="display:none;"class="splash_side_img"><img src="images/splash/side2.jpg" /></a>' +
	    '<a href="zigi-girl-breakout.html" style="display:none;"class="splash_side_img"><img src="images/splash/side3.jpg" /></a>' +
	    '<a href="black-label-breakout.html" style="display:none;"class="splash_side_img"><img src="images/splash/side4.jpg" /></a>' +
	    '<a href="rock-and-candy-breakout.html" style="display:none;"class="splash_side_img"><img src="images/splash/side5.jpg" /></a>' +
	    '<a href="ziggies-breakout.html" style="display:none;"class="splash_side_img"><img src="images/splash/side6.jpg" /></a>'
	);

	//This crappy settimeout gives the images time to load - need to add a real preloader here someday
	setTimeout(
	    function()
	    {
		setInterval(rotateSplashSide, 5000);
		$("#splash_side_loading").remove();
		rotateSplashSide();
	    }, 1000
	);
    }
}

function rotateSplashSide()
{
    $(".splash_side_img:first").fadeOut(
	300, 
	function()
	{
	    $(".splash_side_img:first").remove().appendTo("#splash_side");
	    $(".splash_side_img:first").fadeIn(300);
	}
    );
}


var SplashSSImgWidth = 0;
function setupSplashSS()
{
    //Setup slideshow for mainpage splash

    var slideCount = $("#splash_slides img").length;
    SplashSSImgWidth = $("#splash_slides img:first").width();
    $("#splash_slides").width(slideCount * 682);
    setInterval(nextSplashSS, 7000);
}

function nextSplashSS()
{
    $("#splash_slides").animate(
	{
	    left: "-=" + SplashSSImgWidth
	} , 
	700, 
	"swing",
	function()
	{
	    $("#splash_slides img:first").remove().appendTo("#splash_slides");
	    $("#splash_slides").css("left", "0px");
	}
    );

}


//Behind the Scenes movie
function showBTS()
{
    $("#splash").fadeOut(
	function()
	{
	    $("#bts").fadeIn();
	}
    );
}

function hideBTS()
{
    $("#bts").fadeOut(
	function()
	{
	    $("#splash").fadeIn();
	}
    );
}


//Generic popup functions
function showPopup(which)
{
    $("#shade").show();
    $("#" + which + "_popup").fadeIn();
}

function hidePopup(which)
{
    $("#shade").hide();
    $("#" + which + "_popup").fadeOut();
}





//////////////////////////////////////////////////////////
//
// Breakout Page Functions
//
//////////////////////////////////////////////////////////

function breakout(which)
{
    //Each breakoutpage get styled slightly differently, so modify the existing design rather than making a bunch of manual pages

    if(which == 'zigi-girl')
    {
	$("#main").height('1080px');
	$("#wrapper").addClass('wrapper-zigi-girl');
	$("#sideNav").addClass('sideNav-zigi-girl');
	$("#brands").addClass('brands-zigi-girl').prepend('<div id="brandHighlight" class="HL-zigi-girl">ZiGi Girl</div>');
	$("#brands li a").addClass('brands-li-a-zigi-girl');
    }

    else if(which == 'black-label')
    {
	$("#main").height('1080px');
	$("#wrapper").addClass('wrapper-black-label');
	$("#brands").prepend('<div id="brandHighlight" class="HL-black-label">Black Label</div>');

	//Gotta reshift all the brand menus
	var brands = $("#brands li a").each(
	    function() 
	    {		     
		var oldpos = $(this).css('backgroundPosition');
		var newpos = oldpos.replace('0','-200');
		$(this).css('backgroundPosition', newpos);
	    }
	);

	//This stuff moved to bottom because IE chokes on the position shifting above and we end up with white text on white BG
	$("#sideNav").addClass('sideNav-black-label');
	$("#brands").addClass('brands-black-label');
	$("#brands li a").addClass('brands-li-a-black-label');
    }

    else if(which == 'rock-and-candy')
    {
	$("#main").height('1080px');
	$("#wrapper").addClass('wrapper-rock-and-candy');
	$("#sideNav").addClass('sideNav-rock-and-candy');
	$("#brands").addClass('brands-rock-and-candy').prepend('<div id="brandHighlight" class="HL-rock-and-candy">Rock & Candy</div>');
	$("#brands li a").addClass('brands-li-a-rock-and-candy');
    }

    else if(which == 'grizzleez')
    {
	$("#main").height('1080px');
	$("#wrapper").addClass('wrapper-grizzleez');
	$("#sideNav").addClass('sideNav-grizzleez');
	$("#brands").addClass('brands-grizzleez').prepend('<div id="brandHighlight" class="HL-grizzleez">Grizzleez</div>');
	$("#brands li a").addClass('brands-li-a-grizzleez');
	$("#categories").addClass('categories-grizzleez');
	$("#categories li a").addClass('categories-li-a-grizzleez');
    }

    else if(which == '1999-mens')
    {
	$("#main").height('1080px');
	$("#wrapper").addClass('wrapper-1999-mens');
	$("#sideNav").addClass('sideNav-1999-mens');
	$("#brands").addClass('brands-1999-mens').prepend('<div id="brandHighlight" class="HL-1999-mens">1999 Mens</div>');
	$("#brands li a").addClass('brands-li-a-1999-mens');
    }

    else if(which == 'ziggies')
    {
	$("#main").height('1080px');
	$("#wrapper").addClass('wrapper-ziggies');
	$("#sideNav").addClass('sideNav-ziggies');
	$("#brands").addClass('brands-ziggies').prepend('<div id="brandHighlight" class="HL-ziggies">1999 Mens</div>');
	$("#brands li a").addClass('brands-li-a-ziggies');

	//attach hover event
	$(".zba").hover(
	    function()
	    {
		$(".zbi").hide();
		var num = $(this).attr('id').substring(3);
		$("#zbi" + num).show();
	    },

	    function()
	    {
		$(".zbi").hide();
	    }
	);
	    
    }
}


function showBLLB()
{
    $("#black-label-slideshow").fadeIn();
    $("#bllb-prev").fadeIn();
    $("#bllb-next").fadeIn();
}

function nextBLLB()
{
    var currPos = parseInt($("#black-label-slides").css("left"));
    if(currPos <= -2340) return;
    else
    {
	$("#black-label-slides").stop(true,true).animate(
	    {
		left: "-=" + 780
	    } , 700, "swing"
	);
    }
}

function prevBLLB()
{
    var currPos = parseInt($("#black-label-slides").css("left"));
    if(currPos >= 0) return;
    else
    {
	$("#black-label-slides").stop(true,true).animate(
	    {
		left: "+=" + 780
	    } , 700, "swing"
	);
    }
}