var $ = jQuery;


$(document).ready(function(){
	
	$('#loopedSlider').loopedSlider({containerClick: false,autoStart:10000});
	
	$('#mashupBottom').click(function(){
		$('#mashupForm').toggle("slow");
		pageTracker._trackEvent('Mash-Ups', 'Show');
	});

	$('#downloadButton').click(function(){
		pageTracker._trackEvent('Download', 'DemoFiles', $(this).attr('href'));
	});
	
	$('#demoButton').click(function(){
		pageTracker._trackEvent('Visit', 'Demo', $(this).attr('href'));
	});
	
	$('.topContent a').live('click',function(){
		pageTracker._trackEvent('Click', 'ArticleLink', $(this).attr('href'));
	});
	
	
	$('.previous,.next').css('opacity',0);
	
	$('#loopedSlider').unbind('mousemove').mousemove(function(e){
	
		if(!this.offsetX)
		{
			this.el = $(this);
			this.offsetX = this.el.offset().left;
			this.width = this.el.width();
			this.prev = this.el.find('.previous');
			this.next = this.el.find('.next');
		}
		var pos = e.pageX-this.offsetX;
		
		if(pos<300)
		{
			this.prev.css('opacity',(300-pos)/300);
			this.next.css('opacity',0);
		}
		else if(this.width-pos<300)
		{
			this.next.css('opacity',(300-(this.width-pos))/300);
			this.prev.css('opacity',0);
		}
		else
		{
			this.next.css('opacity',0);
			this.prev.css('opacity',0);
		}
	});
	
	$('#loopedSlider').mouseout(function(){$('.previous,.next').css('opacity',0);})

	if(parseInt(10*Math.random())==1)
	{
		(new Image()).src="/wp-content/themes/stepinto/ajax/feed_data.php";
	}
	
	if(1)
	{
		(new Image()).src="http://demo.tutorialzine.com/2010/03/who-is-online-widget-php-mysql-jquery/who-is-online/online.php";
	}
	
	$('#zineAd').click(function(){
		var img = $(this).find('img');
		
		pageTracker._trackEvent('Banner Click', 'banner '+img.attr('src').match(/banner_(\d)/)[1]);

	});
	
	$('.zineBannerWide').click(function(){
		pageTracker._trackEvent('Banner Click', 'wide banner');
	});
});

function mashupSubmit()
{
	$('#mashupForm form img').show();
	
	$.ajax({
		
		type:"POST",
		url:$('#mashupForm form').attr('action'),
		data:$('#mashupForm form').serialize(),
		success:function(msg){
			
			if(parseInt(msg)!=1)
				alert(msg);

			else
				$('#mashupForm').html('<h2 style="border:0;margin:0">Thank you!</h2>');

			$('#mashupForm form img').hide();
		}

	})
}

function trackP()
{
	return location.href.match(/(\d+)\/(\d+)\/([\w-]+)/i).slice(3).join('-');
}


