
function recordOutboundLink(link, category, action) {
  try {
    var myTracker=_gat._getTrackerByName();
    _gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
    setTimeout('document.location = "' + link.href + '"', 100)
  }catch(err){}
}

var toolthem = function(){

		$(".tooled").tooltip({
			relative: true,
			predelay: 250,
			delay: 30,
			effect: 'slide',
			position: 'center left',
			tipClass: 'tooltip-big',
			onBeforeShow: function(event, position){
				this.getTrigger().parent().parent().css('z-index','9999');
			},
			onHide: function(){
				this.getTrigger().parent().parent().css('z-index','1');
			}
		}).dynamic();
		 
/*
		$(".tooled").tooltip({
			relative: true,
			predelay: 250,
			delay: 30,
			effect: 'slide',
			position: 'top center',
			offset: [14,0],
			tipClass: 'tooltip-big',
			onBeforeShow: function(event, position){
				this.getTrigger().parent().parent().css('z-index','9999');
			},
			onHide: function(){
				this.getTrigger().parent().parent().css('z-index','1');
			}
		}).dynamic({ bottom: { direction: 'down', relative:true } });
*/		 
			 
		$(".tooled").click(function(){
			var tip = $(this).parent().next('.tooltip-side').children('.tooltip-side-inside');
			var h = tip.height();
			tip.html('<div class="magic-sidebar is-tooltip-magic"><div class="center in-tooltip-magic" style="color:#000"><img src="/images/site/overlay/tanflower.gif" alt="loading new page"><br />loading this product...</div></div>').height(h);
		});
		if( !($.browser.msie && ( parseInt($.browser.version) == 7 ) ) ) {
		/*
		$(".tooled-pop").tooltip({
			predelay: 250,
			delay: 30,
			effect: 'slide',
			position: 'top center',
			offset: [14,0],
			tipClass: 'tooltip-big',
			onBeforeShow: function(event, position) {
	       		this.getTip().appendTo(document.body);
	       		return true;
	    	},
	    	onHide: function(){
	    		var tip = this.getTip();
	    		tip.appendTo(this.getTrigger());
	    	}
		}).dynamic({
			 bottom: {
			 	direction: 'down',
			 	bounce: true }
		});
		*/
		$(".tooled-pop").tooltip({
			relative: false,
			predelay: 250,
			delay: 30,
			effect: 'slide',
			position: 'center left',
			tipClass: 'tooltip-big',
			onBeforeShow: function(event, position){
				this.getTip().appendTo(document.body);
	       		return true;
			},
			onHide: function(){
				var tip = this.getTip();
	    		tip.appendTo(this.getTrigger());	
			}
		}).dynamic();
		
		
	
		}
	};

$(document).ready(function(){
	$('#fmessageClose').live('click', function(){
		$(this).parent().fadeOut();
	});
	
	$('.productburst').siblings('img').hover(
		function(){
			$('.productburst').fadeOut();
		},
		function(){
			$('.productburst').fadeIn();
		}
		);
	/* TOOLTIPS */
	toolthem();
	//$(window).resize(toolthem());
	/* SCROLLABLE CAROUSEL */
	$(".scrollable").scrollable();
	$(".scrollable-wide").scrollable();
	$(".overlay").overlay({
		mask: 'darkred',
		effect: 'apple',
		target: '#overlay',
		
		onBeforeLoad: function(){
			var wrap = this.getOverlay().find(".contentWrap");
			if (this.getTrigger().attr('rel') != ''){
				wrap.load(this.getTrigger().attr("rel"));
			}
			else {
				wrap.load(this.getTrigger().attr("href"));
			}
		}
	});
	
	$(".eshipping").submit(function(){
		$.ajax({
			url: "/cart/ajaxship/",
			type: 'POST',
			data: $(this).serialize(),
			success: function(data){
				$(".contentWrap").html(data);
			}
		});
	  	// POPUP OVERLAY
	  	$("#overlay").overlay({
	  		oneInstance: false,
	  		mask: 'darkred',
	  		effect: 'apple',
	  		load: true,
	  		onClose: function(){
	  			var wrap = this.getOverlay().find(".contentWrap");
	  			wrap.html('');	
	  		}
		}).load();
   		return false;
	});
	
	
	
	
	$(".buybutt").each(function(i){
		$(this).submit(function(){
       		// LOAD NEW CART DATA
       		$.ajax({ 
		  		url: "/cart/ajaxadd/",
		  		data: $(this).serialize(),
		  		type: 'POST',
		  		success: function(data){ 
		  			$(".contentWrap").html(data);
		  		}
		  	});
		  	// POPUP OVERLAY
		  	$("#overlay").overlay({
		  		oneInstance: 	false,
		  		mask: 			'black',
		  		effect: 		'apple',
		  		load: 			true,
		  		top:			15,
		  		onLoad: 		function() {
		  							$('#continue-shopping-button').click(function() {
		  								$('.close').click();
		  							});
						  			$.ajax({
						  				url:		'/cart/ajaxrelated/',
						  				data:		{ id: $('#id_related_to').val() },
						  				datatype:	'html',
						  				type:		'post',
						  				success: 	function(data) {
									  					$('#related_content').html(data);
									  					var newtooled = $('#related_content .tooled');
									  					newtooled.tooltip({
															relative: true,
															predelay: 250,
															delay: 30,
															effect: 'slide',
															position: 'top center',
															offset: [14,0],
															tipClass: 'tooltip-big'
														});
									  				},
						  				error: 		function(err) {
						  								$('#related_content').html('<p>We don\'t yet have related albums of this product.</p><p>Reason: ' + err + '</p>');
						  							}
						  			});
		  						},
		  		onClose: 		function(){
		  							var wrap = this.getOverlay().find(".contentWrap");
		  							wrap.html('')
		  							$("#topCheckout").load('/ajax/checkoutbutton/');	
		  						}
			}).load();
       		return false;
      	}); 
	});
	/*
	$(".downButt").each(function(i){
		$(this).submit(function(e){
			e.preventDefault();
			window.location.href="/play/download/"+ $("this, input[name='product_id']").val() +"/"+ $("this, input[name='isrc']").val();
		});
	});
	*/
	$("#facetted input:submit").hide();
	$("#facetted input:checkbox").click(function(){
		//alert($("#facetted").serialize());
		$("#facetted").submit();
	});
	$("ul.tabs").tabs("div.panes > div");
	$("#searchtopnav select").bind("change", function(){
		this.form.submit();
	});
	
	$('.wpmenuitem').click(function(){
		window.location.href = $(this).children('.wpbutton').attr('href')
	});
	
});
