Array.prototype.indexAt= function(what){
	var L= this.length;
	var i= 0;
	while(i< L){
		if(this[i]=== what) return i;
		++i;
	}
	return -1;
}

function isIntegerKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;
}


$(document).ready(function(){
   $('.zeednax_elem').each(function(i,elem){
    eval($(elem).attr('zeednax'));
    })
});



$(document).ready(function(){

$("#loading").bind("ajaxSend", function(){
   $('#loading').show()
 }).bind("ajaxComplete", function(){
   $('#loading').hide()
 });
});


/*
Evaluate the comment inside the element specified by elem_selector paramater to parsed HTML code 
*/
function removeCommentTag(elem_selector){
    comment_nodes=$(elem_selector).contents().filter(
        function() {
            return this.nodeType == 8;
        });
    try{ /* IE comment element has innerHTML property, but firefox comment element has textContent property instead */
        var temp_str = comment_nodes[0].innerHTML;
        temp_str = temp_str.replace('<!--', '').replace('-->', '');
        $(elem_selector).html(temp_str);
    }catch(e){
        $(elem_selector).html(comment_nodes[0].textContent);
    }
}

/*
This function is used to show any DOM element as a dialog with animation during showing/hiding
e.g. We have <div id="dialog">Hello Word</div>
We can invoke: showDialog('dialog') to show the dialog
and showDialog('dialog', false) to hide it
*/
function showDialog(name,show, conf){
    if(show ==  undefined)
        show=true
    if (conf== undefined)
        conf = { modal: true, resizable: false }
        
    /* Disable scrolls in the body when the dialog open and enable them when it closes to prevent annoying body overflow */ 
    conf.open = function(event, ui) { /*$('body').addClass('zc_hidebodyscroll');*/ };
    conf.close = function(event, ui) {$('body #'+name).remove(); /*$('body').removeClass('zc_hidebodyscroll'); */};

    if(show){
        $('#'+name).dialog(conf);
        $('#'+name).dialog('open').fadeIn('slow');
    }
    else{
        $('#'+name).dialog().fadeOut('normal', function(){$('#'+name).dialog('close'); $('#'+name).dialog('destroy'); });
    }
}

/* Show informative message */
function showInfoMessageBox(msg, timeout ,conf, callback){
    /* conf example: {modal:true, title:'Info', width:'auto', height:'auto', resizable: false}*/
    nodeText = '<div id="z_info_temp_dialog_box" class="hidden">' + '</div>';
    elem = $(nodeText);
    elem.html(msg);
    $('body').append(elem);
    
    $('body #z_info_temp_dialog_box').html()
    if (conf === undefined)
        conf = { modal: true, resizable: false }
        
    conf.open = function(event, ui) {  };
    conf.close = function(event, ui) {$('body #z_info_temp_dialog_box').remove();
                                            if (!(callback === undefined))
                                                callback.call(this);
                                            };
    $('#z_info_temp_dialog_box').dialog(conf);
    $('#z_info_temp_dialog_box').dialog('open').fadeIn('slow');
    
    if(timeout > 0){
        var funcText= "$('#z_info_temp_dialog_box').dialog().fadeOut('normal', function(){$('#z_info_temp_dialog_box').dialog('close'); $('#z_info_temp_dialog_box').dialog('destroy'); })";
        
        var t=setTimeout(funcText, timeout);
    }
}

/*
scrollWin is used to scroll the window top to a certain DOM element.
*/
function scrollWin(node){
    $('html, body').animate({
        scrollTop: node.offset().top
    }, 1000);
}

/*
Used internally by flex
*/
function getBaseUrl(){
    return document.location.host;
}





/*
jQuery plugin to upload many js files dynamically
refer to: http://code.google.com/p/jquery-loadscript/  for examples
*/

