/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-07-21 18:45:56 -0500 (Sat, 21 Jul 2007) $
 * $Rev: 2447 $
 *
 * Version 2.1.1
 */
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);

/**
 * Ajax Queue Plugin
 * 
 * Homepage: http://jquery.com/plugins/project/ajaxqueue
 * Documentation: http://docs.jquery.com/AjaxQueue
 */

/**

<script>
$(function(){
	jQuery.ajaxQueue({
		url: "test.php",
		success: function(html){ jQuery("ul").append(html); }
	});
	jQuery.ajaxQueue({
		url: "test.php",
		success: function(html){ jQuery("ul").append(html); }
	});
	jQuery.ajaxSync({
		url: "test.php",
		success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
	});
	jQuery.ajaxSync({
		url: "test.php",
		success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
	});
});
</script>
<ul style="position: absolute; top: 5px; right: 5px;"></ul>

 */
/*
 * Queued Ajax requests.
 * A new Ajax request won't be started until the previous queued 
 * request has finished.
 */

/*
 * Synced Ajax requests.
 * The Ajax request will happen as soon as you call this method, but
 * the callbacks (success/error/complete) won't fire until all previous
 * synced requests have been completed.
 */


(function($) {
	
	var ajax = $.ajax;
	
	var pendingRequests = {};
	
	var synced = [];
	var syncedData = [];
	
	$.ajax = function(settings) {
		// create settings for compatibility with ajaxSetup
		settings = jQuery.extend(settings, jQuery.extend({}, jQuery.ajaxSettings, settings));
		
		var port = settings.port;
		
		switch(settings.mode) {
		case "abort": 
			if ( pendingRequests[port] ) {
				pendingRequests[port].abort();
			}
			return pendingRequests[port] = ajax.apply(this, arguments);
		case "queue": 
			var _old = settings.complete;
			settings.complete = function(){
				if ( _old )
					_old.apply( this, arguments );
				jQuery([ajax]).dequeue("ajax" + port );;
			};
		
			jQuery([ ajax ]).queue("ajax" + port, function(){
				ajax( settings );
			});
			return;
		case "sync":
			var pos = synced.length;
	
			synced[ pos ] = {
				error: settings.error,
				success: settings.success,
				complete: settings.complete,
				done: false
			};
		
			syncedData[ pos ] = {
				error: [],
				success: [],
				complete: []
			};
		
			settings.error = function(){ syncedData[ pos ].error = arguments; };
			settings.success = function(){ syncedData[ pos ].success = arguments; };
			settings.complete = function(){
				syncedData[ pos ].complete = arguments;
				synced[ pos ].done = true;
		
				if ( pos == 0 || !synced[ pos-1 ] )
					for ( var i = pos; i < synced.length && synced[i].done; i++ ) {
						if ( synced[i].error ) synced[i].error.apply( jQuery, syncedData[i].error );
						if ( synced[i].success ) synced[i].success.apply( jQuery, syncedData[i].success );
						if ( synced[i].complete ) synced[i].complete.apply( jQuery, syncedData[i].complete );
		
						synced[i] = null;
						syncedData[i] = null;
					}
			};
		}
		return ajax.apply(this, arguments);
	};
	
})(jQuery);

/*
 * SimpleModal 1.3.4 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2010 Eric Martin (http://twitter.com/EricMMartin)
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 237 2010-03-11 05:51:01Z emartin24 $
 */
