// JavaScript Document
function Lvl_openWin(u,n,w,h,l,t,c,f,x) { //v1.0 4LevelWebs
  	var ww=((screen.width-w)/2);
	if(c==1)
	{
		l=ww;
		t=(screen.height-h)/2;
	}
	if(c==2)
	{
		l=ww;
	}
	//f+=',top='+t+',left='+l;
	LvlWin = window.open(u,n,f);
	if(x==1)
	{
		LvlWin.focus()
	}
	document.MM_returnValue=false;
}
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 showHideCommingSoon(what) {
	if (!document.getElementById || what != "wien")
		return;
		
	var commingSoonGif = document.getElementById("portal-comming-soon-gif");
	
	if (commingSoonGif.style.display == "none") {
		commingSoonGif.style.display = "block";
	} else {
		commingSoonGif.style.display = "none";
	}
}

/// Ajax Projects
//////////////////////////////////////////////////////////////////////////////////////////////////////

var current_offset = new Object();
var current_category = new Object();
var active_nav = new Object();

var changeOffset = function ( offset, num_items, content_id, is_homepage, target_website ) 
{
	if (offset < 0)
		return;
		
	setDeepLink(current_category[content_id] + "," + offset, content_id);
		
	current_offset[content_id] = offset;	
				
	var content_div = document.getElementById("project_list_" + content_id);
	if (content_div && content_div.innerHTML)
		content_div.innerHTML = "<" + "img src='images/ajax-loading.gif' style='margin: 10px;' />"; 

	if ( typeof http != "undefined" ) {
		params = new Object(); 
		params.project_category_id = current_category[content_id];
		params.offset = "" + offset;
		params.num_items = num_items;
		params.content_id = content_id;
		params.target_website = target_website;
		http( "POST" , "custom/projects/ax_projects.cfc?method=getProjects" , populateProjects, params ); 
	}
	
	var path4tracker = window.location.pathname;
	if (window.location.search)
		path4tracker += window.location.search;
	
	path4tracker += "##" + current_category[content_id] + "," + offset;

	if (is_homepage)
		path4tracker = "/start/" + path4tracker;

	try {
		pageTracker._trackPageview(path4tracker);
	} catch(e) {
		// Google not initialised
	}
}

var changeCategoryInit = function ( e, category, startoffset, num_items, content_id, is_homepage, target_website ) {
	//// wird im onload aufgerufen
	if (e && getDeepLink() == "") {
		startoffset = startoffset == null ? 0 : startoffset;
		setDeepLink(category + "," + startoffset, content_id);
		current_category[content_id] = category;
		current_offset[content_id] = startoffset;
		return;
	} else if (e) {
		var catoff = getDeepLink().split(",");
		category = catoff[0];
		startoffset = catoff[1];
	}

	setDeepLink(category + "," + startoffset, content_id);

	current_offset[content_id] = startoffset;
	
	var content_div = document.getElementById("project_list_#content_id#");
	if (content_div && content_div.innerHTML)
		content_div.innerHTML = "<" + "img src='images/ajax-loading.gif' style='margin: 10px;' />"; 

	deactivateTabs(content_id);
		
	current_category[content_id] = category;
	
	var active_tab = document.getElementById("tabset_link_" + content_id + "_" + current_category[content_id]);
	if (active_tab)	active_tab.className += " active";

	if ( typeof http != "undefined" ) {
		params = new Object(); 
		params.project_category_id = current_category[content_id];
		params.offset = "" + startoffset;
		params.num_items = num_items;
		params.content_id = content_id;
		params.target_website = target_website;
		http( "POST" , "custom/projects/ax_projects.cfc?method=getProjects" , populateProjects, params ); 
	}
}

var changeCategory = function ( category, startoffset, num_items, content_id, is_homepage, target_website ) 
{	
	var path4tracker = window.location.pathname;
	if (window.location.search)
		path4tracker += window.location.search;

	path4tracker += "##" + category + "," + startoffset;
	
	if (is_homepage)
		path4tracker = "/start/" + path4tracker;
	
	changeCategoryInit ( null, category, startoffset, num_items, content_id, is_homepage, target_website );
	
	try {
		pageTracker._trackPageview(path4tracker);
	} catch(e) {
		// Google not initialised
	}
}

var populateProjects = function (cfc_result)
{
	var content_div = document.getElementById("project_list_" + cfc_result[2]);
	if (content_div && content_div.innerHTML)
		content_div.innerHTML = cfc_result[0]; 			

	content_div = document.getElementById("ajax_navi_" + cfc_result[2]);
	if (content_div && content_div.innerHTML)
		content_div.innerHTML = cfc_result[1]; 			
	
	if (active_nav[cfc_result[2]])
		active_nav[cfc_result[2]].className = active_nav[cfc_result[2]].className.replace("active", "");			

	active_nav[cfc_result[2]] = document.getElementById("ajax_nav_" + cfc_result[2] + "_" + current_offset[cfc_result[2]]);

	if (active_nav[cfc_result[2]])
		active_nav[cfc_result[2]].className += " active";
}

var deactivateTabs = function (content_id) {
	var tabs = document.getElementsByTagName("a");	
	
	for (var i = 0; i < tabs.length; i++) {
		if (tabs[i].id.indexOf("tabset_link_" + content_id) != -1 ) {
			tabs[i].className = tabs[i].className.replace("active", "");
		}
	}
}

var centerCoverflowBig = function () {

	var windowWidth = 0, windowHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	var coverflow_big = document.getElementById("coverflow_big");
	if (coverflow_big && Math.round((windowHeight - 388 - 400) / 2) > 0 ) {
		coverflow_big.style.paddingTop = Math.round((windowHeight - 388 - 400) / 2) + "px";
	}
}

if (window.addEventListener) window.addEventListener("load", centerCoverflowBig, false);
else if (window.attachEvent) window.attachEvent("onload", centerCoverflowBig);

if (window.addEventListener) window.addEventListener("resize", centerCoverflowBig, false);
else if (window.attachEvent) window.attachEvent("onresize", centerCoverflowBig);
