var popout = null;
/*
 *	Funciones globales
**/ 
jQuery(document).ready(function(){
        popout = new GenericPopout;
	setButtonHover();
	
	jQuery(".sidebar ul").each(function(){
		jQuery(this).children(":first").addClass("first");
	});
	
	jQuery(".sidebar .block-title").toggle(
		function(){
			jQuery(this).addClass("hide");
			jQuery(this).next().slideUp(300);
		},
		function(){
			jQuery(this).removeClass("hide");
			jQuery(this).next().slideDown(300);
		}
	);
	
	var store_currency = new StoreCurrencyPicker;
	
});

function StoreCurrencyPicker(){
	
	this.wrapper				= jQuery("#currency-store-picker");
	this.list_store 			= this.wrapper.find("#list-store");
	this.list_currency 			= this.wrapper.find("#list-currency");
	
	this.current_store 			= this.list_store.find(".here input").val();
	this.current_currency 		= this.list_currency.find(".here input").val();
	
	this.init = function(){
		this.pickerTrigger();
		this.bindEvents();
	};
	
	this.bindEvents = function(){
		
		var _this = this;
		
		this.list_store.find("a").click(function(){
			var element = jQuery(this);
			var parent	= element.parent();
			
			parent.siblings().removeClass("here");
			parent.addClass("here");
			
			_this.current_store = element.next().val();
			
			return false;
		});
		
		this.list_currency.find("a").click(function(){
			var element = jQuery(this);
			var parent	= element.parent();
			
			parent.siblings().removeClass("here");
			parent.addClass("here");
			
			_this.current_currency = element.next().val();
			
			return false;
		});
		
		this.wrapper.find(".button").click(function(){
			var element 	= jQuery(this);
			var url 		= _this.current_currency+"?"+_this.current_store;
			
			document.location.href = url;
			element.parent().addClass("loading");
			element.attr("disabled", "disabled");
			
			return false;
		});
		
	};
	
	this.pickerTrigger = function(){		
		jQuery("#currency-store-trigger").toggle(
			function(){
				jQuery(this).parent().addClass("active");
			},
			function(){
				jQuery(this).parent().removeClass("active");
			}
		);
	};
	
	
	this.init();
	
}
