/*                    
					WWWWWWWWWW. ,WWWWWWWWWWW                         
				   WWWWWWWWWWWW. WWWWWWWWWWWW                         
				   WWWWWWWWWWWW.+WWWWWWWWWWWW                         
				   WWWWWWWWWWWW.+WWWWWWWWWWWW                         
				   WWWWWWWWWWWW.+WWWWWWWWWWW#                         
				   WWWWWWWWWWWW.+WWWWWWWWWW#                          
				   WWWWWWWWWWWW.                                      
	 ##########.   WWWWWWWWWWWW.:##########                           
	 WWWWWWWWWWW@  WWWWWWWWWWWW.+WWWWWWWWWWW,                         
	 WWWWWWWWWWWW. WWWWWWWWWWWW.+WWWWWWWWWWWW                         
	 WWWWWWWWWWWW# WWWWWWWWWWWW.+WWWWWWWWWWWW                         
	 WWWWWWWWWWWW# WWWWWWWWWWWW,,WWWWWWWWWWWW                         
	  WWWWWWWWWWW# WWWWWWWWWWW@  @WWWWWWWWWWW                         
	  ,WWWWWWWWWW# WWWWWWWWWW*    *WWWWWWWWWW  
*/

// set global defaults

var lang;
lang = "en";
var modes = new Array('business','fancy');
var mode;
mode = "0";
var style;
var detail;
detail = false;
var currentPid;
var projectImages;
var projectImagesFull;
var imageId;
var nextAid;
var prevAid;
var randomAid;
var nextPid;
var prevPid;
var randomPid;
var nProjects;
nProjects = 0;

// advertisement
var adTimeout = 10000;
var adTimer;

// slideshow timer
var slideshowTimeout = 5000;
var slideshowTimer;

var calendarMode;

// init application
function init() {	
	setBodyMargin();		
	initHistory();	
	//activateAdTimer();
	//updateTime();
	fillModules(true);	
	//$('yeller').style.left = '00px';
	//$('yeller').style.top = '0px';	
}

function ask() {
	loadContentArea('id=jk&tx_jk[show]=ask&tx_jk[ask]='+$('frmAskInput').value+'&cHash=ugu','answer',false);	
}

function setYell() {
	loadContentArea('id=jk&tx_jk[show]=setyell&tx_jk[yell]='+$('frmyellinput').value+'&cHash=ugu','yeller',false);	
}

function getYell() {
	loadContentArea('id=jk&tx_jk[show]=getyell&cHash=ugu','yeller',false);	
}

function swapRandorama(mod) {
	//alert(mod);
	loadContentAreaIntoTab($('mod_bot_left'),'&tx_jk[show]=randorama');	
}

function initProjects() {	
	var tabs = new Array('Projects');
	var actions = new Array('&tx_jk[show]=project');	
	fillModule("project",tabs,actions);
}

function fadeModIn() {
	
	/*
	var inDuration = 0.3;	
	
	$('mod_top_left').style.display = 'none';
	//$('mod_top_left').style.display = 'none';
	//$('mod_mid_left').style.display = 'none';
	$('mod_bot_left').style.display = 'none';
	$('mod_top_right').style.display = 'none';
	//$('mod_mid_right').style.display = 'none';
	$('mod_bot_right').style.display = 'none';	
	
	//$('logo_mid').style.display = 'none';
	//new Effect.Appear('logo_mid', { queue: 'end',duration:inDuration});
	
	//$('modePick').style.display = 'none';
	//new Effect.Appear('modePick', { queue: 'end',duration:inDuration,to:0.7});
	//new Effect.Appear('modePick', { queue: 'end',duration:inDuration,to:0.7});
	//new Effect.Pulsate('modePick', { queue: 'end'});
	
	new Effect.DelayedChain('Appear', $$('.mod'), { duration: 0.5 }, 100);
	// Fires an Effect.Appear for each element with a delay of 100 m
	
	//$('yeller').style.display = 'none';	
	//new Effect.Appear('yeller', { queue: 'end',duration:1,to:0.2});	
	*/
}

