Elastic.configuration.refreshOnResize = false;
var first_time = false;
// jQuery DOM Ready fn
jQuery(document).bind('elastic:initialize', function (){
	
	// Scrollable Index
	$(".scroller").scrollable({
		size       : 1,
		speed      : 300,
		loop       : true,
		items      : "div.items",
		prev       : "a#left",
		next       : "a#right",
		easing     : "linear",
		keyboard   : true
	});
	
	$('.nposts').css('height', $(".posts-wrapper").height());
	
	// Scrollable Posts
	$(".nposts").scrollable({
		size       : 1,
		speed      : 300,
		loop       : true,
		items      : "div.posts",
		prev       : "a#page-left",
		next       : "a#page-right",
		navi       : "div#values-nav",
		easing     : "linear",
		keyboard   : true
	});
		
	// Scrollable Favorite Links
	$(".colcontent").scrollable({
		size       : 1,
		speed      : 300,
		loop       : true,
		items      : "div.lists",
		prev       : "a#left",
		next       : "a#right",
		navi       : "div#links-nav",
		easing     : "linear",
		keyboard   : true
	});

	// Scrollable Tweets
	$(".twitter").scrollable({
		size       : 1,
		speed      : 300,
		loop       : true,
		items      : "div.tweets",
		prev       : "a#leftl",
		next       : "a#rightr",
		navi       : "div#tweets-nav",
		easing     : "linear",
		keyboard   : true
	});

	// Scrollable Work
	$(".work-scroller").scrollable({
		size       : 6,
		speed      : 300,
		loop       : true,
		items      : "div.items",
		prev       : "a#prev",
		next       : "a#next",
		easing     : "swing",
		keyboard   : true
	});

	// Scrollable Sketch
	$(".sketch-scroller").scrollable({
		size       : 6,
		speed      : 300,
		loop       : true,
		items      : "div.items",
		prev       : "a#prev",
		next       : "a#next",
		easing     : "swing",
		keyboard   : true
	});

	// Services URL parsing and selection
	var theUrl = document.location.toString();
	
	if (theUrl.match('/pulse/') || theUrl.match('935')) {
		$('.control, .bullet').click(function() {
			$('html, body').animate({scrollTop:0}, 'slow');
		});
	}
	

	// shows and hide magnifier on projects page
	$('.project').each(function(){
		var container = this;
		$('div.proj-image', container).mouseenter(function(){
			$('.magnify', container).show();
		});
		$('div.proj-image', container).mouseleave(function(){
			$('.magnify', container).hide();
		});
	});

	// shows and hide magnifier on sketches page
	$('.sketch').each(function(){
		var container = this;
		$('div.container > div.unit > div.container', container).mouseenter(function(){
			$('.magnify', container).show();
		});
		$('div.container > div.unit > div.container', container).mouseleave(function(){
			$('.magnify', container).hide();
		});
	});

	// shows and hide magnifier on work details page
	$('.work-scroller .item').each(function(){
		$(this).mouseenter(function(){
			$('.lupa', this).show();
		});
		$(this).mouseleave(function(){
			$('.lupa', this).hide();
		});
		$(this).click(function() {
			$(this).parents('.unit').stop();
		});
	});

	// shows and hide magnifier on sketch details page
	$('.sketch-scroller .item').each(function(){
		$(this).mouseenter(function(){
			$('.lupa', this).show();
		});
		$(this).mouseleave(function(){
			$('.lupa', this).hide();
		});
		$(this).click(function() {
			$(this).parents('.unit').stop();
		});
	});


	// Shows and hides ratings for sketches
	$('.likes .fixed').each(function(){
		if( $.cookie('notebook_down_'+$('#vota_post_down').attr('rel')) || $.cookie('notebook_up_'+$('#vota_post_up').attr('rel')) == true){
			$('img', this).hide();
			$('div.unit', this).fadeIn('fast');
		}else{
			$(this).hover(function(){
				$('img', this).hide();
				$('div.unit', this).show();
			}, function(){
				$('img', this).show();
				$('div.unit', this).hide();
			});
		}
	});


	//rating sketches
	$('#vota_post_down').click(function(){
		var COOKIE_NAME = 'notebook_down_'+$(this).attr('rel');
		var options = { path: '/', expires: 1 };
		vote_user = $.cookie(COOKIE_NAME);
		if(vote_user != 'true') {
			$.ajax({
				type: "POST",
				url: wp_root+"vote.php",
				data: "vote=down_vote&post_id="+$(this).attr('rel')+"&count="+$('.n_down').attr('rel'),
				success: function(msg){
					$('.n_down').empty();
					$('.n_down').append(msg);
					$('.n_down').attr({rel:msg});

				}
			});
			$.cookie(COOKIE_NAME, 'true', options);
			$('.likes .fixed').each(function(){
				$(this).unbind('mouseenter').unbind('mouseleave');
				$('img', this).hide();
				$('div.unit', this).fadeIn('slow');
			});
		}
		return false;
	});
	$('#vota_post_up').click(function(){
		var COOKIE_NAME = 'notebook_down_'+$(this).attr('rel');
		var options = { path: '/', expires: 1 };
		vote_user = $.cookie(COOKIE_NAME);
		if(vote_user != 'true') {
			$.ajax({
				type: "POST",
				url: wp_root+"vote.php",
				data: "vote=up_vote&post_id="+$(this).attr('rel')+"&count="+$('.n_up').attr('rel'),
				success: function(msg){
					$('.n_up').empty();
					$('.n_up').append(msg);
					$('.n_up').attr({rel:msg});
				}
			});
			$.cookie(COOKIE_NAME, 'true', options);
			$('.likes .fixed').each(function(){
				$(this).unbind('mouseenter').unbind('mouseleave');
				$('img', this).hide();
				$('div.unit', this).fadeIn('slow');
			});
		}
		return false;
	});

});
	

