var mouse_is_inside_menu = false;

$(document).ready(function(){
    // see http://www.thesitewizard.com/archive/framebreak.shtml
    // for an explanation of this script and how to use it on your
    // own website

	setOverlaySize();
	setLogin();
	setLoaderBig();
	setForgotPassword();
	setSharePosition();
	setAddReviewForm();
	setErrorContainerPos();
	setInformHeader();
	setUserMenuPos();
	setCroppingPos();

	setNewWindowAction();	
	
	if( jQuery.isFunction(jQuery.fn.addCaptions) ){
		// function exists, so we can now call it
	    $('body').addCaptions({
	        selector: 'img.cdentcaption'
	    });
	}

	$('#overlay-screen').bind('click', function(){closeLogin();});
	
    if (top.location != location) {
      top.location.href = document.location.href ;
    }

    $('.user-menu-holder').hover(function(){ 
        mouse_is_inside_menu=true;
        jQuery(document).stopTime('menu-hide');
    }, function(){ 
        mouse_is_inside_menu=false; 
        jQuery(document).everyTime(3000, 'menu-hide', function(){
        	if(! mouse_is_inside_menu) $('.user-menu-holder').hide();
        	jQuery(document).stopTime('menu-hide');
    	});        
    });

    $("body").mouseup(function(){ 
        if(! mouse_is_inside_menu) $('.user-menu-holder').hide();
    });
    
    
	$('.searchtext').keyup(function() {

			getDataOnTimeout();
		  
		});
	
	$('#search-video-field').keyup(function(e) {

		if (e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) {
			getVideoLibrarySearchDataOnTimeout();
		}
		
	  
	});	
	
	$('.searchprofessions').click(function() {

		  getPaidFeaturedDentists();
		  getStandardDentists();
		  
		});	
	
	$('#city').change(function() {

		  getPaidFeaturedDentists();
		  getStandardDentists();
		  
		});	
	
	$('#country').change(function() {
		  $('#city').val('');
		  getCities();
		  getPaidFeaturedDentists();
		  getStandardDentists();
		  
		});	
	
	$('.zip').keyup(function() {

		getDataOnTimeout();
	  
	});	
	
	$('#username').keyup(function() {

		checkUsernameOnTimeout();
	  
	});	
	
	$('#mail').blur(function() {

		checkEmailOnTimeout();
	  
	});	

	$('#headerSearch').keyup(
			function (e)
			{
				if (e.keyCode == 13) {
					window.location = baseUrl+'/search/' + $('#headerSearch').val();
				}
			}
	);
	
    $('#confirmmail').blur(function() {

        checkConfirmEmailOnTimeout();

    });
    
	$('.arrow-down').click(function(){
		$('.language-container').slideDown('fast');
		slideUpOnTimer();
		});

	$('#select-country').change(function() {
		  // $('#city').val('');
		  getProvinces();
		  getLanguages();
		});	
	
	$(document).click(function(){
		$('.video-library-search-result').hide();
        $('.language-select').slideUp(300);
	});
	
	$("#login-field").draggable();
	$("#forgot-password").draggable();
	$(".error-container").draggable();
	$("#reply-container").draggable();
	$("#reply-container-form").draggable();
//	$("#filedetails").draggable();
	
	
    var options = { 
            target:        '#step',   // target element(s) to be updated with server response  
            success:       showResponse  // post-submit callback 
     
            // other available options: 
            //url:       url         // override for form's 'action' attribute 
            //type:      type        // 'get' or 'post', override for form's 'method' attribute 
            //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
            //clearForm: true        // clear all form fields after successful submit 
            //resetForm: true        // reset the form after successful submit 
     
            // $.ajax options can be used here too, for example: 
            //timeout:   3000 
        }; 
     
        // bind to the form's submit event 
        $('#create-account').submit(function() { 
            // inside event callbacks 'this' is the DOM element so we first 
            // wrap it in a jQuery object and then invoke ajaxSubmit 
        	showLoaderBig();
            $(this).ajaxSubmit(options); 
     
            // !!! Important !!! 
            // always return false to prevent standard browser submit and page navigation 
            return false; 
        }); 	
        function showResponse(responseText, statusText, xhr, $form)  { 
        	hideLoaderBig();
            // for normal html responses, the first argument to the success callback 
            // is the XMLHttpRequest object's responseText property 
         
            // if the ajaxSubmit method was passed an Options Object with the dataType 
            // property set to 'xml' then the first argument to the success callback 
            // is the XMLHttpRequest object's responseXML property 
         
            // if the ajaxSubmit method was passed an Options Object with the dataType 
            // property set to 'json' then the first argument to the success callback 
            // is the json data object returned by the server 
      
        }

        /**
        * Written by Rob Schmitt, The Web Developer's Blog
        * http://webdeveloper.beforeseven.com/
        */
        /**
        * The following variables may be adjusted
        */
        //var inactive_color = '#cccccc'; // Colour of default text
        //var active_color = $("input.default-value").css("color"); // Colour of user provided text

        /**
        * No need to modify anything below this line
        */
/*
        var default_values = new Array();
        $('input[type=text].default-value').each(function(index) {
        	$(this).css("color", inactive_color);
            $(this).focus(function() {
            	var value = this.value;
            	if(value.length<=0){
            		value = this.title;
            	}

                if (!default_values[this.id]) {
                  default_values[this.id] = value;
                }

                if (value == default_values[this.id]) {
                  this.value = '';
                  this.style.color = active_color;
                }
                $(this).blur(function() {
                  if (this.value == '') {
                    this.style.color = inactive_color;
                    this.value = default_values[this.id];
                  }
                });
              });
        });
*/       
        
});