function fadeContentIn(target) {

	//$(target).style.display = 'none';	
	//new Effect.Appear(target, { queue: 'end', duration:0.4});

}
/*
Effect.DelayedChain = Class.create();
Object.extend(Effect.DelayedChain.prototype, {
    initialize: function(effect, elements, options, timeout){
        this.elements = elements;
        this.effect = effect;
        this.timeout = timeout || 100;
        this.options = Object.extend({}, options || {});

        this.afterFinish = this.options.afterFinish || Prototype.emptyFunction;
        this.options.afterFinish = Prototype.emptyFunction;
        setTimeout(this.action.bind(this),1);
    },
    action: function() {
        if(this.elements.length){ 
            new Effect[this.effect](this.elements.shift(), this.options);
            setTimeout(this.action.bind(this), this.timeout);
        } else {
            if(this.afterFinish) this.afterFinish();
        }
    }
});

Effect.Chain = Class.create();
Object.extend(Effect.Chain.prototype, {
    initialize: function(effect, elements, options){
        this.elements = elements || [];
        this.effect = effect;
        this.options = options || {};
        this.afterFinish = this.options.afterFinish || Prototype.emptyFunction;
        this.options.afterFinish = this.nextEffect.bind(this);
        setTimeout(this.nextEffect.bind(this), 1);
    },
    nextEffect: function(){
        if(this.elements.length)
            new Effect[this.effect](this.elements.shift(), this.options);
        else
            this.afterFinish();
    }
});
*/
function fillModules(isHistoryCall) {
	if (mode == 1) {
		
		var tabs = new Array('Location','Kids','Info','Email');
		var actions = new Array('&tx_jk[show]=location','&tx_jk[show]=kids','&tx_jk[show]=info','&tx_jk[show]=emailform');	
		fillModule("mod_top_left",tabs,actions);
		
		
		var tabs = new Array('Links','Clients');
		var actions = new Array('&tx_jk[show]=links','&tx_jk[show]=client');	
		fillModule("mod_mid_left",tabs,actions);
		
		var tabs = new Array('Advertisements','Randorama');
		var browser = new Array(true,true);	
		var fncts = new Array('','resetAdTimer();');
		var actions = new Array('&tx_jk[show]=advertisement','&tx_jk[show]=randorama');	
		fillModule("mod_bot_left",tabs,actions,fncts,browser);	
		
		var tabs = new Array('News');
		var actions = new Array('&tx_jk[show]=news');	
		fillModule("mod_top_right",tabs,actions);	
		
		var tabs = new Array('Decide','Ask','Yell');
		var actions = new Array('&tx_jk[show]=decide','&tx_jk[show]=askForm','&tx_jk[show]=yeller');	
		fillModule("mod_mid_right",tabs,actions);
		
		var tabs = new Array('Quotes','Freebies');
		var browser = new Array();	
		var actions = new Array('&tx_jk[show]=quotes','&tx_jk[show]=freebies');	
		fillModule("mod_bot_right",tabs,actions,new Array(),browser);
		
		if (!isHistoryCall) {		
			var historyObj = new Object();								
			historyObj['mode'] = modes[mode];
			historyObj['action'] = 'init';	
			historyObj['info'] = 'init mode '+modes[mode];
			setHistoryStorage("init_"+modes[mode],historyObj);
		}
	
	} else {
		
		var tabs = new Array('Neu');
		//var actions = new Array();	
		var actions = new Array('&tx_jk[show]=news');	
		fillModule("mod_top_left",tabs,actions);
		
		//var tabs = new Array('Clients');
		//var actions = new Array('&tx_jk[show]=client');	
		//fillModule("mod_mid_left",tabs,actions);
		
		//var tabs = new Array('Advertisements');
		//var actions = new Array('&tx_jk[show]=advertisement');	
		//var browser = new Array(true);	
		//fillModule("mod_bot_left",tabs,actions,new Array(),browser);
		
		var tabs = new Array('Clients');
		var actions = new Array('&tx_jk[show]=client');	
		//var browser = new Array(true);	
		fillModule("mod_bot_left",tabs,actions);
		
		var tabs = new Array('Contact');
		var actions = new Array('&tx_jk[show]=contact');	
		fillModule("mod_top_right",tabs,actions);
		
		var tabs = new Array('Email');
		var actions = new Array('&tx_jk[show]=emailform');	
		fillModule("mod_bot_right",tabs,actions);
		
		//var tabs = new Array('We are online!');
		//var actions = new Array('&tx_jk[show]=impress');	
		//fillModule("mod_bot_right",tabs,actions,new Array(),new Array());
		
		if (!isHistoryCall) {			
			var historyObj = new Object();								
			historyObj['mode'] = modes[mode];
			historyObj['action'] = 'init';	
			historyObj['info'] = 'init mode '+modes[mode];
			setHistoryStorage(StateManager.defaultStateID,historyObj);			
		}
		
	}
	fadeModIn();	
	initProjects();
	//clearBrowserBg();
	closeFullImage();
	

}

