
function report_error(quote_id) {
	//if ($('.ukn-quote-id-' + quote_id).find('a.ukn-quote-reporting-flag').text() == 'Report Error') {
		$.post("/feedback/report_error", {'qid': quote_id}, function(data){
			$('.ukn-error-id-' + quote_id).html('Reported').addClass('ukn-error-reported');
			$.cookie('reporterror-' + quote_id, 'true');
		});
		$('.ukn-error-id-' + quote_id).html('Hang on!');
	//}
}

function vote(quote_id) {
	if ($('.ukn-quote-id-' + quote_id).find('strong').text() == 'Like') {
		$.post("/feedback/vote", {'qid': quote_id}, function(data){
			$('.ukn-quote-id-' + quote_id).addClass('ukn-quote-reporting-liked').find('strong').html('Liked');
			$.cookie('reportlike-' + quote_id, 'true');
		});
		$('.ukn-quote-id-' + quote_id).find('strong').html('<span>Hold on!</span>');
	} else {
	}
}

function checkvote(quote_id) {
	var reportlike = $.cookie('reportlike-' + quote_id);
	if (reportlike == 'true') {
		$('.ukn-quote-id-' + quote_id).addClass('ukn-quote-reporting-liked').find('strong').html('Liked');
	};
	var reporterror = $.cookie('reporterror-' + quote_id);
	if (reporterror == 'true'){
		$('.ukn-quote-id-' + quote_id).addClass('ukn-quote-reporting-error').find('.ukn-quote-reporting-flag').html('Reported');
	};
}

var searchStatus = 1
function searchStatusLoad () {
	if (searchStatus == 1) {
		$('button.ukn-form-submit').before('<span class="ukn-loading-icon">Loading</span>').parent().parent().addClass('ukn-active');
		$('.ukn-searchbox form').after('<div class="ukn-search-status" style="display:none;">Sorry for the wait. We\'ll just be a few more seconds with your results. :)</div>')
		setTimeout(function(){
			//$(this).after('<p class="ukn-search-status">Sorry for the wait. We\'ll just be a few more seconds with your results. :)</p>')
			$('.ukn-search-status').slideDown(250);
		}, 5000);
		searchStatus += 1;
	}
}

