var quotcoll_requrl, quotcoll_nextquote, quotcoll_loading, quotcoll_errortext;

function quotescollection_init(requrl, nextquote, loading, errortext)
{
	quotcoll_requrl = requrl;
	quotcoll_nextquote = nextquote;
	quotcoll_loading = loading;
	quotcoll_errortext = errortext;
}

function quotescollection_refresh(instance, exclude, show_author, show_source, filter_tags, char_limit)
{
	jQuery("#quotescollection_nextquote-"+instance).html(quotcoll_loading);
	jQuery.ajax({
		type: "POST",
		url: quotcoll_requrl,
		data: "refresh="+instance+"&exclude="+exclude+"&show_author="+show_author+"&show_source="+show_source+"&char_limit="+char_limit+"&tags="+filter_tags,
		success: function(response) {
			jQuery("#quotescollection_randomquote-"+instance).hide();
			jQuery("#quotescollection_randomquote-"+instance).html( response );
			jQuery("#quotescollection_randomquote-"+instance).fadeIn("slow");	
		},
		error: function() {
			alert("There was an error getting quote.");
			jQuery("#quotescollection_nextquote-"+instance).html(quotcoll_nextquote);
		}	
	});
}


jQuery(document).ready(function(){
    var quotes_amount = jQuery('#quotes .quote-home').length;
    var counter = 1
    jQuery('#quotes .quote-home').each(function(){
        jQuery(this).addClass('quote-home-' + counter);
        counter++;   
    });
    var initHeight = jQuery('#quotes .quote-home-1').height();
   jQuery('#quotes .quote-crop').height(initHeight);
    
    var sliderPush = 0;
    var sliderInc = 358;
    var slideCounter = 1; 
    jQuery('#quotes .more-quotes').click(function(){
       sliderPush = sliderPush - sliderInc;
       if(sliderPush <= (-1 * quotes_amount * sliderInc)){sliderPush = 0}

       if(slideCounter >= quotes_amount){
            slideCounter = 1;
            var newHeight = jQuery('#quotes .quote-home-' + slideCounter).height();
            slideCounter--;   
        } 
        else {
            var newHeight = jQuery('#quotes .quote-home-' + slideCounter).next().height();
        }      
       jQuery('#quotes .quote-crop').animate({
          height: newHeight
       },400);
       jQuery('#quotes .quote-slide').css('margin-left', sliderPush + 'px');
       slideCounter++;       
    });
    

});