(function($) {

var scripts = [];

function loadScript(url, callback, context) {

	var script = scripts[url] || (scripts[url] = {
		loaded    : false,
		callbacks : []
	});

	if(script.loaded) {
		return callback.apply(context);
	}

	script.callbacks.push({
		fn      : callback,
		context : context
	});

	if(script.callbacks.length == 1) {
		$.ajax({
			type     : 'GET',
			url      : url,
			dataType : 'script',
			cache    : true,
			success  : function() {
				script.loaded = true;
				$.each(script.callbacks, function() {
					this.fn.apply(this.context);
				});
				script.callbacks.length = 0;
			}
		});
	}

}

$.requireScript = function(url, callback, context, options) {

	if(typeof options === 'undefined' && context && context.hasOwnProperty('parallel')) {
		options = context;
		context = window;
	}

	options = $.extend({ parallel : true }, options);

	if(!$.isArray(url)) {
		return loadScript(url, callback, context);
	}

	var counter = 0;

	// parallel loading
	if(options.parallel) {
		return $.each(url, function() {
			loadScript(this, function() {
				if(++counter == url.length) {
					callback.apply(context);
				}
			});
		});
	}

	// sequential loading
	(function() {
		if(counter == url.length) {
			return callback.apply(context);
		}
		loadScript(url[counter++], arguments.callee);
	})();

};

$.requireScript.registerLoaded = function(url) {
	$.each($.makeArray(url), function() {
		(scripts[url] || (scripts[url] = {})).loaded = true;
	});
};

})(jQuery);





(function($){
/*
 * includeMany 1.2.1
 *
 * Copyright (c) 2009 Arash Karimzadeh (arashkarimzadeh.com)
 * Licensed under the MIT (MIT-LICENSE.txt)
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Date: Nov 11 2009
 */
$.chainclude = function(urls,finaly){
	var onload = function(callback,data){
						if(typeof urls.length!='undefined'){
							if(urls.length==0)
								return $.isFunction(finaly)
											?finaly(data)
											:null;
							urls.shift();
							return $.chainclude.load(urls,onload);
						}
						for(var item in urls){
							urls[item](data);
							delete urls[item];
							var count = 0;
							for(var i in urls)
								count++;
							return (count==0)
										?$.isFunction(finaly)?finaly(data):null
										:$.chainclude.load(urls,onload);
						}
					}
	$.chainclude.load(urls,onload);
};
$.chainclude.load = function(urls,onload){
	if(typeof urls=='object' && typeof urls.length=='undefined')
		for(var item in urls)
			return $.include.load(item,onload,urls[item].callback);
	urls = $.makeArray(urls);
	$.include.load(urls[0],onload,null);
};
$.include = function(urls,finaly){
	var luid = $.include.luid++;
	var onload = function(callback,data){
						if($.isFunction(callback))
							callback(data);
						if(--$.include.counter[luid]==0&&$.isFunction(finaly))
							finaly();
					}
	if(typeof urls=='object' && typeof urls.length=='undefined'){
		$.include.counter[luid] = 0;
		for(var item in urls)
			$.include.counter[luid]++;
		return $.each(urls,function(url,callback){$.include.load(url,onload,callback);});
	}
	urls = $.makeArray(urls);
	$.include.counter[luid] = urls.length;
	$.each(urls,function(){$.include.load(this,onload,null);});
}
$.extend(
	$.include,
	{
		luid: 0,
		counter: [],
		load: function(url,onload,callback){
			if($.include.exist(url))
				return onload(callback);
			if(/.css$/.test(url))
				$.include.loadCSS(url,onload,callback);
			else if(/.js$/.test(url))
				$.include.loadJS(url,onload,callback);
			else
				$.get(url,function(data){onload(callback,data)});
		},
		loadCSS: function(url,onload,callback){
			var css=document.createElement('link');
			css.setAttribute('type','text/css');
			css.setAttribute('rel','stylesheet');
			css.setAttribute('href',''+url);
			$('head').get(0).appendChild(css);
			$.browser.msie
				?$.include.IEonload(css,onload,callback)
				:onload(callback);//other browsers do not support it
		},
		loadJS: function(url,onload,callback){
			var js=document.createElement('script');
			js.setAttribute('type','text/javascript');
			js.setAttribute('src',''+url);
			$.browser.msie
				?$.include.IEonload(js,onload,callback)
				:js.onload = function(){onload(callback)};
			$('head').get(0).appendChild(js);
		},
		IEonload: function(elm,onload,callback){
			elm.onreadystatechange = 
					function(){
						if(this.readyState=='loaded'||this.readyState=='complete')
							onload(callback);
					}
		},
		exist: function(url){
			var fresh = false;
			$('head script').each(
								function(){
									if(/.css$/.test(url)&&this.href==url)
											return fresh=true;
									else if(/.js$/.test(url)&&this.src==url)
											return fresh=true;
								}
							);
			return fresh;
		}
	}
);
//
})(jQuery);





