$(document).ready(function() {
    //$('.rounded').corner("round 5px");

    // clear out search box when clicked
    $('#home-search-input, #small-search').bind('click',
                                 function() {
                                     $(this).val('');
                                 });



    // setup confirmation dialogs for all delete controls
    $('.delete').bind('click', function() { return confirm('Are you sure you want to delete this?'); });


    // Make logos clickable
    $('#logo-small').bind('click', function() { window.location = homeurl });

    // setup swfir object
    try {
         var sir = new swfir();

        sir.specify("border-width", "10");
        sir.specify("border-radius", "15");
        sir.specify("border-color", "fff");
        sir.specify("rotate","-5");
        sir.specify("shadow-blur", "15");
        sir.specify("src", baseurl + "/swfir/swfir.swf");
        sir.specify("maxWidth", "12");


        sir.swap(".swfir");
    } catch(junk) {}

    //Categories management
    removeCategory = function(){
        $(this).parents("tr").remove();
		new_content_check = true;
        if($("#selectedBusinessCategory tr").length == 0){
            $("#selectedBusinessCategory:visible").hide();
        }
        return false;
    };
	//site pages
	new_content_check = false;
	checkNewContent = function(){
		if(new_content_check){
			if(confirm("Your changes have not been saved, do you wish to proceed?")){
				return true;
			}else{
				return false;
			}
		}
	}
    var category_counter = $("#selectedBusinessCategory tr").length;
    if($("#selectedBusinessCategory tbody tr").length > 0 ){
        $("#selectedBusinessCategory:hidden").show();
        $("#selectedBusinessCategory .removeCategory").bind("click",removeCategory);
    }
    $("#addCategory").click(function(){
        var selected_text = $("#businessCategory").find("option:selected").text();
        var selected_value = $("#businessCategory").find("option:selected").val();
        if($("#selectedBusinessCategory tbody tr").length >= 3){
            alert("Business categories is limited to 3");
            return false;
        }
        if($("#selectedBusinessCategory tbody tr").not("select").contains(selected_text).length == 0 && $("#selectedBusinessCategory tbody tr").length < 3){
            $("<tr><td>"+selected_text+"</td><td> <a class=\"removeCategory\" href=\"#\">[Remove Category]</a><input type=\"hidden\" name=\"selectedCategories[" + (category_counter+1) + "]\" value=\""+ selected_value +"\" ></td></tr>").appendTo($("#selectedBusinessCategory tbody"));
            $("#selectedBusinessCategory .removeCategory:last").bind("click",removeCategory);
            $("#selectedBusinessCategory:hidden").show();
			new_content_check = true;
            category_counter++;
        }else{
			alert(selected_text+ " already exists in your categories");
		}
        return false;
    })
});