// 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";
	}
}

if(typeof parkside == "undefined") var parkside = new Object();
if(typeof parkside.ajax_projects == "undefined") parkside.ajax_projects = new Object();

// Constructor
parkside.ajax_projects = function( p_target_website, p_content_id, p_num_items, p_ie, p_ishomepage ) { 
	this.content_id = p_content_id; 
	this.num_items = p_num_items;
	this.isHomepage = p_ishomepage;
	this.ie = p_ie;	
	this.target_website = p_target_website;
}

parkside.ajax_projects.prototype = {

	current_offset: 0
	, current_category: 0
	, active_nav: null
	, num_items: 4
	, ie: true
	, content_id: 0
	, target_website: "stmk"
	
	, changeOffset: function ( offset ) 
	{
		if (offset < 0)
			return;
			
		setDeepLink(this.current_category + "," + offset, this.content_id);
			
		this.current_offset = offset;
					
		var content_div = document.getElementById("project_list_" + this.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;
			params.offset = "" + this.current_offset;
			params.num_items = this.num_items;
			params.content_id = this.content_id;
			params.ie = "" + this.ie + "";
			params.target_website = this.target_website;
			/// scope problems
			var that = this;
			var cb = function(cfc_result) {
				that.populateProjects(cfc_result, that.content_id);
			}
			http( "POST" , "custom/ax_projects.cfc?method=getProjects" , cb, params ); 
		}
		
		var path4tracker = window.location.pathname;
		if (window.location.search)
			path4tracker += window.location.search;
		
		path4tracker += "##" + current_category + "," + offset;

		if (this.isHomepage)
			path4tracker = "/start/" + path4tracker;

		try {
			pageTracker._trackPageview(path4tracker);
		} catch(e) {
			// Google not initialised
		}
	}
	, changeCategoryInit: function ( e, category, startoffset ) {
		if (e && getDeepLink() == "") {
			category = category == null ? 1 : category;
			startoffset = startoffset == null ? 0 : startoffset;			
		} else if (e) {
			var catoff = getDeepLink().split(",");
			category = catoff[0];
			startoffset = catoff[1];
		}

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

		this.current_offset = 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;' />"; 

		var last_active_tab = document.getElementById("tabset_link_" + this.content_id + "_" + this.current_category);
		if (last_active_tab)
			last_active_tab.className = last_active_tab.className.replace("active", "");
			
		this.current_category = category;
		
		var active_tab = document.getElementById("tabset_link_" + this.content_id + "_" + this.current_category);
		if (active_tab)
			active_tab.className += " active";

		if ( typeof http != "undefined" ) {
			params = new Object(); 
			params.project_category_id = this.current_category;
			params.offset = "" + startoffset;
			params.num_items = this.num_items;
			params.content_id = this.content_id;
			params.ie = this.ie;
			params.target_website = this.target_website;
			/// scope problems
			var that = this;
			var cb = function(cfc_result) {
				that.populateProjects(cfc_result, that.content_id);
			}
			http( "POST" , "custom/ax_projects.cfc?method=getProjects" , cb, params ); 
		}
	}
	
	, changeCategory: function ( category, startoffset ) {	
	
		var path4tracker = window.location.pathname;
		if (window.location.search)
			path4tracker += window.location.search;

		path4tracker += "##" + category + "," + startoffset;
		
		if (this.isHomepage)
			path4tracker = "/start/" + path4tracker;
		
		this.changeCategoryInit ( null, category, startoffset );
		
		try {
			pageTracker._trackPageview(path4tracker);
		} catch(e) {
			// Google not initialised
		}
	}
	
	, populateProjects: function (cfc_result, content_id) {

		var content_div = document.getElementById("project_list_" + content_id);
		if (content_div && content_div.innerHTML)
			content_div.innerHTML = cfc_result[0]; 			

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

		this.active_nav = document.getElementById("ajax_nav_" + content_id + "_" + this.current_offset);

		if (this.active_nav)
			this.active_nav.className += " active";
	}
}


/*

	ObjectTabs
	
	
*/
if(typeof parkside == "undefined") var parkside = new Object();
if(typeof parkside.ObjectPaging == "undefined") parkside.ObjectTabs = new Object();

parkside.ObjectPaging = function(p_target_website, p_content_id, p_num_items, p_current_category) {
	this.target_website = p_target_website;
	this.content_id = p_content_id;
	this.num_items = p_num_items;
	this.current_category = p_current_category;
	
	var that = this;
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, function(event) { that.handleChange(event); });
}

parkside.ObjectPaging.prototype = {
	current_offset: 0
	, current_category: 0
	, active_nav: null
	, content_id: 0
	, num_items: 10
	, target_website: "graz"
	
	/*
		change
	*/
	, change: function ( offset, category ) {
		if (offset < 0 || category < 0 || offset == null || category == null )
			return;

		if (this.current_offset == offset && this.current_category == category )
			return;

		this.deactivateTab();

		this.current_offset = offset;
		this.current_category = category == 0 ? this.current_category : category;

		this.activateTab();
		
		var content_div = document.getElementById( "object_list_" + this.content_id );
		if (!content_div || !content_div.innerHTML)
			return;

		content_div.innerHTML = "<img src='images/ajax-loading.gif' style='margin: 10px;' />"; 

		if ( typeof http != "undefined" ) {
			var that = this;
			
			var params = new Object(); 
			params.offset = "" + this.current_offset;
			params.num_items = this.num_items;
			params.content_id = this.content_id;
			params.target_website = this.target_website;
			params.category_id = "" + this.current_category;
						
			http( "POST" , "custom/objects/ax_objects.cfc?method=getObjects" , function( cfc_result ) { that.populateObjects(cfc_result) }, params ); 
		}

	}
	
	/*
		populateObjects
	*/
	, populateObjects: function (cfc_result) {
		var content_div = document.getElementById("object_list_" + this.content_id );
		if (!content_div || !content_div.innerHTML)
			return;
		
		content_div.innerHTML = cfc_result[0]; 		
		
		content_div = document.getElementById("ajax_navi_" + this.content_id);
		if (content_div && content_div.innerHTML) {
			content_div.innerHTML = cfc_result[1]; 
			if (cfc_result[1].length > 0)
				content_div.style.visibility = "visible";
		}
		content_div = document.getElementById("ajax_navi_" + this.content_id + "_2");
		if (content_div && content_div.innerHTML) {
			content_div.innerHTML = cfc_result[1]; 
			content_div.innerHTML += '<a class="btn-up" style="margin-top:-20px;" href="##">Seitenanfang<' + '/a>';
			if (cfc_result[1].length > 0)
				content_div.style.visibility = "visible";
		}
	}
	
	, activateTab: function() {
		var active_tab = document.getElementById("tabset_link_" + this.content_id + "_" + this.current_category);
		if (active_tab)
			active_tab.className += " active";
	}
	
	, deactivateTab: function() {
		var last_active_tab = document.getElementById("tabset_link_" + this.content_id + "_" + this.current_category);
		if (last_active_tab)
			last_active_tab.className = last_active_tab.className.replace("active", "");		
	}
	/*
		handleChange
	*/
	, handleChange: function (event) {
		if (event.path.length > 1 ) {
			var params = event.path.replace("/", "").split(",");
			if (params.length == 2) {
				this.change (parseInt(params[0]), parseInt(params[1]));
			}
		} else if (event.path.length <= 2) {
			this.change (0,this.current_category);
		}
	}
}

var object_paging = {};

