function g(id){
	return document.getElementById(id);
}
function addHover(el){
	if (el)
		$(el).addClass("hover");
}
function removeHover(el){
	if (el)
		$(el).removeClass("hover");
}
var _timers = [];
var _act_elements = [];
var _timeout = 100; //can change this setting to hide items slowly or faster
(function($) {
	$.fn.unselectable = function() {
		return this.each(function() {
			
			$(this)
				.css('-moz-user-select', 'none')		// FF
				.css('-khtml-user-select', 'none')		// Safari, Google Chrome
				.css('user-select', 'none');			// CSS 3
			
			if ($.browser.msie) {						// IE
				$(this).each(function() {
					this.ondrag = function() {
						return false;
					};
				});
				$(this).each(function() {
					this.onselectstart = function() {
						return (false);
					};
				});
			} else if($.browser.opera) {
				$(this).attr('unselectable', 'on');
			}
		});
	};
})(jQuery);
function onItem(el, menu, test_parents, rem_func, add_func){
	if (!menu) menu='';
	var $el = $(el);
	if ($el.hasClass('invis')){
		return false;
	}
	if (_timers[menu])
		clearTimeout(_timers[menu]);
	if (_act_elements[menu] && $el.attr('id') != _act_elements[menu].getAttribute('id') && (!test_parents || !$el.parents("li").is('#'+_act_elements[menu].getAttribute('id')))){
		if (!rem_func) removeHover(_act_elements[menu]);
		else rem_func(_act_elements[menu]);
	}
	if (!add_func && !$el.hasClass('hover')) {
		$el.addClass('hover');
	}
	else if (add_func) {
		add_func(el);
	}
	_act_elements[menu] = el;
}

function outItem(el, menu, tfunc){
	if (!menu) menu='';
	var $el = $(el);
	if ($el.hasClass('invis')){
		return false;
	}
	if (_timers[menu])
		clearTimeout(_timers[menu]);
	if (!tfunc)
		tfunc = function($e){return function(){$e.removeClass('hover');}}($el);
	_timers[menu] = setTimeout(tfunc, _timeout);
}
var $_clicked = [];

function stopBuble(e){
	e = e || window.event;
	e.cancelBubble = true;
	if (e.stopPropagation){ e.stopPropagation(); }
}

function closeall(){
	for (var i in $_clicked){
		$_clicked[i].removeClass('click');
	}
	$_clicked = [];
}

