var prev;
window.addEvent('domready', function() {
	prev = $('main');
	$('loading').setStyle('opacity',0);
	$('header_flash').setHTML(showflash( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','702','height','156','src','mgl1','wmode','opaque','quality','high','movie','mgl1' ));
	var nav = $('navigation');
	var cont = $('loadCont');
	nav.removeClass('hover');
	nav.addClass('no_hover');
	homepage();
	var navvs = $$('#navigation li');
	navvs.each(function(e,i){
		if( 1 ) {
			var fx = new Fx.Styles(e.getFirst(), {duration:400, wait:false});
			e.addEvent("mouseenter",function(){
				fx.start({'opacity':0.001});	
			});
			e.addEvent("mouseleave",function(){
				fx.start({'opacity':1});	
			});
		}
		e.addEvent("click",function(el){
			openSite(el,e,cont);
		});
	});
	$$('#footer_menu a').each(function(e,i){
		e.addEvent("click",function(el){
			openSite(el,navvs[i],cont);
		});		
	});
	home_gallery(cont);
	galleryC();
});
function homepage() {
	var cont = $('loadCont');
	$$('.newslist').each(function(e){
		e.addEvent('click',function(el){
			el = new Event(el).stop();
			loadAjax(e.getProperty('href'),cont);
			$('main').addClass('noactive');
			$('main').removeClass('active');
		});
	});
}
var i;
function openSite(el,e,cont,gall) {
	elm = new Event(el).stop();
	if ( !e.hasClass('active') ) {
		prev.removeClass('active');
		prev.addClass('noactive');		
		e.removeClass('noactive');
		e.addClass('active');
		prev = e;
		loadAjax(e.getFirst().getProperty('href'),cont,gall);
	}
}

function loadAjax(what,where,gall,servcs,galcat) {
	if( gall ) {
		var dupa = gall.split(':');
		var dipwhat = what+'&cat='+dupa[1]+'&catid='+dupa[2];
	}
	var url = what;
	if( dipwhat ) {
		url = dipwhat;
	}
	var fx = new Fx.Styles($('loading'), {duration:200, wait:false});
	fx.start({'opacity':0.7});
	new Ajax(url+'&noheader', {
		method: 'get',
		update: where,
		onComplete: function() {
			fx.start({'opacity':0});
			if( what == '?page=gallery' || galcat ) {
				i = 0;
				galleryC();
				if(gall) {
					play(playerOne,dupa[0]);
					$('movietitle').setText(dupa[3]);
				}
			} else if ( what == '?page=home' ) {
				homepage();
				home_gallery(where);
			} else if ( what == '?page=services' || servcs ) {
				servc();
			} else if ( what == '?page=contact' ) {
				sendMail();
			}
			SI_init();
		}
	}).request();
}
function sendMail() {
	var logs = $('sendmail');
	logs.addEvent('submit', function(e) {
		new Event(e).stop();
		this.send({
			update: logs
		});
	});
}
function servc() {
	var list = $$('.servcl');
	list.each(function(e){
		e.addEvent('click',function(el){
			el = new Event(el).stop();
			loadAjax(e.getProperty('href'),$('loadCont'),false,true)
		});
	});
}