/***********************
    Humanize Date
************************/

(function($) {
	$.fn.cuteTime = function(options) {
        var settings = $.extend(
            {many_seconds:'seconds ago',one_minute:'a minute ago',many_minutes:' minutes ago',one_hour:'one hour ago',many_hours:'hours ago',yesterday:'yesterday at',many_days:'days ago at'}
	        ,options);
        var self = this;
		humanizeDate();
		return this;

		function humanizeDate(){
    	   self.each(function(){
    	        var other_time = parseDate( parseInt( $(this).attr('date_value') ) );
    			if (other_time == undefined || other_time==null)
    			 other_time = parseDate($(this).html());
    			var right_now = new Date().getTime();
    			if ( !( other_time==null || other_time==undefined || isNaN(other_time.valueOf()) ) ){
    			     $(this).attr('date_value',other_time.getTime());
    			     interval = right_now -other_time;
    			     humanized_time = other_time.toLocaleString();
    			     if( interval>0){
    			         if (interval < 1000*60) /*less than one minute */
    			             humanized_time=Math.floor(interval/1000) +' '+settings.many_seconds;
    		             else if (interval < 1000*60*2) /*one minute */
    			             humanized_time=settings.one_minute;
    		             else if (interval < 1000*60*60) /* many hours */
    			             humanized_time=Math.floor(interval/1000/60)+' '+settings.many_minutes;
    		             else if (interval < 1000*60*60*2)/* one hour ago */
    			             humanized_time=settings.one_hour;
    		             else if (interval < 1000*60*60*24)/* many hour ago */
    			             humanized_time=Math.floor(interval/1000/60/60)+' '+settings.many_hours;
    		              else if (interval < 1000*60*60*24*2)/* yesterday */
    			             humanized_time=settings.yesterday +' '+ other_time.toLocaleTimeString();
    		             else if (interval < 1000*60*60*24*30)/* in month */
    			             humanized_time=Math.floor(interval/1000/60/60/24)+' '+settings.many_days +' '+ other_time.toLocaleTimeString();
    			     }
    			     $(this).html( humanized_time );
    			 }
    		});
    	}
	};

	function parseDate(the_date){
        var val = new Date(the_date);
        return isNaN(val.valueOf())?null:val
	}



})(jQuery);





/***********************
    xLazyLoader
************************/

/*
 * xLazyLoader 1.3 - Plugin for jQuery
 * 
 * Load js, css and images asynchron and get different callbacks
 *
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Depends:
 *   jquery.js
 *
 *  Copyright (c) 2008 Oleg Slobodskoi (ajaxsoft.de)
 */