function addClick(el, key, e){
	var $el = $(el);
	var clicked = false;
	if ($_clicked[key]){
		clicked = true;
	}
	closeall();
	if (!clicked){
		$el.addClass('click');
		$_clicked[key] = $el;
	}
	stopBuble(e);
}
function showRNotes(type, t) {
	var paddingBottom = 10;
	var $rNList = $('#'+type);
	if($rNList.attr('condition')=='closed') {
		var currentHeight = $('.rNotesList', $rNList).height();
		$rNList.attr('condition', 'opened');
		$('.rNotesArrow',t).css('background-position', '0 -32px')
		$rNList.stop().animate({'height':(currentHeight+paddingBottom)+'px'}, 200, function(){return function(){}});
	} else {
		$rNList.attr('condition', 'closed');
		$('.rNotesArrow',t).css('background-position', '0 0')
		$rNList.stop().animate({'height':'0px'}, 200, function(){return function(){}});
	}
}
var boxy_params = {
	title: 'Dialog',
	show: false,
	fixed: false,
	draggable: true,
	clickToFront: true,
	modal:true,
	closeText:'<span style="height:19px; width:19px; display:block;" class="boxyClose"></span>'
}; 
var b;
$(document).ready(function() {
	b = new Boxy('', boxy_params);
	b.setContent('<div id="astro_boxy_content"></div>');
});
function showScreen(_screen, screenNum) {
	sGal.imgPreload(screenNum);
	sGal.imgPreload(screenNum+1);
	sGal.imgPreload(screenNum-1);
	var isIE6 = $.browser.msie && $.browser.version == 6.0;
	var isIE7 = $.browser.msie && $.browser.version == 7.0;
	sGal.currentDisplayedScreen = screenNum;
	var $bNext = $('.boxyNextScreen', $('#boxy-closearea'));
	var $bPrev = $('.boxyPrevScreen', $('#boxy-closearea'));
	if(sGal.currentDisplayedScreen >= (sGal.imgs.length-1)) {
		if(!$bNext.hasClass('nextButtDisable'))
			$bNext.addClass('nextButtDisable');
	} else {
		if($bNext.hasClass('nextButtDisable'))
			$bNext.removeClass('nextButtDisable');
	}
	if(sGal.currentDisplayedScreen==0) {
		if(!$bPrev.hasClass('prevButtDisable'))
			$bPrev.addClass('prevButtDisable');
	} else {
		if($bPrev.hasClass('prevButtDisable'))
			$bPrev.removeClass('prevButtDisable');
	}
	var boxyPaddingLeft = 18;
	var boxyPaddingRight = 19;
	//alert('width:'+_screen['width']+', height:'+_screen['height']+', ie6:'+isIE6+' ie7:'+isIE7);
	b.show(true);
	b.resize(_screen['width'], _screen['height']);
	if(isIE6||isIE7)
		$('.boxy-wrapper').css( { width: (_screen['width']+boxyPaddingLeft+boxyPaddingRight)+'px' } );
	$('#astro_boxy_content').html(sGal.preloadImgs[screenNum]);
	b.center();
}
function showNextScreen() {
	var $bPrev = $('.boxyPrevScreen', $('#boxy-closearea'))
		if($bPrev.hasClass('prevButtDisable'))
			$bPrev.removeClass('prevButtDisable');
	if(sGal.currentDisplayedScreen < (sGal.imgs.length-1)) {
		sGal.imgPreload(sGal.currentDisplayedScreen);
		sGal.imgPreload(sGal.currentDisplayedScreen+1);
		if(sGal.currentDisplayedScreen < (sGal.imgs.length-2))
			sGal.imgPreload(sGal.currentDisplayedScreen+2);
		var $nextImg = $(sGal.preloadImgs[sGal.currentDisplayedScreen+1]);
		var $currentImg = $(sGal.preloadImgs[sGal.currentDisplayedScreen]);
		$nextImg.css('opacity',0);
		$nextImg.removeClass('displayNone');
		$('#astro_boxy_content').append($nextImg);
		$nextImg.animate({
			opacity: 1
		}, 400, function($cImg){return function(){$cImg.remove();}}($currentImg));
		sGal.currentDisplayedScreen++;
	} 
	if(sGal.currentDisplayedScreen >= (sGal.imgs.length-1)) {
		var $bNext = $('.boxyNextScreen', $('#boxy-closearea'))
		if(!$bNext.hasClass('nextButtDisable'))
			$bNext.addClass('nextButtDisable');
	}
}
function showPrevScreen() {
	var $bNext = $('.boxyNextScreen', $('#boxy-closearea'))
		if($bNext.hasClass('nextButtDisable'))
			$bNext.removeClass('nextButtDisable');
	if(sGal.currentDisplayedScreen!=0) {
		sGal.imgPreload(sGal.currentDisplayedScreen);
		sGal.imgPreload(sGal.currentDisplayedScreen-1);
		if(sGal.currentDisplayedScreen>1)
			sGal.imgPreload(sGal.currentDisplayedScreen-2);
		var $nextImg = $(sGal.preloadImgs[sGal.currentDisplayedScreen-1]);
		var $currentImg = $(sGal.preloadImgs[sGal.currentDisplayedScreen]);
		$nextImg.css('opacity',0);
		$nextImg.removeClass('displayNone');
		$('#astro_boxy_content').append($nextImg);
		$nextImg.animate({
			opacity: 1
		}, 400, function($cImg){return function(){$cImg.remove();}}($currentImg));
		sGal.currentDisplayedScreen--;
	}
	if(sGal.currentDisplayedScreen==0) {
		var $bPrev = $('.boxyPrevScreen', $('#boxy-closearea'))
		if(!$bPrev.hasClass('prevButtDisable'))
			$bPrev.addClass('prevButtDisable');
	}
}
Boxy.prototype._setupTitleBar = function() {
	if (this.options.title) {
		var self = this;
		var tb = jQuery("<div class='title-bar'></div>").html("<h2>" + this.options.title + "</h2>");
		var $prevButt = $('<span style="height:19px; width:19px; display:block;" class="boxyPrevScreen curPointer" ></span>');
		var $nextButt = $('<span style="height:19px; width:19px; display:block;" class="boxyNextScreen curPointer"></span>');
		$prevButt.mouseover(function($pButt) { return function(){$pButt.addClass('prevButtHover');}}($prevButt));
		$prevButt.mouseout(function($pButt) { return function(){$pButt.removeClass('prevButtHover');}}($prevButt)); 
		$nextButt.mouseover(function($nButt) { return function(){$nButt.addClass('nextButtHover');}}($nextButt));
		$nextButt.mouseout(function($nButt) { return function(){$nButt.removeClass('nextButtHover');}}($nextButt)); 
		$prevButt.click(function() {
			showPrevScreen();
		});
		$nextButt.click(function() {
			showNextScreen();
		});
		$('#boxy-closearea', this.boxy).append($prevButt);
		$('#boxy-closearea', this.boxy).append($nextButt);
		if (this.options.closeable) {
			$('#boxy-closearea', this.boxy).append(jQuery("<a href='#' class='close'></a>").html(this.options.closeText));
		}
		if (this.options.draggable) {
			tb[0].onselectstart = function() { return false; }
			tb[0].unselectable = 'on';
			tb[0].style.MozUserSelect = 'none';
			if (!Boxy.dragConfigured) {
				jQuery(document).mousemove(Boxy._handleDrag);
				Boxy.dragConfigured = true;
			}
			tb.mousedown(function(evt) {
				self.toTop();
				Boxy.dragging = [self, evt.pageX - self.boxy[0].offsetLeft, evt.pageY - self.boxy[0].offsetTop];
				jQuery(this).addClass('dragging');
			}).mouseup(function() {
				jQuery(this).removeClass('dragging');
				Boxy.dragging = null;
				self._fire('afterDrop');
			});
		}
		this.getInner().prepend(tb);
		this._setupDefaultBehaviours(tb);
	}
}
Boxy.prototype._setupDefaultBehaviours = function(root) {
	var self = this;
	if (this.options.clickToFront) {
		root.click(function() { self.toTop(); });
	}
	jQuery('.close', this.boxy).click(function() {
		self.hide();
		return false;
	}).mousedown(function(evt) { evt.stopPropagation(); });
}
Boxy.prototype.show = function() {
        if (this.visible) return;
        if (this.options.modal) {
            var self = this;
            if (!Boxy.resizeConfigured) {
                Boxy.resizeConfigured = true;
                jQuery(window).resize(function() { Boxy._handleResize(); });
            }
            this.modalBlackout = jQuery('<div class="boxy-modal-blackout"></div>')
                .css({zIndex: Boxy._nextZ(),
                      opacity: 0.7,
                      width: jQuery(document.body).width(),
                      height: jQuery(document).height()})
                .appendTo(document.body);
            this.toTop();
            if (this.options.closeable) {
                jQuery(document.body).bind('keypress.boxy', function(evt) {
                    var key = evt.which || evt.keyCode;
                    if (key == 27) {
                        self.hide();
                        jQuery(document.body).unbind('keypress.boxy');
                    }
                });
            }
        }
        this.boxy.stop().css({opacity: 1}).show();
        this.visible = true;
        this._fire('afterShow');
        return this;
    }
