﻿

jQuery(document).ready(function() {
  productSearch.Init();
});

var productSearch = {
	Init: function Init()
	{
		this.bodyElement = jQuery('.productSearch .body')[0];
		this.openHeight = jQuery(this.bodyElement).height();
		jQuery(this.bodyElement).css({ 'height': '0px', 'visibility': 'visible' });
		this.menuElement = jQuery('.productSearch .menu')[0];
		this.openMenuHeight = jQuery(this.menuElement).height();
		jQuery(this.menuElement).css({ 'height': '0px', 'visibility': 'visible' });

		this.isOpen = false;

		this.ajaxFrame = jQuery('.productMenuAjaxHolder', this.bodyElement)[0];

		this.linkElements = jQuery('.productSearch .menu a');
		this.linkElements.click(productSearch.LinkClick);

		jQuery('.closeBtn', this.bodyElement).click(productSearch.CloseClick);

		this.loadingBlock = jQuery('.loadingBlock', this.bodyElement);

		jQuery('.productSearchToolLink').click(productSearch.Toggle);

		jQuery('.productSearch .menu li').mouseover(function() { this.className = 'over'; });
		jQuery('.productSearch .menu li').mouseout(function() { this.className = ''; });
	},

	openHeight: 0,

	bodyElement: null,

	LinkClick: function LinkClick()
	{
		if (!jQuery(this).hasClass('selected')) {
			productSearch.linkElements.removeClass('selected');
			jQuery(this).addClass('selected');
			AJAX.DoAjaxRequest(this.href, "productSearch.AjaxCallBack(xmlHttp);");
			jQuery(productSearch.loadingBlock).fadeIn(200);
		
			//Omniture Tracking Code
			if (typeof(s) != 'undefined'){
			    var strGender = ""
			    if (typeof(currentGender) != 'undefined') strGender = currentGender;			
			    var channel = "";
			    if (typeof(currentChannel) != 'undefined') channel = currentChannel;
		        s.prop1 = "Products";
		        s.Channel = channel;
		        s.pageName = channel + " - Products - " + this.innerHTML;
		        if(strGender == "Male") {
		            s.prop2 = "Male Styling";
		        }
		        if(strGender == "Female") {
		            s.prop2 = "Female Styling";
		        }
		        s.tl(this,'o',this.innerHTML);
		    }
		    //End Omniture Tracking Code
		}
		
		
		
		return false;
	},

	CloseClick: function CloseClick()
	{
		productSearch.Close();
		productSearch.linkElements.removeClass('selected');
	},

	Open: function Open()
	{
		jQuery(productSearch.bodyElement).animate({ 'height': productSearch.openHeight + 'px' }, 500, 'swing', null);
		jQuery(productSearch.menuElement).animate({ 'height': productSearch.openMenuHeight + 'px' }, 300, 'swing', function() { jQuery(this).css('overflow', 'visible') });
		if (!jQuery(productSearch.linkElements[productSearch.linkElements.length - 1]).hasClass('selected') && !productSearch.isOpen)
		{
		    jQuery(productSearch.linkElements[productSearch.linkElements.length - 1]).click();
		}
		productSearch.isOpen = true;

		return true;

	},

	Close: function Close()
	{
		jQuery(productSearch.bodyElement).animate({ 'height': '0px' }, 500, 'swing', null);
		jQuery(productSearch.menuElement).css('overflow', 'hidden');
		jQuery(productSearch.menuElement).animate({ 'height': '0px' }, 300, 'swing', null);
		productSearch.isOpen = false;
		return false;
	},

	Toggle: function Toggle()
	{
		if (productSearch.isOpen)
			productSearch.Close();
		else
			productSearch.Open();
	},

	FlashOpen: function FlashOpen()
	{
		productSearch.Toggle();
	},

	AjaxCallBack: function AjaxCallBack(xmlHttp)
	{
	    //alert(jQuery(productSearch.ajaxFrame)[0].innerHTML);
	    //alert(xmlHttp.responseText) 
		//jQuery(productSearch.ajaxFrame).html(xmlHttp.responseText);
		jQuery(productSearch.ajaxFrame)[0].innerHTML = xmlHttp.responseText;
		jQuery(productSearch.loadingBlock).fadeOut(200);

		slider.Reset();
		slider.Init(productSliderVars);
	}
}


