$().ready(function() {
    
    $('.alert,.notify_green, .notify_red').show(500).delay(4000).hide(500);
    
    $(".add_new_url").click(function() {
        $('.alert, .notify_green, .notify_red').hide();
	});
    
    $('.popup').fadeTo('fast', 0.8, function() {
      // Animation complete.
    }).animate({ left: "360px" }, 1000 );
    
    $(".close").click(function() {
        $('.popup').hide();
	});
    
    $("#submit").click(function() {
        
        $(this).attr("disabled", true);
        $(this).css("background", "#999");
        
        $(this).submit();
        $(this).removeAttr("disabled");
    
	});
    
    $('.thumbnails ul li ul').hide();
    $('.thumbnails ul li').mouseover(function() {
      $(this).children().show();
    });
    $('.thumbnails ul li').mouseout(function() {
      $('.thumbnails ul li ul').hide();
    });
    
    $('#checkinLbl').html('Check-In Date');
    $('#checkoutLbl').html('Check-Out Date');
    $('#accubookSearchButton input').val('FIND ROOMS');
    
    $('#checkoutWrapper').css("width", "960px");
    
	$("#contact_name").keyup(function(){
	   
        var value = $(this).val();		  
		var loadUrl = '/admin/dashboard/generate_uri/' + value;

		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
                $('#username').val(responseText);
			},
			"html"
		);

	});
    
    if(jQuery().fancybox) {
    	$(".fancybox").fancybox({
    		'width'				: '100%',
    		'height'			: '100%',
    		'autoScale'			: false,
    		'transitionIn'		: 'none',
    		'transitionOut'		: 'none',
    		'type'				: 'iframe'
    	});
      
    	$(".fancybox_gallery").fancybox({
    		'transitionIn'	:	'fade',
    		'transitionOut'	:	'fade',
    		'speedIn'		:	600, 
    		'speedOut'		:	200, 
    		'overlayShow'	:	false
    	});
        
    	$(".fancybox_small").fancybox({
    		'width'				: 640,
    		'height'			: 480,
    		'type'				: 'iframe'
    	});
        
    	$(".fancybox_extra_small").fancybox({
    		'width'				: 640,
    		'height'			: 280,
    		'type'				: 'iframe'
    	});
   }
   
   if(jQuery().customFileInput) {
        $('.upload').customFileInput();
   }
    
    if(jQuery().datepicker) {
        
    	$('.datepicker').datepicker({
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
    	});
     }
     
    if(jQuery().easySlider) {
     
    	$(".gallery_slider").easySlider({
    		auto: true, 
    		continuous: true, 
            pause: 7000,  
            speed: 1500, 
            numeric: false,  
            prevId: 'galPrev',
            nextId: 'galNext',
            nextText: 'Next',
            prevText: 'Prev', 
            controlsShow: false, 
    	});
        
    }
     
    if(jQuery().sortable) {
    
        
        // Images
    	$(".thumbnails ul").sortable( { 
    	   
            opacity: 0.5, 
            cursor: 'move', 
            update: function() {

                var order = $(this).sortable("serialize");
                var loadUrl = $(this).attr('id');
                
                $.post( loadUrl, order, function(theResponse){
    				//location.reload();
    			});
    		}
    	});
        
        // Tables
        $(".cmstable tbody.cmstable_content").sortable({
                         
            handle: ".order", 
            axis: "y", 
            placeholder: "highlight", 
            opacity: 0.7, 
            update: function() {
                
                var order = $(".cmstable_content").sortable("serialize") ;
                var loadUrl = $(this).attr('id');
                
                $.post( loadUrl, order, function(theResponse){
                    //location.reload();
    			});
    		}
        });
            
        //$(".cmstable tbody.cmstable_content").disableSelection();
        
    }
    
    if(jQuery().corner) {
        // Rounded Corners
        $('.event_listing').corner("8px");
        $('.back_button').corner("8px");
    }

    $('#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('');
    });
    
     if(jQuery().passStrength) {
        
        $("#password").passStrength({
        	userid:	"#username", 
            baseStyle: 'password_result',
        });
        
     }

    if( $('#password').val() != '' ){
        $(".hide_password").hide();
        $(".change_password").show();
    }else{
        $(".change_password").hide();
    }
    
	$(".show_password").click(function() {
	    $(".hide_password").hide();
		$(".change_password").show();
	});
    
	$(".password_cancel").click(function() {
	    $(".hide_password").show();
        $('#password').val('');
        $('#confirm_password').val('');
        $(".password_result").hide();
		$(".change_password").hide();
	});
    
	$.ajaxSetup ({  
		cache: false  
	});
    
    $('.action_delete').click(function(event) {
        
        $('.alert').hide();
        
        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){
                    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){
                    location.reload();
    			},
    			"html"
    		);
            
            
        }else{
            
        }
        
        return false;
    })
    	
});
