/**
 * Created by IntelliJ IDEA.
 * User: chris
 * Date: Jun 22, 2010
 * Time: 4:01:54 PM
 * To change this template use File | Settings | File Templates.
 */


$(document).ready(function(){
  $("#search").hide();
  $('#loading').hide();
  $('#section-menu').hide();
  $('#addarticlecomment').hide();
  $('#addusernews').hide();
  $('#addshow').hide();
  $('#bandsortbox').hide();

  $('.kwicks').kwicks({
    max : 485
  });

  $("#toggle-ajax").click(function(event){
    if ($('#toggle-ajax').hasClass('hidden')) { // checks if the content is visible
      $('#loading').show();
      $("#ajax-content").load("ajax-response.html");
	  $("#footerad1").load("../ajax-feeds/banned.html");
	  $("#footerad2").load("../ajax-feeds/luckyman.html");
      $('#loading').hide();
    } else {
    }

    return false;
	});

  $(".hidden,.visible").click(function(event){
    if ($(this).hasClass('hidden')){
      $(this).removeClass('hidden')
      $(this).addClass('visible');
    } else {
      $(this).removeClass('visible')
      $(this).addClass('hidden');
    }
    $(this).parent().next().slideToggle();

    return false;
  });

	$("#recientarticles dd:not(:first)").hide();
	$("#recientarticles dt").click(function(){
		$("#recientarticles dd:visible").slideUp("slow");
		$(this).next().slideDown("slow");
		return false;
	});

	$("#section-menu dd:not(:first)").hide();
	$("#section-menu dt").click(function(){
		$("#section-menu dd:visible").slideUp("slow");
		$(this).next().slideDown("slow");
		return false;
	});    

    $('a.showflyer').colorbox({
            maxHeight:'700px',            
            onComplete:function() {
                $("#cboxTitle").hide();
                link = $.fn.colorbox.element();
                title = $(link).attr("title");
                $("<div id='cboxNewTitle'>"+title+"</div>").insertAfter("#cboxPhoto");
                $.fn.colorbox.resize();
            }
    });
    $("a[rel='gallery_in']").colorbox({maxHeight:'700px'});

    //start - auto selects banner and show embed code
    $('.select_text').click(function(event) {
        event.preventDefault();
        var id = $(this).attr('id');
        $('textarea#select'+id).select();
    });
    $('textarea[id^=select]').focus(function() {
        this.select();
    });
    //end - auto select
    //start - show time picker
    $("#clockpick").clockpick({
        starthour : 0,
        endhour : 23
    });//end - show time picker
    //start - Beta tab at top of the page
    $("#sub-panel").click(function(){
        // Toggle the bar up
        $("#top-panel").slideToggle();
        // Settings
        var el = $("#shText");
        // Lets us know whats inside the element
        var state = $("#shText").html();
        // Change the state
        state = (state == 'Beta' ? '<span id="shText">Hide</span>' : '<span id="shText">Beta</span>');
        // Finally change whats insdide the element ID
        el.replaceWith(state);
    }); //end - Beta tab
    $("#venueselect").change(onSelectChange);
});
function onSelectChange(){
    var selected = $("#venueselect option:selected");
    var output = "";
    if(selected.text() == '** Other **'){
        $("#othervenue").removeClass("hidden");
        $("#othervenue").addClass("meta");
    }
    else
    {
        $("#othervenue").removeClass("meta");
        $("#othervenue").addClass("hidden");
    }
}
$(function(){
    $('#commentmain').keyup(function(){
        limitChars('commentmain', 350, 'countdownmain');
    })
});

$(function(){
    $('#commentside').keyup(function(){
        limitChars('commentside', 350, 'countdownside');
    })
});

$(function()
{
      var options = {
        convention: 'mm/dd/yyyy'
      };
    $('#date').datepicker();
});
function limitChars(textid, limit, infodiv)
{
    var text = $('#'+textid).val();
    var textlength = text.length;

    if(textlength > limit)
    {
        $('#' + infodiv).html(limit+' characters limit reached!');
        $('#'+textid).val(text.substr(0,limit));
        return false;
    }
    else
    {
        $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left');
        return true;
    }
}
