/**
 * @author adam
 */

Cufon.replace('.font', { forceHitArea:  true }); 

$(document).ready(function() {
	
	// z-index fix
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	
	// Web Store Menu
	var webStoreHandle = $('li#web-store-handle');
	var webStoreMenu = $('#web-store-menu');
	webStoreHandle.hover(function() {
		$('select').hide(); /* ie 6 fix */
		webStoreMenu.show();
	}, function() {
		webStoreMenu.hide();
		$('select').show();
		resetItems();
	});
	
	// Web Store Menu Items
	var menuItem = $('.item');
	menuItem.click(function() {
		var height = $(this).css('height');
		if(height == "16px") {
			clearItems();
		}
		$(this).css('height', 'auto');
	});
	
	// Highlights
	var highlight = $('.highlight');
	var colors = new Array();
	colors['cats'] = "#F78F1E";
	colors['dogs'] = "#0054A4";
	colors['horses'] = "#AA41D5";
	
	highlight.hover(function() {
		var type = $(this).attr('id').split("-");
		var color = colors[type[1]];
		var theClass = $(this).children('.view-control').attr('class');
		
		if(theClass == "view-control") {
			$(this).children('.view-control').css('backgroundColor', color);
		}
	}, function() {
		var theClass = $(this).children('.view-control').attr('class');
		
		if(theClass == "view-control") {
			$(this).children('.view-control').css('backgroundColor', '#00746B');
		}
	});
	
	// hide options
	var viewOptions = $('#options-control');
	viewOptions.show().html("- Hide Options").click(function() {
		
		var theClass = $(this).attr('class');

		$('#highlights-inner').toggle();
		
		if(theClass == "vis") {
			$(this).html("- Show Options");
			$(this).attr('class', '');
			//$('#products_holder').css('marginTop', '140px');
			$('#basket').hide();
		} else {
			$(this).html("- Hide Options");
			$(this).attr('class', 'vis');
			//$('#products_holder').css('marginTop', '20px');
			$('#basket').show();
		}
	});
	
	// brand select
	var bsel = $('select[name=brand_select]').change(function() {
		var value = $(this).val();
		var id = $(this).attr('id').split("#");

		if(value !== "#") {
			if(value == "all") {
				window.location = REL_ROOT+"store/"+id[0]+"/"+id[1];
			} else {
				window.location = REL_ROOT+"store/"+id[0]+"/brands/"+value+"?sub="+id[1];
			}
		}
	});
	
});

function clearItems() {
	$('.item').each(function() {
		$(this).css("height", "16px");
	});
}

function resetItems() {
	clearItems();
	$('#web-store-menu #cat').css('height', 'auto');
}


