/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

// Pause Actions
pauseForAction = null;

waitForAction = function (func, time) {
    pauseForAction = setTimeout (func, time);   
}

cancelWaitForAction = function (func) {
    clearTimeout(pauseForAction);
}


// Preload
var preload = {
    
    tempTarget : [],
    
    init : function(){

    },

    loadimage : function(images, targets, w, h){
        var image = null;
        var target= null;
        var self  = this;
        
        for(var i = 0; i< images.length; i++){
            image = images[i];
            target= targets[i];

            $('#'+target).append('<div id="preloaderText">LOADING</div><div id="preloaderAnimEmbed"><div id="preloaderAnim"></div><div/>');
            var pw = ($('#'+target).width() / 2) - 60;
            var ph = ($('#'+target).height() / 2) + 10;
            
            $('#preloaderText').css({
                'height'        :'20px',
                'width'         :'120px',
                'position'      :'absolute',
                'margin-top'    : ph-20,
                'margin-left'   : pw,
                'text-align'    :'center',
                'font-family'   :'standard0758',
                'color'         :'black',
                'font-size'     :'8px'
            })
            
            $('#preloaderAnimEmbed').css({
                'height'        :'1px',
                'width'         :'120px',
                'position'      :'absolute',
                'background'    :'#efefef',
                'margin-top'    : ph,
                'margin-left'   : pw
            });
            
            $('#preloaderAnim').css({
                'height'        :'1px',
                'width'         :'0px',
                'position'      :'absolute',
                'background'    :siteMainColor
            });
            
            $('#preloaderAnim').delay(1000).animate({'width':'120px'},800,'easeInSine');
            
            this.tempTarget.push(target);
            
            $('<img src="'+image+'" data-tgt="'+target+'" alt="'+image+'"/>').one('load',function(){
                    var tgt = $(this).data("tgt");  
                    $('#'+tgt).empty();
                    $('#'+tgt).append($(this));
                    $('#'+tgt+' img').css({'width':w, 'height':h});
            }).each(function(){
            	if(this.complete){
            		$(this).trigger("load");	
            	}	
            });
        }
    }
};




// Serialize JSON 
(function($){
    $.fn.serializeJSON=function(){
        var json={};
        jQuery.map($(this).serializeArray(),function(n,i){
            
            if(n['name'].indexOf('[]')){
                n['name'] = n['name'].split('[')[0];
            }
            
            if (json[n['name']]) {
                if (!json[n['name']].push) {
                    json[n['name']] = [json[n['name']]];
                }
                json[n['name']].push(n['value'] || '');
            } else {
                json[n['name']] = n['value'] || '';
            }
        });
        return json;
    };
})(jQuery);

