$().ready(function() {
    
    $(window).scroll(function () { 
        
        if( $(window).scrollTop() > 80 ){
            $('#footer').fadeOut();
            $('#up').show();
            
            //$('body').css("cursor", "pointer");
            $("#up").click(function() {
                $(window).scrollTop(0);
                $('body').css("cursor", "auto");
    	    });
            
        }else{
            $('#footer').fadeIn();
            $('#up').hide();
        }
      
    });
    
    $('.question div').hide();
    $('.question').click(function(){
      $(this).next('div').toggle();
   });
    
    header_height = $('#main_nav').height() + 37;
    content_height = $('#content').height();
    footer_height = $('#footer').height();
    body_height = $(window).height();
    
    body_height = (header_height + content_height) + $(window).height();
    
    $('body').css("height", body_height);
    
    $('.alert').show(500).delay(6000).hide(600);
    
    $(".add_new_url").click(function() {
        $('.alert').hide();
	});
    
    $("#submit").click(function() {
        
        $(this).attr("disabled", true);
        $(this).css("background", "#999");
        
        $(this).submit();
        $(this).removeAttr("disabled");
    
	});
    
	$("#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'				: '70%',
    		'height'			: '75%',
    		'autoScale'			: false,
    		'transitionIn'		: 'none',
    		'transitionOut'		: 'none',
    		'type'				: 'iframe'
    	});
      
    	$(".fancybox_gallery").fancybox({
    		'transitionIn'	:	'fade',
    		'transitionOut'	:	'fade',
    		'speedIn'		:	600, 
    		'speedOut'		:	200, 
    		'overlayShow'	:	false
    	});
   }
    
    if(jQuery().datepicker) {
        
    	$('.datepicker').datepicker({
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
    	});
        
     }
     
    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");
        $('.news_listing').corner("8px");
        $('.back_button').corner("8px");
        $('.bg_green').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('');
    });
    
     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;
    })
    	
});
