$(function() {
    // loading additional libraries if needed
    try {var is_json = JSON != undefined;} catch( e ) {	$.getScript('/js/json.js'); }
    
    $('.actionMenu').click(function(){
        $('#showMenu').toggle();
    })
    $('.next').click(function(){
    
    	$( this ).next('.answer').toggle();

     return false;
    })

    $(".profile_column").sortable({
        connectWith: '.profile_column',
        opacity:0.8,
        handle:'h1',
	update: function(event, ui) {
	    var blocks_configuration = new Object();
	    $('.profile_column').each( function( index ) {
		var col_name = $(this).attr('id');
		
		$('#'+col_name+' .base_content').each(function(){

		    if( blocks_configuration[ col_name ] == null ) {
			blocks_configuration[ col_name ] = new Array();
		    }
		    var block_name = $(this).attr('id');
		    blocks_configuration[ col_name ].push(block_name);
		});		
	    });

	    $.cookie(
		'profile_block_settings',
		JSON.stringify(blocks_configuration),
		{ expires: 366}
	    );
	    
	}


    });
    $(".small .h1_icon").click(function() {
        $(this).toggleClass("minus").toggleClass("plius");
        $(this).parents(".base_content:first").find(".drag_content").toggle();
    });
    $(".profile_column").disableSelection();
    
    $('#mycarousel').jcarousel();
    
    $('#mycarousel li a').lightBox();

    $('.auto-submit-star').rating({
      callback: function(value, link){
        $.get('<?php echo $Link->help("vertinti/")?>'+value);
      }
    });


	$('.clean-on-click').click( function( event, ui ) {
		
		var $this = $( this );
		
		if ( $this.val() == $this.attr('title') ) {
			$( this ).val('');
			$( this ).removeClass( 'grey' );
		}
		
	} );

	$('.clean-on-click').blur( function( event, ui ) {
		
		var $this = $( this );
		
		if ( $this.val() == '' ) {		
			$this.addClass( 'grey' );	
			$this.val( $this.attr('title') );			
		}
		
	} );
	
	$('.confirm-delete').click( function( event, ui ) {
		
		return confirm('Ar tikrai norite iðtrinti?');
		
	} );
    $('.dialog').dialog( {
        autoOpen: false,
        modal: true,
        resizable: false,
        width: 640
    } );
    $('.dialog-link').click( function( event, ui ) {

        $('#' + $( this).attr('id') + '-dialog' ).dialog( 'open' );
        return false;

    } );    
    
    $('.datepicker').datepicker( { first: 1, dateFormat: "yy-mm-dd" });
    
});


function loadUrlAndReloadPage( url ) {
    $.get(url, function(data) {
      window.location.reload();
    });
}

function confirmUrlAndReload( url, message ) {
    if( confirm( message ) ) {
	$.get(url, function(data) {
	  window.location.reload();
	});
    }
}
