function makeZebra() {
	jQuery("table#archive-table tr:visible").each(
      	function( intIndex ){
      		if (intIndex%2==0) {
      			jQuery(this).addClass("altrow");
      		}
      	});
}
jQuery(document).ready(function() { 
       
	jQuery("#contact #submit").hide();
	
	jQuery("#go-contribute").show();
	
	
	jQuery("#s").attr("value", searchText).focus(function(){
		if(jQuery(this).val() == searchText){
			jQuery(this).val("");
         }
    }).blur(function(){
		if(jQuery(this).val() == ""){
			jQuery(this).val(searchText);
		}
	});
	
	jQuery(".fancybox").colorbox({
		href:"#submit-form",
		inline:true, 
		transition:	"elastic",
		scrolling: false,
		opacity: 0.75
	});
	
	
	
	jQuery("input#button").click( function(e) {
		if(jQuery("#s").val() == searchText){
			jQuery("#s").val("");
         }
	});
	
	
	// AJAX za Submit linka
	jQuery("#submit-form form").submit( function(e) {
		var submitter_name = jQuery("input#submitter_name").val();
		var queryString = "is_ajax=1&" + jQuery("#submit-form form").serialize();
		jQuery.ajax({
			cache: 	false,
			type:	"POST",
			url: 	"/",
			data: queryString,
			error: 	function(){
				jQuery("#submit-form p.submit-error").remove();
    			jQuery("#submit-form h2").after('<p class="submit-error">Something went wrong! Please check that all required fields are filled proprely. There are only two of them, it shouldn\'t be that hard ;)</p>');
    			jQuery.fn.colorbox.resize();
  			},
  			success: function() {
  				jQuery("#submit-form").html("<h2>Thank you " + submitter_name + "!</h2><p>Your tip has been submitted successfully.</p>");
  				jQuery.fn.colorbox.resize();
  			}
			
		});
		return false;
	});
	
	
	// Hendlanje klikova na filtere u arhivama
	var tfootDefault = jQuery("tfoot tr td").html();
	var tfootNoTips = "Sorry, no tips available";
	jQuery("li#dos-switch a").bind("click", function(e) { 
    	e.preventDefault();
       	
       	// Sredi meni sa fliterima
       	jQuery("li#dos-switch").attr("id", "dos-switch-active");
       	jQuery("li#donts-switch-active").attr("id", "donts-switch");
       	jQuery("li#all-switch-active").attr("id", "all-switch");
       		
       	// Sakrij, prikaži, animiraj...
        jQuery("table#archive-table tbody").fadeTo("fast", 0.01);
        jQuery("table#archive-table tr.donts").hide();
        jQuery("table#archive-table tr.dos").show();
        jQuery("table#archive-table tr").removeClass("altrow");
        jQuery("table#archive-table tr.dos:odd").addClass("altrow");
       	jQuery("table#archive-table tbody").fadeTo("slow", 1);
       	
       	var dosCount = jQuery("table#archive-table tr.dos").size();
       	if (dosCount > 0) {
    		jQuery("tfoot tr td").html(tfootDefault).find("span").text(dosCount);
    	} else {
    		jQuery("tfoot tr td").html(tfootNoTips);
    	}   	
	});
       	
    jQuery("li#donts-switch a").bind("click", function(e) {
    	e.preventDefault(); 
       		
    	// Sredi meni sa fliterima
    	jQuery("li#dos-switch-active").attr("id", "dos-switch");
		jQuery("li#donts-switch").attr("id", "donts-switch-active");
       	jQuery("li#all-switch-active").attr("id", "all-switch");
       		
        jQuery("table#archive-table tbody").fadeTo("fast", 0.01);
        jQuery("table#archive-table tr.dos").hide();
        jQuery("table#archive-table tr.donts").show();
        jQuery("table#archive-table tr").removeClass("altrow");
        jQuery("table#archive-table tr.donts:odd").addClass("altrow");
       	jQuery("table#archive-table tbody").fadeTo("slow", 1);
       	
       	var dontsCount = jQuery("table#archive-table tr.donts").size();
       	if (dontsCount > 0) {
    		jQuery("tfoot tr td").html(tfootDefault).find("span").text(dontsCount);
    	} else {
    		jQuery("tfoot tr td").html(tfootNoTips);
    	}
	});
       	
    jQuery("li#all-switch a").click(function(e) { 
    	e.preventDefault();
       		
		// Sredi meni sa fliterima
       	jQuery("li#dos-switch-active").attr("id", "dos-switch");
       	jQuery("li#donts-switch-active").attr("id", "donts-switch");
       	jQuery("li#all-switch").attr("id", "all-switch-active");
       	
       	jQuery("table#archive-table tbody").fadeTo("fast", 0.01);
       	jQuery("table#archive-table tbody tr").show();
        jQuery("table#archive-table tbody tr").removeClass("altrow");
        jQuery("table#archive-table tbody tr:odd").addClass("altrow");
       	jQuery("table#archive-table tbody").fadeTo("slow", 1);
       	
       	jQuery("tfoot tr td").html(tfootDefault);	
	});
       	
    jQuery("table#archive-table").tablesorter();
    jQuery("table#archive-table").bind("sortStart", function() { 
    	jQuery("table#archive-table tr").removeClass("altrow");
    	}).bind("sortEnd",function() { 
       		makeZebra();
       	});
       	
    jQuery("li#all-switch").attr("id", "all-switch-active");
             
} );