;(function($){var ie6=$.browser.msie&&parseInt($.browser.version)==6&&typeof window['XMLHttpRequest']!="object",ieQuirks=null,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={appendTo:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',escClose:true,overlayClose:false,position:null,persist:false,transient:false,onOpen:null,onShow:null,onClose:null};$.modal.impl={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.support.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data=='object'){data=data instanceof jQuery?data:$(data);s.d.placeholder=false;if(data.parent().parent().size()>0){data.before($('<span></span>').attr('id','simplemodal-placeholder').css({display:'none'}));s.d.placeholder=true;s.display=data.css('display');if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(!s.o.transient&&ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:s.o.transient?0:w[0],width:s.o.transient?0:w[1],position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(!s.o.transient&&s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(!s.o.transient&&s.o.focus&&e.keyCode==9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode==27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setContainerDimensions(true);if(ie6||ieQuirks){s.fixIE();}else if(!s.o.transient){s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;$.each([s.d.iframe||null,s.o.transient?null:s.d.overlay,s.d.container],function(i,el){if(el){var bch='document.body.clientHeight',bcw='document.body.clientWidth',bsh='document.body.scrollHeight',bsl='document.body.scrollLeft',bst='document.body.scrollTop',bsw='document.body.scrollWidth',ch='document.documentElement.clientHeight',cw='document.documentElement.clientWidth',sl='document.documentElement.scrollLeft',st='document.documentElement.scrollTop',s=el[0].style;s.position='absolute';if(i<2){s.removeExpression('height');s.removeExpression('width');s.setExpression('height',''+bsh+' > '+bch+' ? '+bsh+' : '+bch+' + "px"');s.setExpression('width',''+bsw+' > '+bcw+' ? '+bsw+' : '+bcw+' + "px"');}else{var te,le;if(p&&p.constructor==Array){var top=p[0]?typeof p[0]=='number'?p[0].toString():p[0].replace(/px/,''):el.css('top').replace(/px/,'');te=top.indexOf('%')==-1?top+' + (t = '+st+' ? '+st+' : '+bst+') + "px"':parseInt(top.replace(/%/,''))+' * (('+ch+' || '+bch+') / 100) + (t = '+st+' ? '+st+' : '+bst+') + "px"';if(p[1]){var left=typeof p[1]=='number'?p[1].toString():p[1].replace(/px/,'');le=left.indexOf('%')==-1?left+' + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"':parseInt(left.replace(/%/,''))+' * (('+cw+' || '+bcw+') / 100) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}}else{te='('+ch+' || '+bch+') / 2 - (this.offsetHeight / 2) + (t = '+st+' ? '+st+' : '+bst+') + "px"';le='('+cw+' || '+bcw+') / 2 - (this.offsetWidth / 2) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}s.removeExpression('top');s.removeExpression('left');s.setExpression('top',te);s.setExpression('left',le);}}});},focus:function(pos){var s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);input.length>0?input.focus():s.d.wrap.focus();},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<='1.2.6'?document.documentElement['clientHeight']:$.browser.opera&&$.browser.version<'9.5'&&$.fn.jquery>'1.2.6'?window.innerHeight:el.height();return[h,el.width()];},getVal:function(v){return v=='auto'?0:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},setContainerDimensions:function(resize){var s=this;if(!resize||(resize&&s.o.autoResize)){var ch=$.browser.opera?s.d.container.height():s.getVal(s.d.container.css('height')),cw=$.browser.opera?s.d.container.width():s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.o.maxHeight<w[0]?s.o.maxHeight:w[0],mw=s.o.maxWidth&&s.o.maxWidth<w[1]?s.o.maxWidth:w[1];if(!ch){if(!dh){ch=s.o.minHeight;}else{if(dh>mh){ch=mh;}else if(dh<s.o.minHeight){ch=s.o.minHeight;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}if(!cw){if(!dw){cw=s.o.minWidth;}else{if(dw>mw){cw=mw;}else if(dw<s.o.minWidth){cw=s.o.minWidth;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});if(dh>ch||dw>cw){s.d.wrap.css({overflow:'auto'});}}if(s.o.autoPosition){s.setPosition();}},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target==s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target==s.inputs[0])||s.inputs.length==0){e.preventDefault();var pos=e.shiftKey?'last':'first';setTimeout(function(){s.focus(pos);},10);}}else{e.preventDefault();setTimeout(function(){s.focus();},10);}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.placeholder){var ph=$('#simplemodal-placeholder');if(s.o.persist){ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display',s.display));}else{s.d.data.hide().remove();ph.replaceWith(s.d.orig);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide().remove();s.d.iframe&&s.d.iframe.hide().remove();s.d={};}}};})(jQuery);

(function($){
$.fn._hover = $.fn.hover;

// jquery method
$.fn.hover = function( fn1, fn2, fn3 ) {
	if ( fn3 ) this.bind('hoverstart', fn1 ); // 3 args
	if ( fn2 ) this.bind('hoverend', fn3 ? fn3 : fn2 ); // 2+ args
	return !fn1 ? this.trigger('hover') // 0 args
		: this.bind('hover', fn3 ? fn2 : fn1 ); // 1+ args
	};

// special event configuration
var hover = $.event.special.hover = {
	delay: 100, // milliseconds
	speed: 100, // pixels per second
	setup: function( data ){
		data = $.extend({ speed: hover.speed, delay: hover.delay, hovered:0 }, data||{} );
		$.event.add( this, "mouseenter mouseleave", hoverHandler, data );
		},
	teardown: function(){
		$.event.remove( this, "mouseenter mouseleave", hoverHandler );
		}
	};

// shared event handler
function hoverHandler( event ){
	var data = event.data || event;
	switch ( event.type ){
		case 'mouseenter': // mouseover
			data.dist2 = 0; // init mouse distance²
			data.event = event; // store the event
			event.type = "hoverstart"; // hijack event
			if ( $.event.handle.call( this, event ) !== false ){ // handle "hoverstart"
				data.elem = this; // ref to the current element
				$.event.add( this, "mousemove", hoverHandler, data ); // track the mouse
				data.timer = setTimeout( compare, data.delay ); // start async compare
				}
			break;
		case 'mousemove': // track the event, mouse distance² = x² + y²
			data.dist2 += Math.pow( event.pageX-data.event.pageX, 2 )
				+ Math.pow( event.pageY-data.event.pageY, 2 );
			data.event = event; // store current event
			break;
		case 'mouseleave': // mouseout
			clearTimeout( data.timer ); // uncompare
			if ( data.hovered ){
				event.type = "hoverend"; // hijack event
				$.event.handle.call( this, event ); // handle "hoverend"
				data.hovered--; // reset flag
				}
			else $.event.remove( data.elem, "mousemove", hoverHandler ); // untrack
			break;
		default: // timeout compare // distance² = x² + y²  = ( speed * time )²
			if ( data.dist2 <= Math.pow( data.speed*( data.delay/1e3 ), 2 ) ){ // speed acceptable
				$.event.remove( data.elem, "mousemove", hoverHandler ); // untrack
				data.event.type = "hover"; // hijack event
				if ( $.event.handle.call( data.elem, data.event ) !== false ) // handle "hover"
					data.hovered++; // flag for "hoverend"
				}
			else data.timer = setTimeout( compare, data.delay ); // async recurse
			data.dist2 = 0; // reset distance² for next compare
			break;
		}
	function compare(){ hoverHandler( data ); }; // timeout/recursive function
	};

})(jQuery);

function str_repeat( input, multiplier ) {
    // Returns the input string repeat mult times
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/str_repeat    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // *     example 1: str_repeat('-=', 10);
    // *     returns 1: '-=-=-=-=-=-=-=-=-=-='

    return new Array(multiplier+1).join(input);
}

function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14

    var i = (haystack+'').indexOf( needle, offset );
    return i===-1 ? false : i;
}

function is_string( mixed_var ){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: is_string('23');
    // *     returns 1: true
    // *     example 2: is_string(23.5);
    // *     returns 2: false

    return (typeof( mixed_var ) == 'string');
}

function unserialize(data){
    // http://kevin.vanzonneveld.net
    // +     original by: Arpad Ray (mailto:arpad@php.net)
    // +     improved by: Pedro Tainha (http://www.pedrotainha.com)
    // +     bugfixed by: dptr1988
    // +      revised by: d3x
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %            note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %            note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *       example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');
    // *       returns 1: ['Kevin', 'van', 'Zonneveld']
    // *       example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');
    // *       returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}

    var error = function (type, msg, filename, line){throw new window[type](msg, filename, line);};
    var read_until = function (data, offset, stopchr){
        var buf = [];
        var chr = data.slice(offset, offset + 1);
        var i = 2;
        while(chr != stopchr){
            if((i+offset) > data.length){
                error('Error', 'Invalid');
            }
            buf.push(chr);
            chr = data.slice(offset + (i - 1),offset + i);
            i += 1;
        }
        return [buf.length, buf.join('')];
    };
    var read_chrs = function (data, offset, length){
        buf = [];
        for(var i = 0;i < length;i++){
            var chr = data.slice(offset + (i - 1),offset + i);
            buf.push(chr);
        }
        return [buf.length, buf.join('')];
    };
    var _unserialize = function (data, offset){
        if(!offset) offset = 0;
        var buf = [];
        var dtype = (data.slice(offset, offset + 1)).toLowerCase();

        var dataoffset = offset + 2;
        var typeconvert = new Function('x', 'return x');
        var chrs = 0;
        var datalength = 0;

        switch(dtype){
            case "i":
                typeconvert = new Function('x', 'return parseInt(x)');
                var readData = read_until(data, dataoffset, ';');
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case "b":
                typeconvert = new Function('x', 'return (parseInt(x) == 1)');
                var readData = read_until(data, dataoffset, ';');
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case "d":
                typeconvert = new Function('x', 'return parseFloat(x)');
                var readData = read_until(data, dataoffset, ';');
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case "n":
                readdata = null;
            break;
            case "s":
                var ccount = read_until(data, dataoffset, ':');
                var chrs = ccount[0];
                var stringlength = ccount[1];
                dataoffset += chrs + 2;

                var readData = read_chrs(data, dataoffset+1, parseInt(stringlength));
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 2;
                if(chrs != parseInt(stringlength) && chrs != readdata.length){
                    error('SyntaxError', 'String length mismatch');
                }
            break;
            case "a":
                var readdata = {};

                var keyandchrs = read_until(data, dataoffset, ':');
                var chrs = keyandchrs[0];
                var keys = keyandchrs[1];
                dataoffset += chrs + 2;

                for(var i = 0;i < parseInt(keys);i++){
                    var kprops = _unserialize(data, dataoffset);
                    var kchrs = kprops[1];
                    var key = kprops[2];
                    dataoffset += kchrs;

                    var vprops = _unserialize(data, dataoffset);
                    var vchrs = vprops[1];
                    var value = vprops[2];
                    dataoffset += vchrs;

                    readdata[key] = value;
                }

                dataoffset += 1;
            break;
            default:
//                error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
            break;
        }
        return [dtype, dataoffset - offset, typeconvert(readdata)];
    };
    return _unserialize(data, 0)[2];
}

var object_move = {};

function empty(v) {
	if (typeof v == "undefined")
		return true;

	if (typeof v == "object") {
		for (var vv in v) {
			if (vv)
				return false;
		}
	} else {
		return v == "";
	}

	return true;
}

var mpX, mpY;
$(document).ready(function() {
	$(document).mousemove(function(e) {
		mpX = e.pageX;
		mpY = e.pageY;
	});
	$(document).mousemove(objectMover);
});

function getMousePosition() {
  var pos = [mpX, mpY];
  return pos;
}

function getPageDimensions(){
	var xScroll, yScroll;

	pageWidth = $(document).width();
	pageHeight = $(document).height();
	windowWidth = $(window).width();
	windowHeight = $(window).height();

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function fav(h, t) {
	var h = (typeof h == "undefined")?location.href:h;
	var t = (typeof t == "undefined")?document.title:t;

	if (window.sidebar) {
		window.sidebar.addPanel(t, h, "");
	} else if( window.external ) {
		window.external.AddFavorite(h, t);
	}	else if(window.opera && window.print) {
		return true;
	}
}


// jQuery Functions
$(document).ready(function() {
	$("[id^='submit_delete-']").hide();
	$("input[name^='delete_vars']").live("click", function() {
		var parent_formid = $(this).parents("form").attr("id");
		var delete_checked = ($("#"+parent_formid+" input[name^='delete_vars']:checked").length > 0)?true:false;
		if (!delete_checked) {
			$("#"+parent_formid+" input[name=action]").val('');
		}
		$("#submit_delete-"+parent_formid).css("display", (delete_checked)?"":"none");
	});

	$("textarea").each(function() {
		if ($(this).hasClass("Code")) {
			$(this).tabby();
		}
		if ($(this).hasClass("TextareaFixed")) {
			return;
		}

		var pad_line = 0;
		var expand_rows = parseInt($(this).attr("rows"));
		if (expand_rows <= 1)
			expand_rows = 3;

		var line_height = $(this).css("line-height");
		if (line_height == 'normal') {
			line_height = parseInt($(this).css("font-size").replace('px', ''))+2;
			$(this).css("line-height", line_height+'px');
		} else {
			line_height = parseInt(line_height.replace('px', ''));
		}

		$(this).attr("rows", 1);
		$(this).css("height", line_height+'px');

		$(this).focus(function() {
			var r = expand_rows+2;
			var h = (r*line_height);
			if ($(this).css("height") == h+'px')
				return;

			$(this).attr("rows", expand_rows);
			$(this).animate({height: h}, 250, function() { $(this)[0].focus(); });
		});
	});
});


$(document).ready(function() {
	$(".ToolTip").each(function() {
		var t = new ToolTip(this);
		$(this).mouseover(function () {
			t.show(this);
		});
		$(this).mouseout(function () {
			t.hide();
		});
	});
});


$(document).ready(function() {
	var toggler_checkboxes = [];

	$(".ToggleOptions").each(function() {
		var toggle_to;
		var set = false;
		if (strpos($(this)[0].id, "to_on-") === 0) {
			toggle_to = true;
			set = $(this)[0].id.replace("to_on-", "");
		} else if (strpos($(this)[0].id, "to_off-") === 0) {
			toggle_to = false;
			set = $(this)[0].id.replace("to_off-", "");
		}

		if (set) {
			$(this).click(function() {
				toggleOptions(set, toggle_to);
			});
		}
	});
});
function toggleOptions(set, toggle_to) {
	var options = $("[id^='"+set+"-']").filter("[type='checkbox']");
	if (options.length < 1)
		return false;

	options.attr("checked", toggle_to);

	return;
}


function modalOpen(dialog) {
	dialog.overlay.fadeIn('slow', function () {
		dialog.container.fadeIn('slow', function () {
			dialog.data.slideDown('slow');
		});
	});
}
function modalLoader(load_func, load_func_vars) {
	if (!load_func)
		load_func = false;

	$('#modal_box').modal({
		overlayCss: {
		  backgroundColor: '#000',
	    cursor: 'wait'
	  },
	  containerCss: {
	    height: "560px",
	    width: "720px",
	    backgroundColor: '#fff',
	    border: '3px solid #ccc',
	    overflow: "auto"
	  },
	  onOpen: modalOpen,
	  onShow: function(dialog) {
			dialog.container.addClass("Loading");
			if (load_func) {
				load_func.apply(this, [load_func_vars]);
			}
	  },
  	close: false
	});
}


function loadScript(src) {
	var e = document.createElement("script");
	e.src = src;
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e);
}


function registerObjectMover(object) {
	object_move = {};

	object_move.object = object;
	object_move.init_obj_x = parseInt(object.style.left.replace('px', ''));
	object_move.init_obj_y = parseInt(object.style.top.replace('px', ''));
	object_move.init_pos_x = mpX;
	object_move.init_pos_y = mpY;
	object_move.init_zindex = object.style.zIndex;

	object.style.zIndex = 10000;

	var dim = getPageDimensions();
	object_move.init_win_w = dim[2];
	object_move.init_win_h = dim[3];
}
function unregisterObjectMover() {
	var object = object_move.object;

	var left = parseInt(object.style.left.replace('px', ''));
	var width = parseInt(object.style.width.replace('px', ''));

	if (left+width > object_move.init_win_w)
		object.style.left = object_move.init_win_w-width-5+'px';

	object.style.zIndex = object_move.init_zindex;

	object_move = null;
}
function objectMover() {
	if (empty(object_move))
		return;

	var object = object_move.object;

	object.style.left = object_move.init_obj_x+mpX-object_move.init_pos_x+'px';
	object.style.top = object_move.init_obj_y+mpY-object_move.init_pos_y+'px';
	emptySelection();
}


function emptySelection() {
	if (document.selection) {
		if (document.selection.empty)
			document.selection.empty();
		else
			document.selection.innerHTML = document.selection.createRange().text;
	}	else if (window.getSelection() && window.getSelection() != '')
		window.getSelection().removeAllRanges();
}

function deactivate_screen(show) {
	if (!show)
		var show = false;
	var dim = getPageDimensions();

	if (show)
		$('#deact_screen').addClass('Loading');
	else
		$('#deact_screen').removeClass('Loading');
	$('#deact_screen').css({display:((show)?'':'none'), height:dim[1]+'px'});
}
function loader_display(open) {
	deactivate_screen(open);
	$('#loader_container').css({display:((open)?'':'none')});
}
function loader_loaded() {
	$('#deact_screen').attr({className:''});
}


function debug_message(message) {
	var _message = '';
	if (message && typeof message == 'object') {
		for (m in message)
			_message = debug(message[m])+'<BR>';
	} else
		_message = message+'<BR>';

	return _message;
}
function debug(message) {
	var _message = debug_message(message);
	$('#jsdebug').append(_message);
}


function truncate(string, length, end_string) {
	if (!end_string)
		var end_string = '';
	if (!length)
		var length = 48;

	if (length >= string.length)
		end_string = '';

	string = string.substring(0, length);
	string = string.replace('/\w+$/', '');
	if (end_string)
		string += end_string

	return string;
}
function strip_tags(string) {
  return string.replace(/(<([^>]+)>)/ig,"");
}
function strtolower(str) {
	return str.toLowerCase();
}
String.prototype.repeat = function(l){
	return new Array(l+1).join(this);
};
function int2str(i) {
	return i+'';
}
function bytes_string(bytes) {
  var s = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
  var e = Math.floor(Math.log(bytes)/Math.log(1024));
  return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
}

function assembleOptions(options_data, options_vars, options, level) {
	var value, display_value, subs;
	if (!options)
		var options = new Array();
	if (!level)
		var level = 0;
	var indent = '--';

	if (options_vars && options_vars['value_key'] && options_vars['display_key']) {
		for (o in options_data) {
			value = options_data[o][options_vars['value_key']];
			display = options_data[o][options_vars['display_key']];

			var ind = '';
			if (level) {
				ind = indent.repeat(level)+' ';
			}
			options[options.length] = new Array(ind+display, value);
			if (subs = options_data[o][options_vars['subs_key']])
				options = assembleOptions(subs, options_vars, options, level+1);
		}
	} else {
		for (o in options_data) {
			options[options.length] = new Array(options_data[o], o);
		}
	}
	return options;
}

function unix_timestamp() {
	var d = new Date();
	var time = d.getTime();
	time = parseInt(time/1000);

	return time;
}

function ToolTip(element) {
	var c_id = null;
	var tt_id = "_tt_";
	var hide_timeout = null;
	var tt_content = "";
	var active = false;

	if ($(element).attr("alt"))
		tt_content = $(element).attr("alt");
	else if ($(element).attr("title"))
		tt_content = $(element).attr("title");

	if (!tt_content)
		return;

	$(element).attr("title", "");
	$(element).attr("alt", "");

	var _hide = function() {
		if ($("#"+tt_id))
			$("#"+tt_id).remove();
		active = false;
	}

	this.hide = function() {
		__hide = _hide;
		hide_timeout = setTimeout(__hide, 250);
	}

	this.show = function() {
		if (hide_timeout)
			clearTimeout(hide_timeout);

		if (!active) {
			_hide();
			$(element).after('<SPAN class="ToolTipContainer" id="'+tt_id+'">'+tt_content+'</SPAN>');
			$("#"+tt_id).css({"top": mpY, "left": mpX});
			$("#"+tt_id).mouseover(this.show);
			$("#"+tt_id).mouseout(this.hide);
			active = true;
		}
	}
}

function date ( format, timestamp ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
    // +      parts by: Peter-Paul Koch (http://www.quirksmode.org/js/beat.html)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: MeEtc (http://yass.meetcweb.com)
    // +   improved by: Brad Touesnard
    // +   improved by: Tim Wiel
    // *     example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400);
    // *     returns 1: '09:09:40 m is month'
    // *     example 2: date('F j, Y, g:i a', 1062462400);
    // *     returns 2: 'September 2, 2003, 2:26 am'

    var a, jsdate=((timestamp) ? new Date(timestamp*1000) : new Date());
    var pad = function(n, c){
        if( (n = n + "").length < c ) {
            return new Array(++c - n.length).join("0") + n;
        } else {
            return n;
        }
    };
    var txt_weekdays = ["Sunday","Monday","Tuesday","Wednesday",
        "Thursday","Friday","Saturday"];
    var txt_ordin = {1:"st",2:"nd",3:"rd",21:"st",22:"nd",23:"rd",31:"st"};
    var txt_months =  ["", "January", "February", "March", "April",
        "May", "June", "July", "August", "September", "October", "November",
        "December"];

    var f = {
        // Day
            d: function(){
                return pad(f.j(), 2);
            },
            D: function(){
                t = f.l(); return t.substr(0,3);
            },
            j: function(){
                return jsdate.getDate();
            },
            l: function(){
                return txt_weekdays[f.w()];
            },
            N: function(){
                return f.w() + 1;
            },
            S: function(){
                return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th';
            },
            w: function(){
                return jsdate.getDay();
            },
            z: function(){
                return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0;
            },

        // Week
            W: function(){
                var a = f.z(), b = 364 + f.L() - a;
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;

                if(b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
                    return 1;
                } else{

                    if(a <= 2 && nd >= 4 && a >= (6 - nd)){
                        nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                        return date("W", Math.round(nd2.getTime()/1000));
                    } else{
                        return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
                    }
                }
            },

        // Month
            F: function(){
                return txt_months[f.n()];
            },
            m: function(){
                return pad(f.n(), 2);
            },
            M: function(){
                t = f.F(); return t.substr(0,3);
            },
            n: function(){
                return jsdate.getMonth() + 1;
            },
            t: function(){
                var n;
                if( (n = jsdate.getMonth() + 1) == 2 ){
                    return 28 + f.L();
                } else{
                    if( n & 1 && n < 8 || !(n & 1) && n > 7 ){
                        return 31;
                    } else{
                        return 30;
                    }
                }
            },

        // Year
            L: function(){
                var y = f.Y();
                return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0;
            },
            //o not supported yet
            Y: function(){
                return jsdate.getFullYear();
            },
            y: function(){
                return (jsdate.getFullYear() + "").slice(2);
            },

        // Time
            a: function(){
                return jsdate.getHours() > 11 ? "pm" : "am";
            },
            A: function(){
                return f.a().toUpperCase();
            },
            B: function(){
                // peter paul koch:
                var off = (jsdate.getTimezoneOffset() + 60)*60;
                var theSeconds = (jsdate.getHours() * 3600) +
                                 (jsdate.getMinutes() * 60) +
                                  jsdate.getSeconds() + off;
                var beat = Math.floor(theSeconds/86.4);
                if (beat > 1000) beat -= 1000;
                if (beat < 0) beat += 1000;
                if ((String(beat)).length == 1) beat = "00"+beat;
                if ((String(beat)).length == 2) beat = "0"+beat;
                return beat;
            },
            g: function(){
                return jsdate.getHours() % 12 || 12;
            },
            G: function(){
                return jsdate.getHours();
            },
            h: function(){
                return pad(f.g(), 2);
            },
            H: function(){
                return pad(jsdate.getHours(), 2);
            },
            i: function(){
                return pad(jsdate.getMinutes(), 2);
            },
            s: function(){
                return pad(jsdate.getSeconds(), 2);
            },
            //u not supported yet

        // Timezone
            //e not supported yet
            //I not supported yet
            O: function(){
               var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
               if (jsdate.getTimezoneOffset() > 0) t = "-" + t; else t = "+" + t;
               return t;
            },
            P: function(){
                var O = f.O();
                return (O.substr(0, 3) + ":" + O.substr(3, 2));
            },
            //T not supported yet
            //Z not supported yet

        // Full Date/Time
            c: function(){
                return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P();
            },
            //r not supported yet
            U: function(){
                return Math.round(jsdate.getTime()/1000);
            }
    };

    return format.replace(/[\\]?([a-zA-Z])/g, function(t, s){
        if( t!=s ){
            // escaped
            ret = s;
        } else if( f[s] ){
            // a date function exists
            ret = f[s]();
        } else{
            // nothing special
            ret = s;
        }

        return ret;
    });
}

function clink(l) {
	if (typeof dc_m == "undefined" || typeof dc_m.a == "undefined" || typeof dc_m.a[l] == "undefined")
		return "index.php";

	return dc_m.a[l];
}

var rf_init = {};
var rf_prime = {};

function ActiveFeature(featureid) {
	var nav_opacity = 40;
	var z_lo = 1000;

	var options = active_features[featureid].options;
	var slides = active_features[featureid].slides;

	var c_rid = 0;
	var l_rid = false;

	var s_pre = 'af_'+featureid;
	var s_bns = false;

	if (!document.getElementById('af_'+featureid))
		return false;

	$("[id^='"+s_pre+"_i_']").hide();
	if ($("[id^='"+s_pre+"_b_']").length > 1) {
		s_bns = true;
		$("[id^='"+s_pre+"_b_']").fadeTo(1, .60);
	}

	var total_slides = 0;
	for (i in slides) {
		total_slides++;
	}

	var c_to = null;
	var c_init_c = null;
	var c_init_to = null;
	var c_href = false;

	var _init = function() {
		if (rf_init['rb_'+c_init_c])
			rf_init['rb_'+c_init_c].call();

		c_init_c = null;
		clearTimeout(c_init_to);
	}

	var _cycle = function() {
		c_init_c = null;
		if (c_init_to)
			clearTimeout(c_init_to);
		if (rf_prime['rb_'+c_rid])
			rf_prime['rb_'+c_rid].call();

		c_href = false;
		if (slides[c_rid].href) {
			c_href = slides[c_rid].href;
			$("#"+s_pre).css("cursor", "pointer");
		} else
			$("#"+s_pre).css("cursor", "default");

		c_i = $("#"+s_pre+"_i_"+c_rid);
		c_i.css("z-index", z_lo+5);
		if (s_bns) {
			$("#"+s_pre+"_b_"+c_rid).fadeTo(50, .90);
		}

		if (l_rid !== false) {
			l_i = $("#"+s_pre+"_i_"+l_rid);
			l_i.css("z-index", z_lo);
			l_i.fadeOut(750, function () { l_i.css("display", "none"); });

			if (s_bns) {
				$("#"+s_pre+"_b_"+l_rid).fadeTo(50, .60);
			}
		}

		c_i.fadeIn(750);

		c_init_c = null;
		if (rf_init['rb_'+c_rid]) {
			c_init_c = c_rid;
			c_init_to = setTimeout(_init, 750);
		}

		l_rid = c_rid;
		c_rid = (c_rid < total_slides-1)?c_rid+1:0;

		c_to = setTimeout(_cycle, options.delay);
	}

	var _recycle = function(c) {
		$("[id^='"+s_pre+"_i_']").hide();
		$("[id^='"+s_pre+"_b_']").fadeTo(1, .60);

		l_rid = c_rid;
		c_rid = c;

		clearTimeout(c_to);

		_cycle();
	}

	this.cycle = function() {
		_cycle();
	}

	var jump = function(i) {
		if (slides[i].href)
			window.location.href = slides[i].href;
	}

	$("[id^='"+s_pre+"_i_']").click(function() {
		comps = this.id.split("_");
		ix = parseInt(comps[comps.length-1]);
		jump(ix);
	});

	for (i in slides) {
		$("#"+s_pre+"_b_"+i).click(function () {
			comps = this.id.split("_");
			ix = parseInt(comps[comps.length-1]);
			_recycle(ix);
		});
	}

	$("#"+s_pre+"_b_next").click(function () {
		_recycle(c_rid);
	});
	$("#"+s_pre+"_b_prev").click(function () {
		var ps = (l_rid == 0)?total_slides-1:l_rid-1;
		_recycle(ps);
	});

	this.cycle();
}

var minisearch_init = false;
$(document).ready(function() {
	minisearch_init = $("#minisearch-search_string").val();
	$("#minisearchform .MiniSearchLabel").click(function() {
		$("#minisearch-search_string").parent().fadeIn("fast");
	});

	$(".MiniSearchLabel").click(checkMiniSearch);
});

function checkMiniSearch() {
	if ($("#minisearch-search_string").val() != '' && $("#minisearch-search_string").val() != minisearch_init) {
		$("#minisearchform").submit();
		return true;
	}

	$("#minisearch-search_string").parent().fadeIn("fast");
	return false;
}

$(document).ready(function() {
	var cm_t_href = [];
	var cm_c_count = [];
	var cm_ch_count = [];

	$(".MainLinksGroupTitle").each(function() {
		var comps = this.id.split("_");
		var gid = comps[comps.length-1];

		if ($("#cm_sl_"+gid)[0]) {
			cm_t_href[gid] = $(this).attr("href");
			$(this).attr("href", "javascript: void(0);");

			$(this).click(function() {
				menuLinks(gid);
			});
		}
	});
});

function menuLinks(gid) {
	$(".MainLinksGroupSublinksContainer").each(function() {
		var scomps = this.id.split("_");
		var sgid = scomps[scomps.length-1];
		if (sgid != gid)
			$(this).animate({height: "0px"});
	});

	var p_rows = 2;
	var p_c = $("#cm_sl_"+gid+" > DIV.MainLinksGroupSublinksPrimary");
	var p_h = 0;
	if (p_c[0])
		p_h = parseInt(p_c[0].style.height.replace("px", ""));
	var h = p_h+24;

	if ($("#cm_sl_"+gid).css("height") == "0px") {
		s_count = $("#cm_sl_"+gid+"_sl").children("DIV:visible").children("A").length;
		h += (s_count*15)+4;

		$("#cm_sl_"+gid).css("display", "").animate({height: h+"px"});
	} else {
		$("#cm_sl_"+gid).animate({height: "0px"}).css("display", "none");
	}
}

function menuHideSublinks(gid) {
	s_menu = $("#cm_sl_"+gid+"_sl");

	s_menu.css({display: "none"});
	s_menu.children("DIV").css({display: "none"});
}
function menuSublinks(gid, sgid) {
	$("[id^='cm_sl_"+gid+"_sla_']").attr("className", "");

	t_menu = $("#cm_sl_"+gid);

	s_menu = $("#cm_sl_"+gid+"_sl");
	s_links = $("#cm_sl_"+gid+"_sl_"+sgid);
	s_count = s_links.children("A").length;

	s_links_a = $("#cm_sl_"+gid+"_sla_"+sgid);
	s_links_a.attr("className", "MainLinksGroupSublinksSecondaryOActive");

	s_menu.css({display: "none"});
	s_menu.children("DIV").css({display: "none"});
	s_links.fadeOut(1);

	var h_s = (s_count*15)+4;

	var p_c = $("#cm_sl_"+gid+" > DIV.MainLinksGroupSublinksPrimary");
	var p_h = 0;
	if (p_c[0])
		p_h = parseInt(p_c[0].style.height.replace("px", ""));
	var h_t = p_h+24+h_s;

	t_menu.animate({height: h_t+"px"});
	s_menu.css({display: ""});
	s_links.fadeIn(500);
}

$(document).ready(function() {
	$("DIV.HeadLink").each(function() {
		if ($(this).children().length > 1) {
			$(this).hover(function() {
				$(this).children().filter(".HeadLinksSublinksContainer").show();
			}, function() {
				$(this).children().filter(".HeadLinksSublinksContainer").hide();
			});
		}
	});
});

$(document).ready(function() {
	if ($("[id^='ehl_title-']")[0]) {
		$("[id^='ehl_title-']").each(function() {
			var comps = this.id.split("-");
			var eid = comps[1];

			$(this).css("cursor", "pointer");

			$("#ehl_descr_box-"+eid).css("display", "none");
			$("#ehl_date-"+eid).css("display", "none");

			$("#ehl_title-"+eid).click(function() {
				var d = ($("#ehl_descr_box-"+eid)[0].style.display == "")?"none":"";
				$("#ehl_descr_box-"+eid).css("display", d);
				$("#ehl_date-"+eid).css("display", d);
			});
		});
	}
});

$(document).ready(function() {
	var arollovers = $(".AutoRollover div[id^='aro-']");
	if (arollovers[0]) {
		var aro_groups = [];
		arollovers.each(function() {
			var comps = this.id.split("-");
			var g_id = comps[1];
			var r_id = comps[2];
			var p_id = 'aro_p-'+comps[1]+'-'+comps[2];

			if (typeof aro_groups[g_id] == 'undefined') {
				aro_groups[g_id] = r_id;

				$("[id^='aro-"+g_id+"-']").attr("class", "aro-row");
				$("#aro-"+g_id+"-"+r_id).attr("class", "aro-row-active");

				$("[id^='aro_p-"+g_id+"-']").css("display", "none");
				$("#aro_p-"+g_id+"-"+r_id).css("display", "");
			}
		});

		var aro = $("[id^='aro-']");
		if (aro[0]) {
			aro.hover(function() {
				var comps = this.id.split("-");

				var go_id = 'aro-'+comps[1]+'-';
				var po_id = 'aro-'+comps[1]+'-'+comps[2];

				$("[id^='"+go_id+"']").attr("class", "aro-row");
				$("#"+po_id).attr("class", "aro-row-active");

				var g_id = 'aro_p-'+comps[1]+'-';
				var p_id = 'aro_p-'+comps[1]+'-'+comps[2];

				$("[id^='"+g_id+"']").css("display", "none");
				$("#"+p_id).css("display", "");
			});
		}
	}
});
