﻿function centerdiv(elem)
{
	sizes = window.getSize();
	scrollito = window.getScroll();
	$(elem).setStyles({
		'position': 'absolute',
		'display': 'block',
		'left': (scrollito.x + (sizes.x - $(elem).getSize().x) / 2).toInt(),
		'top': (scrollito.y + (sizes.y - $(elem).getSize().y) / 2).toInt()
	});
}

function uploadFile(elem)
{
	sizes = window.getSize();
	scrollito = window.getScroll();
	$(elem).setStyles({
		'position': 'absolute',
		'width': '500px',
		'height': '170px',
		'display': 'block',
		'left': (scrollito.x + (sizes.x - 500) / 2).toInt(),
		'top': (scrollito.y + (sizes.y - 200) / 2).toInt()
	});
}

function openURLBlank(href)
{
	window.open(href);
}

function openPicture(el)
{
//	Slimbox.open($(el).value, "")

		var remooz = new ReMooz($(el), {
			'link': $(el).value,
			'origin': 'img',
			'shadow': 'onOpenEnd',
			'resizeFactor': 0.9,
			'cutOut': false,
			'opacityResize': 0.4,
	//		'dragging': false,
			'temporary': true,
			'centered': true
		});
		remooz.open();
}

function DisplayWizardMenuItems()
{
	sizes = window.getSize();
	scrollito = window.getScroll();
	$('WizardMenuItems').setStyles({
		'position': 'absolute',
		'width': '500px',
		'height': '140px',
		'display': 'block',
		'left': (scrollito.x + (sizes.x - 500) / 2).toInt(),
		'top': (scrollito.y + (sizes.y - 140) / 2).toInt()
	});
}

function UndisplayWizardMenuItems()
{
	$('WizardMenuItems').setStyle('display', 'none');
}

function Mid(str, start, len)
{
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}

window.addEvent('domready', function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var aLinkExternal = $$("a");	
	var classLinkExternal = $$(".linkexternal");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className = "external_link";
	};	
	for (var i=0;i<aLinkExternal.length;i++){
		if(check(aLinkExternal[i])) set(aLinkExternal[i]);
	};		
	for (var i=0;i<classLinkExternal.length;i++){
		set(classLinkExternal[i]);
	};		
});

window.addEvent('load', function() {
	if (self.ReMooz !== undefined) {
		ReMooz.assign('.ZoomReMooz', {
			'origin': 'img',
			'shadow': 'onOpenEnd',
			'resizeFactor': 0.9,
			'cutOut': false,
			'opacityResize': 0.4,
	//		'dragging': false,
			'centered': true
		});
	};
});

window.addEvent('load', function() {
	$$('.block-ul-slide').each(function(item){
		var elToSlide=new Fx.Slide(item.getElement('.block-ul-toslide'));
		elToSlide.hide();
		item.getElement('.block-ul-click-slide').addEvent('click',function(e) {
			e.stop();
			elToSlide.toggle();
			if (elToSlide.open==true) 
				{
					this.removeClass('block-ul-open');
					this.addClass('block-ul-close');
				}
			else
				{
					this.removeClass('block-ul-close');
					this.addClass('block-ul-open')
				}
		});
	});
});

window.addEvent('domready', function() {
	$$('.mootable-resizable').each(function(item){
		new MooTable( item, {sortable: true, resizable: true, height: '450px'});
	});
});

window.addEvent('domready', function(){

/*	var dispose = new Element('span', {'class': 'dispose', text: '(remove)'}).addEvents({
		mousedown: function(e){
			e.stop();
		},
		click: function(){
			this.getParent('li').dispose();
		}
	});*/

	// Example #2
	$$('.collapse').each(function(item){
		new Collapse(item);
	});
});
