/*
 * @package WordPress
 * @subpackage Dereklam
 * @author: A. Kuzmanovski
 */
/*global  self */

jQuery.noConflict();

/**
 *
 */
function GetScrollY(){
    if (self.pageYOffset) // all except Explorer
    {
        return self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
    {
        return document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        return document.body.scrollTop;
    }
    return 0;
}

/**
 *
 */
function is_ie() {
    return (/msie/i).test(navigator.userAgent);
}

/**
 * @param obj
 */
function is_defined(obj) {
    return !((obj === null) || (typeof(obj) === undefined) || (typeof(obj) === "undefined"));
}

/**
 *
 */
var utils = {
        mouse: {x: 0, y: 0},
        debugging: true
};//var


//if(!window.console) {  
//    window.console = {  
//        log : function(str) {  
//          alert(str);  
//        }  
//    };  
//    // mehr JS Code...  
//    console.log("Hallo Welt!");  
//}  

/**
 *
 */
function _l() {
    //if (window.console !== undefined && window.console !== "undefined") {
     //   window.console.log( Array.prototype.slice.call(arguments) );
    //}
}

/**
 * Kopiert alle Eigenschaften von parent in child
 *
 */
function extend(child, parent) {
    var i;
    child = child || {};
    child.parent = parent;
    for (i in parent) {
        if (parent.hasOwnProperty(i)) {
            child[i] = parent[i];
        }
    }
    return parent;
}//func

/** Capture Mouse Moves
 */
jQuery(document).mousemove(function(event){
    utils.mouse.x = event.pageX;
    utils.mouse.y = event.pageY;
});//func

/** Prüfen, ob die Maus sich in einem Div befindet, abzüglich der Korrekturpunkte
 *
 * id: id of div
 * cl: Korrekturpunkte links
 * cr: Korrekturpunkte rechts
 * ct: Korrekturpunkte oben
 * cb: Korrekturpunkte unten
 */
utils.mouse_is_in_div = function(id,cl, cr, ct, cb) {
    var pos = jQuery(id).offset(),
        width = jQuery(id).width(),
        height = jQuery(id).height(),
        pad_left = parseInt(jQuery(id).css("padding-left"), 10),
        pad_right = parseInt(jQuery(id).css("padding-right"), 10),
        pad_top = parseInt(jQuery(id).css("padding-top"), 10),
        pad_bottom = parseInt(jQuery(id).css("padding-bottom"), 10);
    cl = cl || 0;
    cr = cr || 0;
    ct = ct || 0;
    cb = cb || 0;
    if (!pos) {
        return false;
    }   
    if ( (pos.left + cl) < utils.mouse.x) {
        if ( utils.mouse.x < (pos.left + width + pad_right + pad_left - cr )) {
            if (pos.top < utils.mouse.y) {
                if (utils.mouse.y < (pos.top + height + pad_bottom + pad_top )) {
                    return true;
                }
            }
        }
    }
    return false;
};//func

/**
 * jQuery Plugin
 * 
 * Image Preloader
 *
 */
function init_jQuery_Preloader(){
    
    var imgList = [],
         deactivated = false,
        useBrowserCache = false,
        load_fun  = function() {
            //alert("Upps")
        };
    jQuery.extend({
            preload: function(imgArr, option) {
            var setting = jQuery.extend({
                    init: function(loaded, total) {},
                    loaded: function(img, loaded, total) {},
                    loaded_all: function(loaded, total) {}
                }, option), total = imgArr.length, loaded = 0, i = 0, now= new Date();
            setting.init(0, total);
            if (total === 0) {
                setting.loaded_all(loaded, total);
            }
            load_fun = function(url) {
              _l("loaded "+url);
              loaded++;
              setting.loaded(url, loaded, total);
              if(loaded === total) {
                 //alert("ALL loaded");
                 setting.loaded_all(loaded, total);
                 
              }
            };
            for(i=0; i < imgArr.length; i++) {
               now= new Date();
               var url = useBrowserCache? imgArr[i] + "?t=" : imgArr[i] + "?t=" + now.getTime();
               if (deactivated) {
                  _l("deactivated " + url);

                   load_fun(url);
               } else {
                imgList[i] = jQuery("<img />").attr("src", url);
                _l("this: " + url);
                imgList[i].load(function(){load_fun(url);});
                } 
            }
        }
    });
}

init_jQuery_Preloader();
