Shadowbox.init({
	skipSetup: false,
	adapter: 'base',
	language: 'en',
	overlayColor: '#000000',
	overlayOpacity: '0.9',
	handleOversize: 'drag',
	players: ["img"]
});

function fixpng(){
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (document.body.filters) && (version < 7)){
		var png_images = $$('.pngfix');	
		png_images.each(function(element) {
			if(!$(element).hasClass('pngfixed')){
				$(element).addClass('pngfixed');
				var img = $(element);
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.getProperty('width') + "px; height:" + img.getProperty('height') + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML					
			}
		});
	} else {
		$$('.pngfix').addClass('pngfixed');
	}
}

var scrollFx = new Fx();

function scroll_to(in_el){
	scrollFx.cancel();
	var center = Math.max(0, Math.round(($('body').getSize().x/2) - ($(in_el).getSize().x/2)));
	scrollFx = new Fx.Scroll($('site'), {duration: 1500, transition: Fx.Transitions.Quad.easeInOut}).start($(in_el).getPosition('container').x - center, 0);	
}

function init(){
	fix();
	fixpng();
	
	if(Browser.Platform.ios){
		var myDragInstance = new Drag($('container'), {modifiers: {'x': 'left', 'y': false}});
		var touchstart = 0;
		$('container').addEvent('touchstart', function(e){
			var touch = e.touches[0];
			touchstart = touch.pageX; 
		})
		$('container').addEvent('touchmove', function(e){
			  if(e.touches.length == 1){ 
			  	e.preventDefault();
			    var touch = e.touches[0];
			    delta = (touch.pageX - touchstart);
			    touchstart = touch.pageX;
			    $('container').setStyle('left', $('container').getPosition().x+delta+'px');
			  } 
		});
	}
	
	pi = 0;
	
	//	setup menu links
	$$('.rlink').each(function(el,i){
		if(el.get('rel')){
			el.removeEvents('click'); 
			el.addEvent('click', function(e){
				if (e) new Event(e).stop();	
				scroll_to(el.get('rel'));
			});
		}	
	});
	
	//	setup info links
	$$('.infolink').each(function(el,i){
		if(id = el.get('id').substring(5)){
			var mel = $('infocontainer_'+id); 
			mel.setStyle('opacity', 0);
			el.addEvent('mouseenter', function(){
				if(mel.fx) mel.fx.cancel();
				mel.setStyle('display', 'block');
				mel.fx = new Fx.Tween(mel, {duration: 1000}).start('opacity', mel.getStyle('opacity'), 0.8);
			});
			el.addEvent('mouseleave', function(){
				if(mel.fx) mel.fx.cancel();
				mel.fx = new Fx.Tween(mel, {duration: 1000, onComplete: function(){ mel.setStyle('display', 'none'); }}).start('opacity', mel.getStyle('opacity'), 0);
			});
		}
	});
	
	//	setup popup links
	$$('.plink').each(function(el,i){
		if(el.get('rel')){
			el.removeEvents('click'); 
			el.addEvent('click', function(e){
				if (e) new Event(e).stop();	
				EB.window.popup(SITE_ROOT+'page=site.'+el.get('rel'), 'popup'+(pi++), 350, 270);
			});
		}	
	});
	
	//	setup contact links
	$$('.clink').each(function(el,i){
		if(el.get('rel')){
			el.removeEvents('click'); 
			el.addEvent('click', function(e){
				if (e) new Event(e).stop();	
				EB.window.popup(SITE_ROOT+'page=site.'+el.get('rel'), 'popup'+(pi++), 350, 450);
			});
		}	
	});
	
	//	setup video links
	$$('.vlink').each(function(el,i){
		if(el.get('rel')){
			el.removeEvents('click'); 
			el.addEvent('click', function(e){
				if (e) new Event(e).stop();	
				EB.window.popup(SITE_ROOT+'page=site.'+el.get('rel'), 'youtube'+(pi++), 600, 360);
			});
		}	
	});
	
}

function fix(){
	//	create dynamic spacers
	$$('td.spacer').set('html', '<div style="width: 5px; height: 1px"></div>');
	$$('td.colspacer').set('html', '<div style="width: 20px; height: 1px"></div>');
	$$('td.begin').set('html', '<div style="width: '+Math.round(($('body').getSize().x/2)-($('start').getSize().x/2))+'px; height: 1px;"/></div>');
	$$('td.end').set('html', '<div style="width: '+Math.round(($('body').getSize().x/2)-($('thanx').getSize().x/2))+'px; height: 1px;"></div>');
}

window.addEvent('domready', init);
window.addEvent('resize', fix);
