$().ready(function() {

    if(jQuery().tooltip) {
        $("input[title]").tooltip();
        $("select[title]").tooltip();
    }
    
    $("input:visible:enabled:first").focus();
    $("select:visible:enabled:first").focus();
    
    $('.alert').show(500).delay(4000).hide(500);
    
    if(jQuery().datepicker) {
        
    	$('.datepicker').datepicker({
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
    	});
        
     }
     
    if(jQuery().slidorion) {
        $('#slidorion').slidorion();
    }
    if(jQuery().accordion) {
        $("#news_accordion").accordion();
    }
     
    if(jQuery().easySlider) {

    	$(".news_slider").easySlider({
    		auto: true, 
    		continuous: true, 
            pause: 1500,  
            speed: 1000, 
            numeric: false, 
            prevText: '<img src="/application/views/templates/default/images/arrow_left.gif" />',
            nextText: '<img src="/application/views/templates/default/images/arrow_right.gif" />',
            prevId: 'newsPrev', 
            nextId: 'newsNext'
    	});
        
    	$(".community_slider").easySlider({
    		auto: true, 
    		continuous: true, 
            pause: 3000,  
            speed: 1000, 
            numeric: false, 
            prevText: '&laquo; Previous',
            nextText: 'Next &raquo;',
            prevId: 'commPrev', 
            nextId: 'commNext'
    	});
     
    	$(".gallery_slider").easySlider({
    		auto: true, 
    		continuous: true, 
            pause: 1500,  
            speed: 1000, 
            numeric: false, 
            prevId: 'galPrev',
            nextId: 'galNext',
            nextText: 'Next Image',
            prevText: 'Previous Image'
    	});
        
    }
     
    if(jQuery().sortable) {
    	$(".thumbnails ul").sortable( { opacity: 0.5, cursor: 'move', update: function() {
    			
                var order = $(this).sortable("serialize") ;
                
                var loadUrl = $(this).attr('id');
                
                //alert(order);
                
                $.post( loadUrl, order, function(theResponse){
    				location.reload();
    			});
    		}
    	});
    }
    
    if(jQuery().corner) {
        // Rounded Corners
        $('.event_listing').corner("8px");
        $('.news_listing').corner("8px");
        $('.news_slider').corner("8px");
        $('.back_button').corner("8px");
        $('.tickets').corner("8px");
        $('.tickets .button').corner("6px");
        $('.notify_green').corner("8px");
        $('.notify_red').corner("8px");
        $('.terms').corner("8px");
    }
    
    //$('#footer li').first().css('padding-left', '0px');
    $('#main_nav li').last().css('border', 'none');
    
    $("#upload_image").show();
    $(".image_uploading").hide();
	$("#upload_image").click(function() {
	    $(".image_uploading").show();
        $("#upload_image").hide();
	});
    
    $('#change_user_id').change(function() {
    
        alert('Importing advertisers default contact details.');
        window.location = $(this).attr('title')+$(this).val();
        return false;
    });
    
	$(".thumbs, .clicks").click(function() {
		window.location=$(this).find("a").attr("href");return false;
	});
    
	$(".newsletter_form").click(function() {
		window.location=$(this).find("a").attr("href");return false;
	});
    
    $('#edit_user_id').change(function() {
        
    });
    
    $('#search, .per_line, .search_button').focus(function() {
      $(this).val('');
    });

    $(".change_password").hide();
	$(".show_password").click(function() {
	    $(".hide_password").hide();
		$(".change_password").show();
	});
    
	$(".password_cancel").click(function() {
	    $(".hide_password").show();
		$(".change_password").hide();
	});
    
	$.ajaxSetup ({  
		cache: false  
	});
    
    $('.action_delete').click(function(event) {
        var answer = confirm('Are you sure you want to complete this task?');
        
        if (answer){
                
            var loadUrl = $(this).attr('id');
        
    		$.get(
    			loadUrl,
    			{language: "php", version: 5},
    			function(responseText){
                    alert(responseText);
                    location.reload();
    			},
    			"html"
    		);
            
            
        }else{
            
        }
        
        return false;
    }) 
    
    $('.action_status').click(function(event) {
        var answer = confirm('Are you sure you want to change this status?');
        
        if (answer){
                
            var loadUrl = $(this).attr('id');
        
    		$.get(
    			loadUrl,
    			{language: "php", version: 5},
    			function(responseText){
                    alert(responseText);
                    location.reload();
    			},
    			"html"
    		);
            
            
        }else{
            
        }
        
        return false;
    })

    if( ($("#payment_type").val() != 'payment') ){
  	         $("#amount").val('0.00');
             $("#amount").attr('disabled', 'disabled');
    }

	$("#payment_type").change(function(){
       
       var id = $(this).val(); 
       if( (id === 'free') || (id === 'donation') ){
  	         $("#amount").val('0.00');
             $("#amount").attr('disabled', 'disabled');
       }else{
            $("#amount").val('');
            $("#amount").removeAttr('disabled');
            $("#amount").focus();
       }
        
	});
    	
});