/*screens gallery*/
var screensGallery = function(id) {
	this.id = id;
	this.imgs = new Array();
	this.buttPrev = '';
	this.buttNext = '';
	this.gallery = '';
	this.screenWidth = 178;
	this.currentPage =0;
	this.pages = 0;
	this.onPage = 5;
	this.nextFunc = '';
	this.prevFunc = '';
	this.preloadImgs = Array();
	this.currentDisplayedScreen = -1;
}
screensGallery.prototype.imgPreload = function(screenNum) {
	if(this.preloadImgs[screenNum]==-1) {
		this.preloadImgs[screenNum] = $(this.imgs[screenNum]['img']);
		this.preloadImgs[screenNum].unselectable();
	}
}
screensGallery.prototype.initImgPreloadArray = function() {
	for(var i=0; i<this.imgs.length; i++) {
		this.preloadImgs[i] = -1;
	}
}
screensGallery.prototype.addElement = function(obj) {
	this.imgs[this.imgs.length] = obj;
}
screensGallery.prototype.addArrElement = function(arr, obj) {
	arr[arr.length] = obj;
}
screensGallery.prototype.showNext = function() {
	if(this.imgs.length>this.onPage)
		this.buttPrev.removeClass('disabled');
	if(this.currentPage<(this.pages-1)) {
		if(this.currentPage==(this.pages-2)) {
			this.buttNext.addClass('disabled');
			this.buttNext.unbind('click', this.nextFunc);
		}
		this.currentPage++;
		$('.screens', this.gallery).animate({'left': '-'+(this.screenWidth*this.onPage*this.currentPage)+'px'}, 500);
		this.buttPrev.bind('click', this.prevFunc);
	}
}
screensGallery.prototype.showPrev = function() {
	this.buttNext.removeClass('disabled');
	if(this.currentPage>0) {
		if(this.currentPage == 1) {
			this.buttPrev.addClass('disabled');
			this.buttPrev.unbind('click', this.prevFunc);
		}
		this.currentPage--;
		$('.screens', this.gallery).animate({'left': '-'+(this.screenWidth*this.onPage*this.currentPage)+'px'}, 500);
		this.buttNext.bind('click', this.nextFunc);
	}
}
function screenWidth(){
	if(window.innerWidth){
		width = window.innerWidth;
		} else if(document.documentElement && document.documentElement.clientWidth){
		width = document.documentElement.clientWidth;
		} else if(document.body && document.body.clientWidth){
		width = document.body.clientWidth;
	}
	return width;
}
screensGallery.prototype.initGallery = function() {
	this.gallery = $('#'+this.id);
	this.buttPrev = $('#butt_prev', this.gallery);
	this.buttNext = $('#butt_next', this.gallery);
	this.pages =Math.floor(this.imgs.length/5);
	var modulous = this.imgs.length%5;
	if(modulous>0)
		this.pages++;
	if(this.imgs.length>5) {this.buttNext.removeClass('disabled');}
	this.nextFunc = function(t){return function(){t.showNext()}}(this);
	this.prevFunc = function(t){return function(){t.showPrev()}}(this);
	this.buttNext.bind('click', this.nextFunc);
	this.initImgPreloadArray();
}
function setScreenImgWidth() {
	document.getElementById("scroll_independence").style.width = ( ( screenWidth( ) ) - 20)+"px";
}