$(function(){
	$(".quickViewLink").live("click", openQuickView);
	$(".productBox").live("click", function(event){
		var pageURL = $(event.currentTarget).data("url");
		location.href = pageURL;
	});
	
	$(".openModal").click(function(event){
		event.preventDefault();
		var href = $(this).attr("href");
		var options = {maxWidth: 800 };
		if (href.indexOf("#") > -1)
			options.html = $(href).html();
		else
			options.href = href;
		if ($(this).attr("modalWidth"))
			options.innerWidth = $(this).attr("modalWidth");
		$.colorbox(options);
	});
	
	$("#headerLinks img.ecrew").click(function(){
		$("#headerLinks #ecrewHolder").toggle();
	});
});

toast = function(msg,type,options) {
	 /*types: 'showSuccessToast', 'showWarningToast','showErrorToast'*/																
	if (!type || type == null)
		type = 'showNoticeToast';
	if (options == null)
		options = {
			sticky: false,			
			position: 'top-center'
		}
	 if (options.type == null)
 		switch (type) {
 		case "showNoticeToast":
 			options.type = 'notice';
 			break;
 		case "showSuccessToast":
 			options.type = 'success';
 			break;
 		case "showErrorToast":
 			options.type = 'error';
 			break;
 		case "showWarningToast":
			options.type = 'warning';	 		
 			break;
		}
	if (options.text == null)
		options.text = msg;
	return $().toastmessage('showToast', options);	
}
openQuickView = function(event) {
	event.stopPropagation();
	var pageURL = $(event.currentTarget).data("url");
	$.colorbox({
		href: pageURL,
		innerWidth: 768,
		innerHeight: 600,
		escKey: false,
		iframe: true,
		close: closeLabel,
		top: 30,
		onComplete: function(){
			$("#quickViewConfirm").css("left",$("#colorbox").css("left"));			
		},
		onCleanup: function(){
			$("#quickViewConfirm").hide();
			if (location.href.toLowerCase().indexOf("c_store.viewshoppingcartcontents") > -1 || location.href.toLowerCase().indexOf("c_store.viewallshoppingcarts") > -1)
				location.reload(true);
			else if (currentAccountType.toLowerCase() != quickViewAccountType.toLowerCase()) {
				$.get(
					"/sfc3/index.cfm",
					{
						route: "c_customer.ChangeAccountType",
						AccountType: currentAccountType,
						Tab: currentAccountType,
						ReRoute: "ajax"
					}
				)
			}
		}
	});
	if (typeof pageTracker == "object")
		pageTracker._trackPageview(pageURL);
};

var refreshRighSidebarCart = function(){
	$.get(
		"/sfc3/index.cfm",
		{
			route: "c_store.viewSidebarCartAjax",
			checkLogin: checkLogin,
			changeWebsite: changeWebsite,
			_cf_nodebug: "true"
		},
		function(response){
			if (response.SUCCESS){
				$("#RSCartContents").fadeTo("slow",0).html(response.data).fadeTo("slow",1,function(){
					$(this).css('filter','');	
				});
				
				$("#RSCart").show();
				$(".ItemCount").html(response.CARTSTATS.ITEMCOUNT);
				$(".BasketTotal").html(response.CARTSTATS.CARTTOTAL);
				
			} else
				window.location = "/";
		},
		"json"
	);
};

	
	
	if(!Object.keys) Object.keys = function(o){  
		if (o !== Object(o))  
        	throw new TypeError('Object.keys called on non-object');  
     	var ret=[],p;  
     	for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p);  
     	return ret;  
    }  
