$.preloadImages = function() {
	for(var i = 0; i < arguments.length; i++) {
		$('<img />').attr('src', arguments[i]);   
	} 
}

$(document).ready(function() {
	$.preloadImages(
		'assets/img/bg-gallery-photo.png',
		'assets/img/bg-gallery-video.png',
		'assets/img/glyph-gallery-loader.gif',
		'assets/img/button-gallery-close.png',
		'assets/img/button-gallery-left.png',
		'assets/img/button-gallery-right.png',
		'assets/img/button-linkedin.png',
		'assets/img/button-twitter.png'
	);
	
	if ($.browser.webkit){
		$('#tapmates').scroll(function(event){
			$('body').css('background-position', ((-1) * $(this).scrollTop()) + 'px right');
		});
	}
	
	$('#Email')
		.data('watermark', $('#Email').val())
		.focus(function(event){
			if ($(this).val() == $(this).data('watermark'))
				$(this).val('');
		})
		.blur(function(event){
			if ($(this).val().length == 0)
				$(this).val($(this).data('watermark'));
		});
	
	$('#buttonSubmitEmail').submit();
	
	$('a.-sel-appIcon').click(function(event){
		$this = $(this);
		if ($this.hasClass('enabled')) {

			
			if (!$this.hasClass('active')) {
				$('a.-sel-appIcon.active').removeClass('active');
				$this.addClass('active');
			}
		}
		
		event.preventDefault();
	});
	
	$('#apps').serialScroll({
		target: 'div.app-details',
		items: 'div.app-detail',
		axis: 'x',
		navigation: 'div.app-menu li a.enabled',
		duration: 500,
		force: true,
		easing: 'easeOutBounce'
	});
	
	$("a[rel^='screener']").screener({});
	
	$('#link_cookmate_appstore').click(function(){
		_gaq.push(['_trackPageview', '/appstore/cookmate']);
	});
	
	$('#avatars div.avatar')
		.mouseenter(function(){
			var $sender = $(this);
			
			$sender.find('span.image').stop().animate({'margin-top': '0px'}, 300, function(){
				$sender.find('div.contact').fadeIn(80);
			});
		})
		.mouseleave(function(){
			var $sender = $(this);
			
			$sender.find('div.contact').fadeOut(80);
			$sender.find('span.image').stop().animate({'margin-top' : '30px'}, 300);
		});
	
	$(".stream").tweet({
		username: [],
		join_text: null,
		avatar_size: 48,
		count: 3,
		auto_join_text_default: "",
		auto_join_text_ed: "",
		auto_join_text_ing: "",
		auto_join_text_reply: "",
		auto_join_text_url: "",
		loading_text: "Loading tweets...",
		query: "tapmates"
  });	
});