function setBrowserBg (mod) {
	$(mod).addClassName('browser'); 
}

function clearBrowserBg (mod) {
	$$(mod).removeClassName('browser'); 
}

	

function swapMode(isHistoryCall) {
	var arr = $$('#project .content')
	arr[0].innerHTML = '';
	//console.debug($$('#project .content'));
	if (mode == 0) {
		mode = 1;		
		assignCSS("fancy");
		fillModules(isHistoryCall);
	} else {
		mode = 0;
		assignCSS("business");
		fillModules(isHistoryCall);	
	}	
}

var dynCSS = document.createElement("link");
	
function assignCSS(css) {	
	dynCSS.href = "fileadmin/jealouskid/templates/css/"+css+".css";
	dynCSS.rel = "stylesheet";
	dynCSS.type = "text/css";
	document.getElementsByTagName("head")[0].appendChild(dynCSS);	
}


function fillModule(mod, tabs, actions,fncts,browser) {	
	var fnctCall = '';
	var tabContent = '';			
	if (tabs.length == 1) {		
		tabContent += '<span class="noTab">'+tabs[0]+'</span>';		
		//actions = actions[0];
	} else {		
		tabContent += '<ul>';
		for (var index = 0; index < tabs.length; ++index) {
			$(mod).removeClassName('browser'); 
			fnctCall = '';
			if (fncts && fncts[index]) {
				fnctCall = fncts[index];
			}
			if (browser && browser[index]) {
				
				fnctCall += 'setBrowserBg('+mod+');';
			}
			tabContent += '<li class="tab"><a onfocus="blur();" onclick="changeTab(\''+mod+'\','+index+');loadContentAreaIntoTab(\''+mod+'\',\''+actions[index]+'\');'+fnctCall+'" href="#">'+tabs[index]+'</a></li>';
		}		
		tabContent += '</ul>';	
	}
	var	tabElement_arr = $(mod).getElementsByClassName('tabs')	
	var tabElement = tabElement_arr[0];	
	tabElement.innerHTML = tabContent;
	
	// now get random tab and open
	if (tabs.length > 1) {	
		var randNum =  Math.floor(Math.random()*tabs.length);
		changeTab(mod,randNum);
		actionToLoad = actions[randNum];
		
		// check if a function needs get get called
		
		if (fncts && fncts[randNum]) {
			window[fncts[randNum]];			
		}
		if (browser && browser[randNum]) {
				setBrowserBg(mod);
		}
	} else {
		actionToLoad = actions[0];
		if (browser && browser[0]) {
			setBrowserBg(mod);
		}
		if (fncts && fncts[0]) {
			window[fncts[randNum]];			
		}
	}
	if (actionToLoad){
		loadContentAreaIntoTab(mod,actionToLoad);		
	} else {
		// todo not nice really ;)
		loadContentAreaIntoTab(mod,'');		
	}
}

function changeTab(mod,curIndex) {
	var tabs = $$('#'+mod+' .tabs li');	
	for (var index = 0; index < tabs.length; ++index) {	
		var tab = tabs[index];	
		if (curIndex == index) {
			tab.addClassName('act');		
		} else {			
			tab.removeClassName('act');
		}
	}
}


// ad timer functions
function resetAdTimer() {	
	if (adTimer) {
		 window.clearTimeout(adTimer)
	}
}
function activateAdTimer() {	
	adTimer = window.setTimeout("adTimerCallBack()", adTimeout);
}

function adTimerCallBack() {
	 loadAdvertisement(randomAid);
	 activateAdTimer();
}

// slideshow timer functions
function resetSlideshowTimer() {	
	if (slideshowTimer) {
		 window.clearTimeout(slideshowTimer)
	}
}
function activateSlideshowTimer() {	
//alert("test");
	slideshowTimer = window.setTimeout("slideshowTimerCallBack()", slideshowTimeout);
}

function slideshowTimerCallBack() {	
	loadProjectImage('+'); 
	activateSlideshowTimer();
}

function getRandomStyle() {	
	var theStyle = "0"+Math.round(Math.random()+1).toString();
	return theStyle;
}