$(document).ready(function () {
	
	if (window.console && window.console.firebug) {
		//console.info("Powered by Ultra Knowledge");
		console.log("Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. - Brian Kernighan");
	}
	
	// SEARCHBOX
	$('input').labelify({
	  text: 'label'
	});
	
	$('.ukn-form-submit').click(function() {
		searchStatusLoad();
	});
	
	$("input.ukn-form-searchbox").keypress(function (e) {
		if (e.which == 13) {
			searchStatusLoad();
		}
    });
	
	//$('#ukn-topbar ul li.current_page_item a, .ukn-quote-reporting-like, .ukn-quote-counter').addClass('ukn-corner');
	//$('.ukn-corner').corner("3px");
	//$('.ukn-quote-reporting-like strong').corner("1px");
	
	// MOVE READ MORE INTO H2 TAGS
	$('.ukn-quote a.ukn-view-quote-full').html('').each(function(){
		var $this = $(this);
		var textEl = 'h2.ukn-quote-content';
		$(this).parent().prev().wrapInner($this);
		$(this).prev().remove(); //remove meta sep
		$(this).remove(); //remove original read more link
	});
	
	/*$('.ukn-quote-reporting a.ukn-quote-id-' + quote_id).css('background', 'red');
	$('.ukn-quote-reporting a.ukn-quote-id-' + quote_id).click(function(e) {
		if ($(this).find('strong').text() == 'Like') {
			$(this).addClass('ukn-quote-reporting-liked').find('strong').html('Liked');
			$.cookie('liked', 'voteliked');
	        e.preventDefault();
			return false;
		} else {
	        e.preventDefault();
			return false;
		}
	});
	//$('.ukn-quote-reporting a[title=google].ukn-quote-reporting-like').css('background', 'purple');
	
	var liked = $.cookie('liked');
	if (liked == 'voteliked') {
		$('.ukn-quote-reporting a[href=#1].ukn-quote-reporting-like').addClass('ukn-quote-reporting-liked').find('strong').html('Liked');
	};*/
	
	/*$('.ukn-quote').each(function(i) {
		i = i+1;
		$(this).addClass('ukn-result-'+i);
	});*/
	
	//$('.ukn-quote-leaderboard-ranks').append('<li><span class="ukn-quote-rank">'+i+'</span></li>');
	
	/*$('ul li').click(function(e) {
	    if($('ul.expanded').is(':hidden')) {
	        $('ul').addClass('expanded');
	        $('ul.expanded').fadeIn(300);
	    } 
	});*/
	
	$('.ukn-frontpage .ukn-quote-results').prepend('<a style="display:none;" href="#" class="ukn-quote-results-updated">Oh dear. People have been saying stuff while your back was turned. <br /><span>Refresh now</span> to see what\'s been said.</a>');
	$('.ukn-quote-results-updated').click(function() {
		location.reload();
		return false;
	});
	setTimeout(function(){
		$('.ukn-quote-results-updated').slideDown(500);
	}, 120000);

	
	// NEED TO REPLACE [href=#1] with ARTICLE ID
	/*$('.ukn-quote-reporting a[href=#1].ukn-quote-reporting-like').click(function(e) {
		if ($(this).find('strong').text() == 'Like') {
			$(this).addClass('ukn-quote-reporting-liked').find('strong').html('Liked');
			$.cookie('liked', 'voteliked');
	        e.preventDefault();
			return false;
		} else {
	        e.preventDefault();
			return false;
		}
	});
	//$('.ukn-quote-reporting a[title=google].ukn-quote-reporting-like').css('background', 'purple');
	
	var liked = $.cookie('liked');
	if (liked == 'voteliked') {
		$('.ukn-quote-reporting a[href=#1].ukn-quote-reporting-like').addClass('ukn-quote-reporting-liked').find('strong').html('Liked');
	};*/
	
	/*$.each(document.cookie.split(';'), function(i, cookie) {
	    var c = $.trim(cookie), name = c.split('=')[0], value = c.split('=')[1];
	    if (value == 'voteliked') {
	        alert('The name is: ' + name);
	    }
	});*/
	
	//$('.ukn-quotes').before('<button>Clear</button>');
	//$('button').click(function() {
	//	$.cookie('liked', null);
	//});
	//$('body').prepend(liked);
	
	/*var sortStrength = $.cookie('sortStrength');
	if (sortStrength == 'active') {
		$(".ukn-popular-tags ul.ukn-component-main li").tsort('a', {order:"desc",attr:"style"});
		$('.ukn-popular-tags a.ukn-sort-abc').removeClass('ukn-sort-abc-asc-active');
		$('.ukn-popular-tags a.ukn-sort-strength').addClass('ukn-sort-strength-desc-active');
		$('.ukn-sort-controls').removeClass('ukn-sort-abc-asc-active').addClass('ukn-sort-strength-desc-active');
	};*/
	
	//var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" ");
	//$(".ukn-form-searchbox").autocomplete(data);
	
	$('.ukn-sidebar').prepend('<div class="ukn-sidebar-nav"><button class="ukn-sidebar-nav-next"><span>Next &rarr;</span></button>').hover(function() {
		/*$('.ukn-sidebar-nav').css('visibility', 'visible');
	}, function() {
		$('.ukn-sidebar-nav').css('visibility', 'hidden');*/
	});
	$('.ukn-sidebar-inner').cycle({
		fx: 'scrollDown',
		speed:500,
		timeout:0,
		next:'.ukn-sidebar-nav-next',
		pause:1,
		pauseOnPagerHover: true,
		height: 'auto',
		cleartype: !$.support.opacity
	});
	/*$(".ukn-sidebar-inner div ul").collapsorz({
		minimum: 10,
		showText: "+",
		hideText: "-",
		linkLocation: "after"
	});*/
	/*$('.ukn-sidebar-inner div a.toggler').each(function(){
		var $this = $(this);
		var textEl = $(this).parent().find('ul').find('li.ukn-toggler').show();
		$(textEl).append($(this));
		//$(textEl).remove();   .ukn-sidebar-inner div ul   *MIGHT WORK IF I MANUALLY ADDED IN THE LAST LIST ELEMENT*
	});*/
	
	//$('.ukn-quote-leaderboard ul li').prepend('<span class="ukn-quote-rank">100</span>');
	//$(".ukn-quote-leaderboard ul li:odd").css('margin', '0 0 18px 10px');
	$('body').not('.ukn-search').find('.ukn-quote-leaderboard ul').before('<div class="ukn-sort-controls"><span class="ukn-sort-method">Sorted by Rank</span><a class="ukn-sort-controls-rank" href="#"><span>Sort by Rank</span></a> <a class="ukn-sort-controls-alpha" href="#"><span>Sort by Alphabetical</span></a></div>');
	$('.ukn-quote-leaderboard ul').before('<ul class="ukn-quote-leaderboard-ranks"></ul>').children('li').each(function (i) {
		i = i+1;
		$('.ukn-quote-leaderboard-ranks').append('<li><span class="ukn-quote-rank">'+i+'</span></li>');
	});
	$('.ukn-quote-leaderboard ul h2').css('padding', '0 0 0 45px');
	
	$('.ukn-quote-leaderboard .ukn-sort-controls .ukn-sort-controls-rank').addClass('ukn-active');
	$(".ukn-quote-leaderboard ul li").tsort("h2 .ukn-quote-count strong",{order:"desc"});
	
	$('.ukn-quote-leaderboard .ukn-sort-controls .ukn-sort-controls-rank').click(function() {
		$(".ukn-quote-leaderboard ul li").tsort("h2 .ukn-quote-count strong",{order:"desc"});
		$(this).addClass('ukn-active').next().removeClass('ukn-active');
		$('.ukn-quote-leaderboard .ukn-sort-controls .ukn-sort-method').html('Sorted by Rank');
		return false;
	});
	$('.ukn-quote-leaderboard .ukn-sort-controls .ukn-sort-controls-alpha').click(function() {
		$(".ukn-quote-leaderboard ul li").tsort("h2 a",{order:"asc"});
		$(this).addClass('ukn-active').prev().removeClass('ukn-active');
		$('.ukn-quote-leaderboard .ukn-sort-controls .ukn-sort-method').html('Sorted Alphabetically');
		return false;
	});
	
	var fqn = $('.ukn-quote-person-famous .ukn-quotes .ukn-quote').size();
	if (fqn > 1) {
		$('.ukn-quote-person-famous .ukn-quote-person-famous-inner').append('<div class="ukn-quotes-nav"><button class="ukn-quotes-nav-next">Next <span>&rarr;</span></button><button class="ukn-quotes-nav-prev"><span>&larr;</span> Previous</button></div>');
		$('.ukn-quote-person-famous .ukn-quotes').cycle({
			fx: 'scrollHorz',
			speed:500, 
			timeout:5000,
			next:'.ukn-quotes-nav-next',
			prev:'.ukn-quotes-nav-prev',
			pager: ".ukn-quotes-nav",
			pause:1,
			pauseOnPagerHover: true,
			height: 'auto'
		}).after('<span class="ukn-quote-mark-open">&ldquo;</span><span class="ukn-quote-mark-close">&rdquo;</span>');
		$('.ukn-quote-person-famous .ukn-quotes-count').show();
	}
	
	$('.ukn-related-people .ukn-component-main .ukn-meta-sep:last').hide();
	
	/*$('.ukn-quote-person-famous-quotes .ukn-quotes .ukn-quote:nth-child(3n+1) h2').css({
		lineHeight:'30px',
		fontSize:'26px'
	});
	$('.ukn-quote-person-famous-quotes .ukn-quotes .ukn-quote:nth-child(3n+2) h2').css({
		lineHeight:'24px',
		fontSize:'18px'
	});*/
	//$('.ukn-quote-wall .ukn-quotes').masonry();
	/*$('.ukn-quote-wall .ukn-quote').each(function(i){
		var n = i % 3;
		$(this).addClass(
		n == 0 ? 'ukn-style-a' :
		n == 1 ? 'ukn-style-b' :
		n == 2 ? 'ukn-style-c' : '');
	});*/
	
	/*$('.ukn-related-quotes ul.ukn-quotes').each(function () {
		$(this).find('li.ukn-quote:last h2.ukn-quote-content a').css('border-bottom', '0px');
	});
	$('.ukn-quote-tables .ukn-quote-leaderboard ul.ukn-quote-leaderboard-table li:last h2 a').css('border-bottom', '0px');*/
	
	//$('.ukn-quote-tables').css('background', 'red').equalHeight();
	/*$('.ukn-quote-tables .ukn-quote-latest ul').cycle({
		fx: 'scrollDown',
		speed:500, 
		timeout:10000,
		pause:1
	});*/
	
	//$('.ukn-quote-wall .ukn-quote:nth-child(6n+1) h2 a').prepend('<img src="images/quote-mark-start-white.png" border="0" />');
	//$('.ukn-quote-wall .ukn-quote:nth-child(6n+2) h2 a').prepend('<img src="images/quote-mark-start-grey.png" border="0" />');
	//$('.ukn-quote-wall .ukn-quote:nth-child(6n) h2 a').prepend('<img src="images/quote-mark-start-blue.png" border="0" />');
	
	//$('.ukn-quote-wall .ukn-quote:nth-child(3n+1)').addClass("ukn-style-a");
	//$('.ukn-quote-wall .ukn-quote:nth-child(3n+2)').addClass("ukn-style-b");
	//$('.ukn-quote-wall .ukn-quote:nth-child(3n)').addClass("ukn-style-c");
	
	$('.ukn-network-jumper').hover(function () {
		$(this).addClass('ukn-active');
		$(this).children('ul').show();
	},function () {
		$(this).removeClass('ukn-active');
		$(this).children('ul').hide();
	});
	
});
