function mycarousel_initCallback(carousel) {
    jQuery('#carouselPrev').bind('click', function() {
        carousel.prev();
        return false;
    });	
    jQuery('#carouselNext').bind('click', function() {
        carousel.next();
        return false;
    });
};

function checkDefault(form) {
    var success = true;
    $("#"+form+" input[default!=\"\"]").each(function() {
        if (this.value === $(this).attr('default')) {
            this.value = '';
            success = false;
        }
    });
    
    $("#"+form+" textarea[default!='']").each(function() {
        if (this.value === $(this).attr('default')) {
            this.value = '';
            success = false;
        }
    });
    
    return success;
}

function setDefault(form) {
    var success = true;
    $("#"+form+" input[type=text][default!=\"\"]").each(function() {
        if (this.value == '' && $(this).attr('default') !== undefined) {
            this.value = $(this).attr('default');
            success = false;
        }
    });
    
    $("#"+form+" textarea[default!=\"\"]").each(function() {
        if (this.value == '' && $(this).attr('default') !== undefined) {
            this.value = $(this).attr('default');
            success = false;
        }
    });
    
    return success
}


$(document).ready(function() {
    
    jQuery("#show_all").change(function(){
        var chk = jQuery(this).attr("checked");
        var action = 0;
        if(chk)
            action = 1;
 
        jQuery.ajax({
            type: "POST",
            url: "/udata/custom/setShowAll/"+action,
            success : function()
            {
                window.location.reload(true);
               						
            },
            error: function(jqXHR, textStatus, errorThrown){
                return false;            
            }
        });
    
    });
    
    jQuery( "#tabs" ).tabs();
    
    jQuery('.details-col .l-col ul li:odd').addClass('odd');
    
    $('a[rel=lightbox]').lightBox();
    
    $("input[default!=\"\"]").blur(function() {
        if (this.value === '' && $(this).attr('default') !== undefined) {
            this.value = $(this).attr('default');
        }
    }).focus(function() {
        if (this.value === $(this).attr('default')) {
            this.value = '';
            success = false;
        }
    });
    
    $("textarea[default!='']").blur(function() {
        if (this.value === '' && $(this).attr('default') !== undefined) {
            this.value = $(this).attr('default');
        }
    }).focus(function() {
        if (this.value === $(this).attr('default')) {
            this.value = '';
            success = false;
        }
    });    

    $("form").submit(function() {
        checkDefault($(this).attr('id'));
        return true;
    })
	
    setDefault('comments_form');
    
    jQuery(".piclist").jcarousel({
        wrap: 'null',
        scroll: 1,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});