function setStyle(newStyle) {
	style=newStyle;
	switchLang(lang);
	var container = document.getElementById('container');	
	container.style.backgroundImage = "url('./fileadmin/jealouskid/templates/img."+style+"/background.png')";
}

// update tutti
function loadContent() {
	resetAdTimer();
	clearMailForm();
	detail = false;	
	
	//loadContentArea('id=gw&tx_gw[mode]='+ mode +'&tx_gw[show]=profile&tx_gw[lang]='+ lang +'&cHash=ugu','profile',false);	
	loadContentArea('id=jk&tx_jk[mode]='+ mode +'&tx_jk[show]=project&tx_jk[lang]='+ lang +'&cHash=ugu','project',true);
}


function loadContentAreaIntoTab(mod,action) {	
	var theTarget = $(mod).getElementsByClassName('content');
	theTarget = theTarget[0];	
	loadContentArea('id=jk&'+ action+'&cHash=ugu',theTarget,false);
}

// load certain area
function loadContentArea(pars,target,javascriptEval){
		
 	// window.console.log("test"); 
	javascriptEval = true;
	var url = 'http://www.jealouskid.net/index_jk.php';	
	pars = pars + '&tx_jk[mode]='+mode;
	theTarget = target;	
	
	if (javascriptEval) {		
		theAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, evalScripts: true, onComplete:fadeContentIn(target)});		
	} else {
		theAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, onComplete:fadeContentIn(target)});	
	}
}


function switchCalendarMode(newMode){	
	calendarMode = newMode
	loadContentArea('id=gw&tx_gw[calendarMode]='+ calendarMode +'&tx_gw[show]=calendar&tx_gw[lang]='+ lang +'&cHash=ugu','calendar');
	updateCalendarNavi();	
}

function updateCalendarNavi(){	
	var internalObj = document.getElementsByClassName('internal')[0];	
	var externalObj = document.getElementsByClassName('external')[0];	
	if (calendarMode) {		
		internalObj.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/internal.'+lang+'.gif" />';		
		externalObj.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/external.ro.'+lang+'.gif" />';
		
	} else {			
		internalObj.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/internal.ro.'+lang+'.gif" />';		
		externalObj.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/external.'+lang+'.gif" />';
		
	}		
}

// update set of items defined by class name
function updateImages(theClassName){
	//alert(theClassName+' - '+modes[mode]);
	var ro = '';	
	if (modes[mode] === theClassName) {		
		ro = '.ro';		
	}	
	var items = document.getElementsByClassName(theClassName);	
	for (i in items) {		
		items[i].innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/'+theClassName+ro+'.'+lang+'.gif"/>';	 
	}	
}

function switchMode(newMode){
	// reset old mode buttons
	resetMode = mode;
	mode = '';
	updateImages(modes[resetMode]);	
	// set new buttons
	mode = newMode;
	updateImages(modes[newMode]);
	// update content
	loadContent();
}

function filterProjectByClient(clientName,isHistoryCall) {
	//var arr = $$('#project .content')
	//arr[0].innerHTML = '';
	//window.console.log("filterProjectByClient: "+clientName);
	
	detail = false;
	updateProjectNavi();
	loadContentAreaIntoTab('project','id=jk&tx_jk[show]=project&tx_jk[filter]=client_en&tx_jk[filter_value]='+clientName);
	if (FullscreenMode) {
		closeFullImage();
	}
	if (!isHistoryCall) {
		var historyObj = new Object();								
		historyObj['mode'] = modes[mode];
		historyObj['action'] = 'filter';
		historyObj['clientName'] = clientName;	
		historyObj['info'] = 'filter projects by '+clientName;
		//setHistoryStorage("filter_"+encodeURI(clientName),historyObj); 	
		setHistoryStorage("filter_"+Math.floor(Math.random()*5000),historyObj); 	
		
		trackEvent('/clients/'+clientName);
		
	}	
}


// load project details
function loadProjectDetail(pid,isHistoryCall,title) {
	//console.debug("loadProjectDetail "+pid);
	//console.debug("aElement "+title);
	currentPid = pid;
	detail = true;
	updateProjectNavi();
	loadContentAreaIntoTab('project','id=jk&tx_jk[show]=projectDetail&tx_jk[projectId]='+pid+'&cHash=ugu');
	
	if (isHistoryCall == null) {		
		//console.debug("history loadProjectDetail "+pid);
		
		// define history storage object	
		var historyObj = new Object();
		historyObj['mode'] = modes[mode];
		historyObj['pid'] = pid;
		historyObj['action'] = 'projectDetails';	
		historyObj['info'] = 'load project detail for project '+pid;
		//dhtmlHistory.add("pid_"+pid,historyObj);		
		setHistoryStorage("projectDetails_"+pid,historyObj);
		trackEvent('/projects/'+title);
	}
}

