$(document).ready(function(){
		
	var likeButton = $(".like");
	var dislikeButton = $(".dislike");
	var saveitButton = $(".saveit");
	var viewLargerButton = $(".view-larger");
		
	// ---------------------------------- //
	// Vote Click (Likes)                 //
	// ---------------------------------- //
	likeButton.click(function(){
		
		likeID = this.id;
		likeID = likeID.split("-");
		item_id = likeID[1];
		
		if ( $("#like-area-"+item_id).find(".like-area").hasClass("liked") ) {
			// Do nothing!
		} else {
			//_trackEvent('Items','Vote','Liked');
			ajaxVoteData = $(this).attr('rel');
			$("#dataLoadingArea").load("/php_actions/vote.php", ajaxVoteData, fadeInVoteArea);
		}
		
	}); // END Vote Click (Likes)
	
	dislikeButton.click(function(){
		
		dislikeID = this.id;
		dislikeID = dislikeID.split("-");
		item_id = dislikeID[1];
		
		if ( $("#like-area-"+item_id).find(".like-area").hasClass("disliked") ) {
			// Do nothing!
		} else {
			//_trackEvent('Items','Vote','Disliked');
			ajaxVoteData = $(this).attr('rel');
			$("#dataLoadingArea").load("/php_actions/vote.php", ajaxVoteData, fadeInVoteArea);
		}
		
	}); // END Vote Click (Likes)
	
	function SetCookie(cookieName,cookieValue,nDays) {
	 	var today = new Date();
		var expire = new Date();
		if (nDays==null || nDays==0) nDays=1;
		expire.setTime(today.getTime() + 3600000*24*nDays);
		document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
	}
	
	function fadeInVoteArea() {
		$("#like-area-"+item_id).hide();
		setTimeout("$('#like-area-'+item_id).fadeIn('fast')",100);
	}
	
	
	// ---------------------------------- //
	// Big Top Area - Hide Button   //
	// ---------------------------------- //
	
	$('.hide-button').click(function(){
		$('#big-top-area').slideUp({'duration':700,'easing':'easeInOutQuint'});
		SetCookie('ds_bigtoparea_setting','off','365');
	});
	
	
	// ---------------------------------- //
	// Item Rollover, Save to Favorites   //
	// ---------------------------------- //
	
	//$('.avatar-and-info').animate({"top": "13px"}, 0);
	//$('.like-percent').animate({"top": "78px"}, 0);
	//$('.action-buttons').animate({"top": "153px"}, 0);
	
	$(".rollover-info").animate({'opacity':0},0);
	
	$(".rollover-info").hover(function(){
		
		$(this).stop().animate({'opacity':1},400, 'easeOutExpo');
				
	}, function() {
		
		$(this).stop().animate({'opacity':0},300, 'easeInExpo');
		
	});
	// END Rollover Action
	
	// Save to Favorites
	saveitButton.click(function(){
		
		likeID = this.id;
		likeID = likeID.split("-");
		item_id = likeID[1];
		
		ajaxVoteData = $(this).attr('rel');
		$("#dataLoadingArea").load("/php_actions/saveit.php", ajaxVoteData);
		
	}); // END Save to Favorites
	
	
	
	// ---------------------------------- //
	// Dropdowns, Filters                 //
	// ---------------------------------- //
	var dropdown = $(".dropdown");
	var filter = $(".dropdown a");
	var filteredWindow = $("#ajax-tab-window");
	
	dropdown.click(function(){
		$(this).find('ul').slideToggle("fast");
	});
	
	filter.click(function(){
		$('#isLoading').show();
		ajaxTabData = $(this).attr('rel');
		var promotedItems = $('#promoted_items').val();
		if (promotedItems == 'search'){
			filteredWindow.load("/tab_includes/search_results.php", ajaxTabData, hideLoading);
		} else if (promotedItems == 1){
			filteredWindow.load("/tab_includes/top_designs.php", ajaxTabData, hideLoading);
		} else {
			filteredWindow.load("/tab_includes/random_designs.php", ajaxTabData, hideLoading);
		}
	});
	
	
	
	// ---------------------------------- //
	// Pagination                         //
	// ---------------------------------- //
	/*var page = $(".item-pagination a");
	var pagedWindow = $("#ajax-tab-window");
	var bsa = $(".bsa");
	
	page.click(function(){
		$('#isLoading').show();
		ajaxTabData = $(this).attr('rel');
		if ($(this).hasClass('search')){
			filteredWindow.load("/tab_includes/search_results.php", ajaxTabData, hideLoading);
			//bsa.load("/php_includes/bsa.php");
		} else if ($(this).hasClass('submissions')){
			filteredWindow.load("/tab_includes/random_designs.php", ajaxTabData, hideLoading);
			//bsa.load("/php_includes/bsa.php");
		} else {
			filteredWindow.load("/tab_includes/top_designs.php", ajaxTabData, hideLoading); 
			//top.bsa.location.href = "http://hotshotphoto.com/php_includes/bsa.php?hello=1";
			//bsa.load("/php_includes/bsa.php");
		}
		
		var $target = 'items-top';
		$target = $target.length && $target || $('[name=items-top]');
		if ($target.length) {
			//$target.ScrollTo(100);
			return false;
		}
	});*/
	
	
	
	// ---------------------------------- //
	// Item - View Full Screenshot        //
	// ---------------------------------- //
	var itemView = 0;
	
	viewLargerButton.click(function(){
		
		var screenshotHeight = $(this).find('.screenshot').height();
		
		if (itemView == 1) {
			$('.screenshot-wrap').stop().animate({'height':'300'},400);
			$('.screenshot-wrap').removeClass('enlarged');
			$('.view-larger-block').html('Click to View Full Screenshot');
			itemView = 0;
		} else {
			$('.screenshot-wrap').stop().animate({'height':screenshotHeight},400);
			$('.screenshot-wrap').addClass('enlarged');
			$('.view-larger-block').html('Click to View Small Screenshot');
			itemView = 1;
		}
		
	}); // END Vote Click (Likes)
	

	
	// ---------------------------------- //
	// Elastic Text Areas                 //
	// ---------------------------------- //
	var textAreas = $(".textarea");
	textAreas.elastic();
	textAreas.blur(function(){
		if (!$(this).hasClass("reply_textarea")) {
			if (this.value == '') {
				$(this).animate({"height": "19px"}, "fast");
			}
		} else {
			if (this.value == '') {
				$(this).animate({"height": "15px"}, "fast");
			}
		}
	}); // END Elastic Text Areas
	
	
	
	// ---------------------------------- //
	// Reply to Messages                  //
	// ---------------------------------- //
	var reply_id = 0;
	var current_reply_id = 0;
	var replyLink = $('.reply-link');
	
	replyLink.click(function(){
		
		replyLink = this.id;
		replyLink = replyLink.split("_");
		reply_id = replyLink[2];
		
		$(this).hide();
		$('#reply_'+reply_id).fadeIn("fast");
		document.getElementById('reply_textarea_'+reply_id).focus();
		
	}); // END Reply to Messages
	
	// ---------------------------------- //
	// Post a Comment                     //
	// ---------------------------------- //
	var options = { target:'#messageFormAlert' };
	var messageForm = $('#messageForm');
	var messageButton = $('#messageButton');
	var messageLoader = $("#messageLoader");
	
	messageForm.ajaxForm(options);
	messageButton.click(function(){
		messageLoader.show();
	}); // END Post a Message
	
	// ---------------------------------- //
	// Post a Comment Reply               //
	// ---------------------------------- //
	replyForm = $('.replyForm');
	replySubmit = $('.reply_submit');
	replyWrap = $(".reply_wrap");
	options = { target:'#dataLoadingArea' };
	
	replyForm.ajaxForm(options); 
	replySubmit.click(function(){
		replyWrap.hide();
	});
	
});