/**
 * Common javascript method and definitions
 * 
 */

function jquery_loaded()
{
    // If jQuery library is loaded return true
    if (typeof(jQuery) != "undefined") { return true; }
    
    return false;
}


jQuery(document).ready(function(){

    // Create span element
    $span = jQuery("<span>").addClass('ui-icon ui-icon-help');

    jQuery(".question-mark").html($span);

    jQuery(".question-mark").click(function(e) { e.preventDefault(); });

    /*
    jQuery( ".show-window" ).mousemove(function(e){

        // Hide all other windows
        jQuery(".window-to-show").hide();

        var window =  jQuery(this).next(".window-to-show").offset({ top: e.pageY+10, left: e.pageX+10 });

        // Fix to do not blink images
        window.show().offset({ top: e.pageY+10, left: e.pageX+10 });

    }).mouseleave(function(e){

        var keep_window = jQuery(this).hasClass('keep-it');

        // Hide all other windows
        if ( ! keep_window)
        {
            jQuery(".window-to-show").hide();
        }

    });

    jQuery( ".window-to-show" ).mouseleave(function(e){
        // Hide all other windows
        jQuery(".window-to-show").hide();
    });
    */
   
    // FAST START DEFINITION
    jQuery(".fast-start").mouseenter(function() {
            if ( ! jQuery(this).hasClass("static"))
                jQuery(this).find("ul.actions").slideDown("fast");
    });
    jQuery(".fast-start").mouseleave(function() {
            if ( ! jQuery(this).hasClass("static"))
                jQuery(this).find("ul.actions").slideUp("fast");
    });
});


function confirmExit() { 
    if (needToConfirm) return lang.discard_changes;
}

function disableConfirmation() { needToConfirm = false; }

function secondsToHms(d) {
	d = Number(d);
	var h = Math.floor(d / 3600);
	var m = Math.floor(d % 3600 / 60);
	var s = Math.floor(d % 3600 % 60);
	return ((h > 0 ? h + ":" : "") + (m > 0 ? (h > 0 && m < 10 ? "0" : "") + m + ":" : "0:") + (s < 10 ? "0" : "") + s);
}

function pause(millisecondi) {
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;

    while(true) {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}

function getBrowserSize()
{
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        browserWidth = window.innerWidth;
        browserHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        browserWidth = document.documentElement.clientWidth;
        browserHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        browserWidth = document.body.clientWidth;
        browserHeight = document.body.clientHeight;
    }

    return [browserWidth, browserHeight];
}