function trackEvent(trackingCode) {
	urchinTracker(trackingCode);
	//console.debug(trackingCode);
	//alert(trackingCode);	
}


function loadAdvertisement(aId){	
	resetAdTimer();	
	loadContentAreaIntoTab('mod_bot_left','tx_jk[show]=advertisement&tx_jk[aId]='+ aId);
}


// debug object
function debug(input) {
	var ret;
	for (var i in input) {		
		ret += "["+i+"] = "+input[i]+"\n";		
	}
	alert(ret);
	
}
// swap image based on class name
// if onelang set then dont add .en / .de
function swapImage(callingObj,oneLang) {	
	var theLang = '.'+lang;	
	if (oneLang) {		
		theLang = '';
	}	
	callingObj.firstChild.src = './fileadmin/jealouskid/templates/img.'+style+'/navigation/'+callingObj.className+'.ro'+theLang+'.gif';
}
// restore image based on class name of calling obj
// special handling of project and image navi
// if onelang set then dont add .en / .de
function swapImgRestore(callingObj,oneLang) {
	var theLang = '.'+lang;	
	if (oneLang) {		
		theLang = '';
	}
	var ro = '';	
	
	if (modes[mode] === callingObj.className || (callingObj.className === 'list' && !detail) || (callingObj.className === 'detail' && detail) || (callingObj.className - 1) == imageId || ((callingObj.className === 'external' && calendarMode) || (callingObj.className === 'internal' && !calendarMode))) {		
		ro = '.ro';		
	} 	
	callingObj.firstChild.src = './fileadmin/jealouskid/templates/img.'+style+'/navigation/'+callingObj.className+ro+theLang+'.gif';
}
// update top list detail switch
// and hid bottom of project box navi
function updateProjectNavi() {
	if (detail) {		
		parent.$('browserProject').style.display = 'inline';	
	} else {
		parent.$('browserProject').style.display = 'none';	
	}
}

function loadProjectList (){
	detail = false;
	loadContentAreaIntoTab('project','id=jk&tx_jk[show]=project&cHash=ugu');
	updateProjectNavi();
}

var headLines = new Array('gw','departments','calendar','links','projects','profile','email','ad','contact');

function updateHeadlines(){
	var hlObj;
	for (headLine in headLines) {		
		hlObj = document.getElementById('headLine_'+headLines[headLine]);		
		if (hlObj) {		
			hlObj.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/headlines/'+headLines[headLine]+'.'+lang+'.gif" />';
		}		
	}	
}

function loadProjectImage(action){	
	switch (action) {					
		case "+":
			imageId ++;
			if (imageId > (projectImages.length-1)) {
				imageId = 0;
			}
			break;
		case "-":
			imageId --;
			if (imageId < 0) {
				imageId = projectImages.length-1;
			}
			break;		
		default:
			imageId = action;
			break;
	}
	
	if (FullscreenMode){
		
		var imageBrowser = document.getElementsByClassName('browserImage');	
		imageBrowser = imageBrowser[0];
		
		var projectImageDiv = document.getElementById('imageFull');
		// update image div
		projectImageDiv.innerHTML = '<a href="javascript:closeFullImage();">'+projectImagesFull[imageId]+'</a>';		
		
	} else {
		
		var projectImageDiv = document.getElementById('projectImage');
		// update image div
		projectImageDiv.innerHTML = '<a href="javascript:loadImageFull();">'+projectImages[imageId]+'</a>';	
		
	}	
	updateImageNavi();
}

var FullscreenMode;
FullscreenMode = false;