(function($){

$.xLazyLoader =  function ( method, options ) {
    if ( typeof method == 'object' ) {
        options = method;
        method = 'init';
    };
    new xLazyLoader()[method](options);
};

$.xLazyLoader.defaults = {
    js: [], css: [], img: [],
    name: null,
    timeout: 20000,
    //success callback for all files
    success: function(){}, 
    //error callback - by load errors / timeout
    error: function(){},
    //complete callbck - by success or errors
    complete: function(){},
    //success callback for each file
    each: function(){} 
};

var head = document.getElementsByTagName("head")[0];

function xLazyLoader ()
{

    var self = this,
        s,
        loaded = [],
        errors = [],
        tTimeout,
        cssTimeout,
        toLoad,
        files = []
    ;
    
    this.init = function ( options )
    {
        if ( !options ) return;
        
        s = $.extend({}, $.xLazyLoader.defaults, options);
        toLoad = {js: s.js, css: s.css, img: s.img};
        
        $.each(toLoad, function( type, f ){
            if ( typeof f == 'string' )        
                f = f.split(',');
            files = files.concat(f);    
        });

        if ( !files.length ) {
            dispatchCallbacks('error');
            return;    
        };

        if (s.timeout) {
            tTimeout = setTimeout(function(){
                var handled = loaded.concat(errors);
                /* search for unhandled files */
                $.each(files, function(i, file){
                    $.inArray(file, handled) == -1 && errors.push(file);        
                });
                dispatchCallbacks('error');            
            }, s.timeout);
        };


        $.each(toLoad, function(type, urls){
            if ( $.isArray(urls) )
                $.each( urls, function(i, url){
                    load(type, url);
                });
            else if (typeof urls == 'string')
                load(type, urls);
        });
        


    };

    this.js = function ( src, callback, name )
    {
        var $script = $('script[src*="'+src+'"]');
        if ( $script.length ) {
            $script.attr('pending') ? $script.bind('scriptload',callback) : callback();
            return;
        };
        
        var s = document.createElement('script');
        s.setAttribute("type","text/javascript");
        s.setAttribute("src", src);
        s.setAttribute('id', name);
        s.setAttribute('pending', 1);
        // Mozilla only
        s.onerror = addError;
        
        
        $(s).bind('scriptload',function(){
            $(this).removeAttr('pending');
            callback();
             //unbind load event
             //timeout because of pending callbacks
            setTimeout(function(){
                $(s).unbind('scriptload');
            },10);
        });
        
        // jQuery doesn't handling onload event special for script tag,
        var done = false;
        s.onload = s.onreadystatechange = function() {
            if ( !done && ( !this.readyState || /loaded|complete/.test(this.readyState) ) ) {
                done = true;
                // Handle memory leak in IE
                s.onload = s.onreadystatechange = null;
                $(s).trigger('scriptload'); 
            };
        };
        head.appendChild(s);
    
    };

    this.css = function ( href, callback, name )
    {

        if ( $('link[href*="'+href+'"]').length ) {
            callback();
            return;
        };
        
        var link=document.createElement("link");
        link.setAttribute("rel", "stylesheet");
        link.setAttribute("type", "text/css");
        link.setAttribute("href", href);


        //var link = $('<link rel="stylesheet" type="text/css" media="all" href="'+href+'" id="'+name+'"></link>')[0];
        if ( $.browser.msie ) {
            link.onreadystatechange = function () {
                /loaded|complete/.test(link.readyState) && callback();
            };
        } else if ( $.browser.opera ) {
            link.onload = callback;
        } else {
            /* 
             * Mozilla, Safari, Chrome 
             * unfortunately it is inpossible to check if the stylesheet is really loaded or it is "HTTP/1.0 400 Bad Request"
             * the only way to do this is to check if some special properties  were set, so there is no error callback for stylesheets -
             * it fires alway success
             * 
             * There is also no access to sheet properties by crossdomain stylesheets, 
             * so we fire callback immediately
             */
            
            var hostname = location.hostname.replace('www.',''),
                hrefHostname = /http:/.test(href) ? /^(\w+:)?\/\/([^\/?#]+)/.exec( href )[2] : hostname;
            hostname != hrefHostname && $.browser.mozilla ?  
                callback()
                :  
                //stylesheet is from the same domain or it is not firefox
                (function(){
                    try {
                        link.sheet.cssRules;
                    } catch (e) {
                        cssTimeout = setTimeout(arguments.callee, 20);
                        return;
                    };
                    callback();
                })();
        };

                
        document.getElementsByTagName("head")[0].appendChild(link);
    };
    
    this.img = function ( src, callback )
    {
        var img = new Image();
        img.onload = callback;
        img.onerror = addError;
        img.src = src;
    };
    
    /* It works only for css */
    this.disable = function ( name )
    {    
        $('#lazy-loaded-'+name, head).attr('disabled', 'disabled');
    };

    /* It works only for css */
    this.enable = function ( name )
    {    
        $('#lazy-loaded-'+name, head).removeAttr('disabled');
    };
    
    /*
     * By removing js tag, script ist still living in browser memory,
     * css will be really destroyed
     */
    this.destroy = function ( name )
    {
        $('#lazy-loaded-'+name, head).remove();    
    };
    
    function load ( type, url ) {
        self[type](url, function(status) { 
            status == 'error' ? errors.push(url) : loaded.push(url) && s.each(url);
            checkProgress();
        }, 'lazy-loaded-'+ (s.name ? s.name : new Date().getTime()) );
    };
    
    function dispatchCallbacks ( status ) {
        s.complete(status, loaded, errors);
        s[status]( status=='error' ? errors : loaded);
        clearTimeout(tTimeout);
        clearTimeout(cssTimeout);
    };
    
    function checkProgress () {
        if (loaded.length == files.length) dispatchCallbacks('success')
        else if (loaded.length+errors.length == files.length) dispatchCallbacks('error');
    };
    
    function addError () {
        errors.push(this.src);    
        checkProgress();
    };

};

})(jQuery);