function loadImageFull(){	

	FullscreenMode = true;
	
	var imageBrowser = document.getElementsByClassName('browserImage');	
	imageBrowser = imageBrowser[0];

	var container = document.getElementById('imageFullContainer');	
	
	if (mode == 1) {	
		container.style.backgroundImage = "url('./fileadmin/jealouskid/templates/img/gallery-overlay.fancy.png')";	
	} else {
		container.style.backgroundImage = "url('./fileadmin/jealouskid/templates/img/gallery-overlay.business.png')";			
	}
		
	var projectTitle = $$('#project .headline');		
	projectTitle = projectTitle[0].innerHTML;
	$('imageFullHeadline').innerHTML = projectTitle;		
	
	var fullScreenNavi = $('imageFullNavi');		
	fullScreenNavi.innerHTML = '';	
	fullScreenNavi.innerHTML = imageBrowser.innerHTML;	
	
	var fullScreenImage = $('imageFull');		
	fullScreenImage.innerHTML = '';	
	fullScreenImage.innerHTML = '<a href="javascript:closeFullImage();">'+projectImagesFull[imageId]+'</a>';		
	
	var fullScreenLayer = $('imageFullContainer');	
	fullScreenLayer.style.visibility = 'visible';	
	fullScreenLayer.style.zIndex = '100';	
	
	// hack for ff mac to hide the scrollbar of underlying divs!
	
	//var projectDiv = document.getElementById('project');
	//projectDiv.style.display = 'none';
	
	//var projectDivContent = projectDiv.getElementByClass('content');
	//projectDivContent.style.display = 'none';
	
	//var projectDivModeSwitch = projectDiv.getElementByClass('content');
	//projectDivContent.style.display = 'none';
	
	var arr = $$('#project .content');
	arr[0].hide();
	$('projectMode').hide();
	$('browserProject').hide();
	
	//$$('#project tabs')
	
	//var adDiv = document.getElementById('advertisement');
	//adDiv.style.display = 'none';
}

function closeFullImage(){	

	FullscreenMode = false;	
	var fullScreenLayer = document.getElementById('imageFullContainer');	
	fullScreenLayer.style.visibility = 'hidden';
	fullScreenLayer.style.zIndex = '-1';	

	//var projectDiv = document.getElementById('project');
	//projectDiv.style.display = 'block';
	
	var arr = $$('#project .content');
	arr[0].show();
	$('projectMode').show();
	$('browserProject').show();
	$('browserProject').style.display = 'inline';
	
}

// update image navigation
function updateImageNavi() {
	var imageNaviButton;
	for (i=1;i<=projectImages.length+1;i++) {
		imageNaviButton = document.getElementsByClassName(i)[0];		
		if (imageNaviButton) {		
			if ((i-1) == imageId) {			
				imageNaviButton.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/'+i+'.ro.gif" />';			
			} else {	
				imageNaviButton.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/'+i+'.gif" />';				
			}
		}
		imageNaviButton = document.getElementsByClassName(i)[1];		
		if (imageNaviButton) {		
			if ((i-1) == imageId) {			
				imageNaviButton.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/'+i+'.ro.gif" />';			
			} else {	
				imageNaviButton.innerHTML = '<img src="./fileadmin/jealouskid/templates/img.'+style+'/navigation/'+i+'.gif" />';				
			}
		}
	}	
}
// upadet the area navigation (typo3 content doesnt know the style id!)
function updateAreaNavi() {
	updateImages('event');
	updateImages('vc');
	updateImages('general');
	updateImages('public');
}
// check browser
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

// check if screen resolution is small, then 0px top margin
function setBodyMargin(){	
	if (screen.height<=768){
	 document.body.style.marginTop = "0px";
	} else {
	 document.body.style.marginTop = "20px";
	}	
}

// handle mailing
function sendMail() {
	loadContentArea('id=gw&tx_jk[mode]='+ mode +'&tx_jk[show]=sendMail&tx_jk[name]='+ $('mailFormName').value +'&tx_jk[email]='+$('mailFormEmail').value+'&tx_jk[message]='+$('mailFormMessage').value+'&cHash=ugu','mailError',true);
}
// clear mail form, set inital values
function clearMailForm() {
	if (lang == 'en') {
		document.forms["mailForm"].elements["message"].value = 'Message';
	
	} else {
		document.forms["mailForm"].elements["message"].value = 'Nachricht';
	}
	document.forms["mailForm"].elements["email"].value = 'Email';
	document.forms["mailForm"].elements["name"].value = 'Name';
}

// get time and date string

function updateTime(){	
	var today = new Date();	
	d = new Date();
	var timeDisplay = document.getElementById('timeDisplay');	
	timeDisplay.innerHTML = d.formatDate("F dS Y h:i:s"); 	 
	window.setTimeout("updateTime()", 1000);	
}

// buttons rollover

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
