df_debug = false;



function FrameObject()
{
	this.active = 			false;
	this.html = 			'undefined';
	this.bgColor= 			df_item_bgColor;
	this.bgColorHover= 		df_item_bgColorHover;
	this.bgColorActive=		df_item_bgColorActive;
	this.colorActive= 		df_item_colorActive;
	this.color= 			df_item_color;
	this.colorHover= 		df_item_colorHover;
	this.imageActive = 		null;
	this.imageHover = 		null;
	this.imageInactive = 	null;
	this.imagePressed = 	null;
	this.elem = 			null;
	this.id = 				'';
	this.userdata = 		'';
	this.node = 			false;
	this.collapse =			false;	
}

// preload images
function FrameContainer()
{
	this.active = false;
	this.html = 'undefined';
	this.bgColor= 			df_item_bgColor;
	this.bgColorHover= 		df_item_bgColorHover;
	this.bgColorActive=		df_item_bgColorActive;
	this.colorActive= 		df_item_colorActive;
	this.color= 			df_item_color;
	this.colorHover= 		df_item_colorHover;
	this.imageActive = 		null;
	this.imageHover = 		null;
	this.imageInactive = 	null;
	this.imagePressed = 	null;
	this.elem = 			null;
	this.id = 				'';
	this.userdata = 		'';
	this.node = 			false;	
	this.collapse = 		false;
	this.objects = 			new Array();
	this.numObjects = 		0;
}

function CopyObject(dest, src) {
    for (i in src) {
        if (typeof src[i] == 'object') {
           dest[i] = new CopyObject(src[i]);
        }
        else
            dest[i] = src[i];
    }
}

var baseURL = '';
var currentHash = '';
var styles = new Array();
var stylesid = new Array();

var df_active_location = null;
var df_active_location_parent = null;
var df_active_tab = null;
var df_active_category = null;
var df_active_category_parent = null;
var df_active_content = null;
var df_workshop_cat = df_art_cat;
var df_workshop_catids = df_art_catids;


var df_buttonart = new FrameObject;
df_buttonart.color = df_button_color;
df_buttonart.colorActive = df_button_colorActive;
df_buttonart.colorHover = df_button_colorHover;
var df_buttonwk = new FrameObject;
df_buttonwk.color = df_button_color;
df_buttonwk.colorActive = df_button_colorActive;
df_buttonwk.colorHover = df_button_colorHover;
var df_footer = new FrameObject;
var df_categoryhead = new FrameObject;
var df_category =  new FrameContainer;
var df_contenthead = new FrameObject;
var df_content =  new FrameContainer;
var df_locationhead = new FrameObject;
var df_location =  new FrameContainer;

var ifx_xmlrequestListings = false;
var ifx_xmlrequestCategories = false;
var listings = '';

function ifx_getXMLHTTPrequest ()
{

	try
	{
		ifx_xmlrequestListings = new XMLHttpRequest();
		ifx_xmlrequestCategories = new XMLHttpRequest();		
	}
	catch (err)
	{
		try
		{
			ifx_xmlrequestListings = new ActiveXObject("Msxml2.XMLHTTP");
			ifx_xmlrequestCategories = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (err)
		{
			try
			{
				ifx_xmlrequestListings = new ActiveXObject("Microsoft.XMLHTTP");			
				ifx_xmlrequestCategories = new ActiveXObject("Microsoft.XMLHTTP");			
			}
			catch (err)
			{
				ifx_xmlrequestListings = false;
				ifx_xmlrequestCategories = false;
			}
		}
	
	}
	return ifx_xmlrequestListings;
}

function df_HTTPResponseListings()
{
	switch (ifx_xmlrequestListings.readyState)
	{
	case 1:
		document.getElementById('df_content').innerHTML = '<img src="dynfront/loading.gif" alt="Loading...">'; 
		break;
	case 2:
		break;
	case 3:
		break;
	case 4:
		if (ifx_xmlrequestListings.status == 200)
		{
	/*		listings = ifx_xmlrequestListings.responseXML.getElementsByTagName("listing");
			//document.getElementById('df_content').innerHTML = listings.item(0).childNodes[0].nodeValue;	
			for (i=0; i<listings.length; i++)
			{
				//Display only element nodes
				if (listings.item(i).nodeType==1)
				{
					//document.write(x.item(i).nodeName);
					document.getElementById('df_content').innerHTML = listings.item(i).childNodes[0].nodeValue;	
				}
			} 
		*/	
			df_fillContent();
		}
		else
		{
			document.getElementById('df_content').innerHTML = 'Error: data not fetched';	
		}
	}
}




function getPage( url, bRandom )
{
	if (typeof bRandom == "undefined") bRandom = false;
	
	var theUrl = url;
	if (bRandom == true)
	{
		myRand = parseInt(Math.random()*999999999999);
		theUrl += '?rand=' + myRand;
	}
	ifx_xmlrequestListings.open("GET", theUrl, true);
	ifx_xmlrequestListings.onreadystatechange = ifx_HTTPResponse;
	ifx_xmlrequestListings.send(null);
}


function debugMessage(val)
{
	if (df_debug != true) return;
	alert(val);
}

function df_fillLocations (locationList, idList, continentList, expandContinent)
{
	var collapsed = true;
	if (typeof expandContinent == "undefined") expandContinent = 0;
	for (x in df_location.objects)
	{
		delete df_location.objects[x];
	}
	output = '<ul>';
	
	var locfound = false;
	for (x in locationList)
		if (idList[x] == df_active_location) locfound = true;
	if (!locfound) df_active_location = -99;
		
	var i = 0;
	for (x in locationList)
	{
		var temp = new FrameObject
		len = df_location.objects.length;
		temp.html = locationList[x];
		temp.id = 'DF_locItem_' + x;
		temp.userdata = idList[x];
		if (idList[x] <= 0)
		{
			output += '<li id="DF_locItem_' + x + '" title="' + locationList[x] + '" onclick="df_click(this)"  onmouseout="df_mouseout(this)" onmouseover="df_mouseover(this)"><span id="l'+len+'">';
			if (idList[x] != -99)
			{
				if (idList[x] == expandContinent)
				{
					collapsed = false;
					output += imContract;
				}
				else
				{
					collapsed = true;
					output += imExpand;
				}
			}
			temp.node = true;
			temp.collapse = collapsed;				
			output += locationList[x] + '</span></li>';
			df_location.objects[len] = new Object();
			CopyObject(df_location.objects[len], temp);
		}
		else
		{
			if (collapsed == false)
			{
				output += '<li id="DF_locItem_' + x + '" title="' + locationList[x] + '" onclick="df_click(this)"  onmouseout="df_mouseout(this)" onmouseover="df_mouseover(this)"><span id="l'+len+'">';		
				output += imNothing;
				output += locationList[x] + '</span></li>';
				df_location.objects[len] = new Object();
				CopyObject(df_location.objects[len], temp);
			}
		}
	}
	output += '</ul>';
	df_location.html = output;
	df_location.elem.innerHTML = output;	
	for (x in df_location.objects)
	{
		df_location.objects[x].elem = document.getElementById( df_location.objects[x].id );
		if (document.getElementById('l'+ x).offsetWidth + 16 < df_location.objects[x].elem.offsetWidth) 
			df_location.objects[x].elem.title = '';
	}
}
		

function df_fillCategories (locationList, idList, continentList, expandContinent)
{
	debugMessage('df_fillCategories: ' + locationList.length + ', ' + idList.length);
	var oldcat = df_active_category;
	var collapsed = false;
	var debugOutput = '';
	if (typeof expandContinent == "undefined") expandContinent = 0;
	for (x in df_category.objects)
	{
		delete df_category.objects[x];
	}
	var output = '<ul>';
	var i = 0;
	for (x in locationList)
	{
	    if  (typeof locationList[x] != 'string') continue;	
		var temp = new FrameObject
		len = df_category.objects.length;	
		temp.html = locationList[x];		
		temp.id = 'DF_catItem_' + x;
		temp.userdata = idList[x];		
		if (idList[x] <= 0)
		{
			output += '<li id="DF_catItem_' + x + '" title="' + locationList[x] + '" onclick="df_click(this)"  onmouseout="df_mouseout(this)" onmouseover="df_mouseover(this)"><span id="c'+len+'">';		
			if (idList[x] != -99)
			{
				if (locationList[x].substr(0,1) == '*')
				{
					output += imContract + locationList[x].substr(1) + '</span></li>';
					collapsed = false;
				}
				else
				{
					output += imEmptynode + locationList[x] + '</span></li>';
					collapsed = false;
				}
			}
			else
			{
				output += locationList[x] + '</span></li>';
				collapsed = false;
			}
			temp.node = true;
			temp.collapse = collapsed;	
			df_category.objects[len] = new Object();		
			CopyObject(df_category.objects[len], temp);				
		}
		else
		{
			if (collapsed == false)
			{
				output += '<li id="DF_catItem_' + x + '" title="' + locationList[x] + '" onclick="df_click(this)"  onmouseout="df_mouseout(this)" onmouseover="df_mouseover(this)"><span id="c'+len+'">';		
				output += imNothing + '&nbsp;';
				output += locationList[x] + '</span></li>';
				df_category.objects[len] = new Object();		
				CopyObject(df_category.objects[len], temp);					
			}
		}
	}
	output += '</ul>';
	df_category.html = output;
	df_category.elem.innerHTML = output;
	var catfound = false;
	for (x in df_category.objects)
	{
		df_category.objects[x].elem = document.getElementById( df_category.objects[x].id );
		if (df_category.objects[x].userdata == df_active_category)
		{
			df_category.objects[x].active = true;
			df_category.objects[x].elem.style.backgroundColor = df_category.objects[x].bgColorActive;
			df_category.objects[x].elem.style.color = df_category.objects[x].colorActive;			
			catfound = true;
		}
		if (document.getElementById('c'+ x).offsetWidth + 16 < df_category.objects[x].elem.offsetWidth) 
			df_category.objects[x].elem.title = '';		
	}
	if (!catfound)
	{
		df_active_category = -99
	}
	newCategory(oldcat);
}

function getListings(bGetAll)
{
	var	myRand = parseInt(Math.random()*999999999999);
	var theUrl = df_dynfront + 'query.php';
	theUrl += '?tab=' + df_active_tab;
	theUrl += '&loc=' + df_active_location;
	theUrl += '&cat=' + df_active_category;
	theUrl += '&item=' + df_active_content;
	theUrl += '&lang=' + df_lang;
	theUrl += '&query=listings';
	if (bGetAll==true) theUrl += '&all=true';
	theUrl += '&r=' + myRand;
	debugMessage ('fetching data from server: '+theUrl);
	ifx_xmlrequestListings.open("GET", theUrl, true);
	ifx_xmlrequestListings.onreadystatechange = df_HTTPResponseListings;
	ifx_xmlrequestListings.send(null);
}

function df_HTTPResponseCategories()
{
	switch (ifx_xmlrequestCategories.readyState)
	{
	case 1:
		document.getElementById('df_category').innerHTML = '<img src="dynfront/loading_s.gif" alt="Loading...">'; 
		break;
	case 2:
		break;
	case 3:
		break;
	case 4:
		var t = 0;
		if (styles.length > 0) styles.splice (0, styles.length);
		if (stylesid.length > 0) stylesid.splice (0, stylesid.length);
		var oldldrid = -99;
		styles.push(df_categoryRoot);
		stylesid.push(-99);
		t++;
		if (ifx_xmlrequestCategories.status == 200)
		{
			var xmlstyles = ifx_xmlrequestCategories.responseXML.getElementsByTagName("style");
			var items = ifx_xmlrequestCategories.responseXML.getElementsByTagName("items");
			for (var i=0; i<xmlstyles.length; i++)
			{
				if (xmlstyles.item(i).nodeType==1)
				{
					var ldrid = xmlstyles.item(i).attributes.getNamedItem("ldrid").nodeValue;
					var num = xmlstyles.item(i).attributes.getNamedItem("num").nodeValue;
					var catid = xmlstyles.item(i).childNodes[0].nodeValue;	
					if (ldrid != oldldrid) // new group
					{
						oldldrid = ldrid;
//						debugMessage('leader: ' + df_styles[ldrid]);
						if ( i+1 < xmlstyles.length )// isn't the last item
						{
							if (ldrid == xmlstyles.item(i+1).attributes.getNamedItem("ldrid").nodeValue) //isn't the only item in this group?
							{
								styles.push(df_styles[ldrid]); // insert a group node
								stylesid.push(-ldrid);
								t++;	
								styles.push(df_styles[catid] + ' (' + num + ')');
								stylesid.push(catid);
								t++;
							}
							else
							{
								styles.push(df_styles[ldrid].substr(1) + ' (' + num + ')'); // only item in this group: only show the group node
								stylesid.push(-ldrid);
								t++;
							}
						}
						else
						{
							styles.push(df_styles[ldrid].substr(1) + ' (' + num + ')'); // only item in this group: only show the group node
							stylesid.push(-ldrid);
							t++;
						}
					}
					else
					{
						styles.push(df_styles[catid] + ' (' + num + ')');
						stylesid.push(catid);
						t++;
	//					debugMessage('category: ' + df_styles[catid]);
					}
				}
			}
			var total = items.item(0).childNodes[0].nodeValue;
//			debugMessage('total: ' + total);
			if (total > 0) 
			{
				df_fillCategories (styles, stylesid);	
			}
		}
		else
		{
			document.getElementById('df_content').innerHTML = 'Error: data not fetched';	
		}
	}
}

function getCategories()
{
	var	myRand = parseInt(Math.random()*999999999999);
	var theUrl = df_dynfront + 'query.php';
	theUrl += '?tab=' + df_active_tab;
	theUrl += '&loc=' + df_active_location;
//	theUrl += '&cat=' + df_active_category;
//	theUrl += '&item=' + df_active_content;
	theUrl += '&lang=' + df_lang;
	theUrl += '&query=categories';
	theUrl += '&r=' + myRand;
	debugMessage ('fetching data from server: '+theUrl);
	ifx_xmlrequestCategories.open("GET", theUrl, true);
	ifx_xmlrequestCategories.onreadystatechange = df_HTTPResponseCategories;
	ifx_xmlrequestCategories.send(null);
}

function newCategory(oldCategory)
{
	debugMessage ('new category: ' + df_active_category);
	for (x in df_category.objects)
	{	
		if (df_category.objects[x].userdata == oldCategory)
		{
			df_category.objects[x].active = false;						
			df_category.objects[x].elem.style.backgroundColor=df_category.objects[x].bgColor;
			df_category.objects[x].elem.style.color=df_category.objects[x].color;			
		}
		if (df_category.objects[x].userdata == df_active_category)
		{
			df_category.objects[x].active = true;						
			df_category.objects[x].elem.style.backgroundColor=df_category.objects[x].bgColorActive;
			df_category.objects[x].elem.style.color=df_category.objects[x].colorActive;			
		}
	}	
	getListings();
}

function df_updateFromHash() 
{ 	
	var tab = '';
	var location = '';
	var category = '';
	var content = '';
	
	// get the hash
	hash = window.location.hash;
    hash = hash.substr(1, hash.length);
	hash = decodeURIComponent(hash);
	//if (hash.length == 0) return;
	var args = hash.split('&');
	// parse name/value pairs separated via &
	for (var i = 0; i < args.length; i++) 
	{
		var pair = args[i].split('=');
		var name = (pair[0]);
		var value = (pair.length==2) ? (pair[1]) : name;
		switch (name)
		{
			case 'loc': location = parseInt(value,16); break;
			case 'cat': category = parseInt(value,16); break;
			case 'tab': tab = parseInt(value,16); break;
			case 'cnt': content = parseInt(value,16); break;
		}
	}
	df_update(tab, location, category, content);
	//eval (evalstr);
}

function df_update(tab, location, category, content) 
{ 
	var args = '';
	// check what needs to be updated / loaded
	var updateTab = false;
	var reloadLocations = false;
	var updateLocations = false;
	var reloadCategories = false;
	var updateCategories = false;
	var reloadContent = false;	
	var oldTab = df_active_tab;
	var oldLocation = df_active_location;
	var oldCategory = df_active_category;
	var oldContent = df_active_content;
		
	if (tab !== ''){
		if (tab != df_active_tab){
			df_active_tab = tab; 
			updateTab = true;}}
	else{
		if (df_active_tab === null){
			df_active_tab = preferredTab; 
			updateTab = true;}}
	
	if (location !== ''){
		if (location != df_active_location){
			df_active_location = location; 
			updateLocations = true;
			if (df_active_location <= 0)
				reloadLocations = true; // clicked a continent
		}}
	else{
		if (df_active_location === null){
			df_active_location = preferredLoc; 
			reloadLocations = true;}}
	
	if (category !== ''){
		if (category != df_active_category){
			df_active_category = category;
			updateCategories = true;
//			if (df_active_category <= 0)
//				reloadCategories = true; // clicked a group
		}}
	else{
		if (df_active_category === null){
			df_active_category = preferredCat; 
			reloadCategories = true;}}
	
	if (content !== ''){
		if (content != df_active_content){
			df_active_content = content;
			reloadContent = true;			
			}}
	else{	
		if (df_active_content === null){
			df_active_content = -99; 
			reloadContent = true;
			}} 
	
	// set hash
	currentHash = 'tab=' + df_active_tab.toString(16) + '&loc=' + df_active_location.toString(16) + '&cat=' + df_active_category.toString(16) + '&cnt=' + df_active_content.toString(16);
	currentHash = '#'+ encodeURIComponent(currentHash);
	window.location.hash = currentHash;
	
	// update
	if (updateTab == true)
	{
		debugMessage ('update tab: '+df_active_tab);
		if (df_active_tab == 0) 
		{
			df_buttonart.elem.style.backgroundImage=df_buttonart.imageActive;
			df_buttonwk.elem.style.backgroundImage=df_buttonwk.imageInactive;
			df_buttonart.elem.style.color = df_buttonart.colorActive;
			df_buttonwk.elem.style.color = df_buttonwk.color;
			df_buttonart.active = true;
			df_buttonwk.active = false;
			
		}
		else
		{
			df_buttonart.elem.style.backgroundImage=df_buttonart.imageInactive;
			df_buttonwk.elem.style.backgroundImage=df_buttonwk.imageActive;
			df_buttonart.elem.style.color = df_buttonart.color;
			df_buttonwk.elem.style.color = df_buttonwk.colorActive;			
			df_buttonart.active = false;
			df_buttonwk.active = true;
		}	
		reloadLocations = true;
		reloadCategories = true;		
	}
	
	if (reloadLocations == true)
	{
		updateLocations = true;
		reloadCategories = true;
		var parent = 0;
		if (df_active_location <= 0) // clicked a continent
		{
			debugMessage('Clicked continent, location: ' + df_active_location);
			parent = df_active_location;
		}
		else
		{
			var i = 0;
			var t = 0;
			for (x in df_art_locids)
			{
				if (df_art_locids[x] <= 0) 
				{
					t = df_art_locids[x];
					//debugMessage('Found continent: ' + t);
				}	
				if (df_art_locids[x] == df_active_location) 
				{
					parent = t;
					debugMessage('Found match: ' + parent);					
					break;
				}
			}
		}
		debugMessage ('reload locations: '+df_active_tab+', parent: '+parent);		
		if (df_active_tab == 0)
			df_fillLocations (df_art, df_art_locids, df_art_continent, parent);
		else
			df_fillLocations (df_workshop, df_workshop_locids, df_workshop_continent, parent);

	}
		
    if (updateLocations == true)
	{
		reloadCategories = true;
		reloadContent = true;
		debugMessage ('update locations: '+df_active_location + ' (' + oldLocation + ')');
		for (x in df_location.objects)
		{	
			if ((reloadLocations == false) & (df_location.objects[x].userdata == oldLocation))
			{
				df_location.objects[x].active = false;						
				df_location.objects[x].elem.style.backgroundColor=df_location.objects[x].bgColor;
				df_location.objects[x].elem.style.color=df_location.objects[x].color;				
			}
			if (df_location.objects[x].userdata == df_active_location)
			{
				df_location.objects[x].active = true;						
				df_location.objects[x].elem.style.backgroundColor=df_location.objects[x].bgColorActive;
				df_location.objects[x].elem.style.color=df_location.objects[x].colorActive;				
			}
		}	

	}
	
	if (reloadCategories == true)
	{
		debugMessage ('reload categories: '+df_active_tab);
		updateCategories = false; // wait until categories have loaded
		getCategories();

	}

	if (updateCategories == true) // if categories have loaded
	{
		newCategory(oldCategory);
	}
}

function df_fillContent()
{
	for (x in df_content.objects)
	{
		delete df_content.objects[x];
	}
	var output = '<ul>';
	listings = ifx_xmlrequestListings.responseXML.getElementsByTagName("listing");
	items = ifx_xmlrequestListings.responseXML.getElementsByTagName("items");
	//document.getElementById('df_content').innerHTML = listings.item(0).childNodes[0].nodeValue;	
	for (var i=0; i<listings.length; i++)
	{
		//Display only element nodes
		if (listings.item(i).nodeType==1)
		{
			var link = listings.item(i).attributes.getNamedItem("link").nodeValue;
			var title = listings.item(i).attributes.getNamedItem("title").nodeValue;
			var photo = listings.item(i).attributes.getNamedItem("photo").nodeValue;
			var name = listings.item(i).attributes.getNamedItem("name").nodeValue;
			var city = listings.item(i).attributes.getNamedItem("city").nodeValue;
			var country = listings.item(i).attributes.getNamedItem("country").nodeValue;
			var state = listings.item(i).attributes.getNamedItem("state").nodeValue;
			var style = listings.item(i).attributes.getNamedItem("style").nodeValue;

			var x = listings.item(i).childNodes[0].nodeValue;	
			var temp = new FrameObject
			var temp_content = new String(df_content_listitem);
			temp_content = temp_content.replace(/\[TITLE]/g, title);
			temp_content = temp_content.replace(/\[LINK]/g, link);
			temp_content = temp_content.replace(/\[PHOTOURL]/g, photo);
			temp_content = temp_content.replace(/\[ARTISTNAME]/g, name);
			temp_content = temp_content.replace(/\[ARTISTCITY]/g, city);
			temp_content = temp_content.replace(/\[ARTISTCOUNTRY]/g, country);
			temp_content = temp_content.replace(/\[ARTISTSTATE]/g, state);
			temp_content = temp_content.replace(/\[ARTSTYLE]/g, style);
			temp_content = temp_content.replace(/\[DESCRIPTION]/g, x);
	
			output += '<li id="DF_contItem_' + i + '" onclick="df_click(this)"  onmouseout="df_mouseout(this)" onmouseover="df_mouseover(this)">' + temp_content + '</li>';
			len = df_content.objects.length;	
			df_content.objects[len] = new Object();		
			CopyObject(df_content.objects[len], temp);		
			df_content.objects[len].html = temp_content;		
			df_content.objects[len].id = 'DF_contItem_' + i;
			df_content.objects[len].userdata = link;
		}
	}
	output += '</ul>';
	df_content.html = output;
	df_content.elem.innerHTML = output;	
	for (x in df_content.objects)
	{
		df_content.objects[x].elem = document.getElementById( df_content.objects[x].id );
		if (df_content.objects[x].active == true)
		{
			df_content.objects[x].elem.style.backgroundColor = df_content.objects[x].bgColorActive;
			df_content.objects[x].elem.style.color = df_content.objects[x].colorActive;			
		}
	}	
	var total = items.item(0).childNodes[0].nodeValue;
	df_contenthead.elem.innerHTML = '<span>' + df_lang_latest + ' ' + i + ' ' + df_lang_from + ' ' + total + '.</span><span style="position:absolute; right:10px;"><a href="javascript:getListings(true);">' + df_lang_showall + '</a></span>';
}

// df_getelements assigns the html elements to corresponding javascript variables
function df_getElements()
{
 	df_locationhead.id = 'df_locationhead';
	df_location.id = 'df_location';
	df_categoryhead.id = 'df_categoryhead';
	df_category.id = 'df_category';
	df_contenthead.id = 'df_contenthead';
	df_content.id = 'df_content';
	df_buttonart.imageInactive="url('" + tab1SrcInactive + "')";
	df_buttonart.imageActive="url('"+ tab1SrcActive + "')";
	df_buttonart.imageHover="url('"+ tab1SrcHover + "')";
	df_buttonart.id = 'df_buttonart';
	df_buttonwk.imageInactive="url('" + tab2SrcInactive + "')";
	df_buttonwk.imageActive="url('"+ tab2SrcActive + "')";
	df_buttonwk.imageHover="url('"+ tab2SrcHover + "')";	
	df_buttonwk.id = 'df_buttonwk';
	df_footer.id = 'df_footer';

	df_locationhead.elem = document.getElementById(df_locationhead.id);
	df_location.elem = document.getElementById(df_location.id);
	df_categoryhead.elem = document.getElementById(df_categoryhead.id);
	df_category.elem = document.getElementById(df_category.id);
	df_contenthead.elem = document.getElementById(df_contenthead.id);
	df_content.elem = document.getElementById(df_content.id);
	df_footer.elem = document.getElementById(df_footer.id);
	df_buttonart.elem = document.getElementById(df_buttonart.id);
	df_buttonwk.elem = document.getElementById(df_buttonwk.id);
}

function clickedArtButton()
{
	df_update(0,'','','');
}

function clickedWkButton()
{
	df_update(1,'','','');
}

// df_click is called when a html elements onclick event is triggered
function df_click(elem)
{
	switch (elem.id)
	{
//	case df_locationhead.id: 	df_locationhead.elem.style.backgroundColor=df_locationhead.bgColorActive; df_locationhead.elem.style.color=df_locationhead.colorActive; break;
//	case df_categoryhead.id: 	df_categoryhead.elem.style.backgroundColor=df_categoryhead.bgColorActive; df_categoryhead.elem.style.color=df_categoryhead.colorActive; break;
//	case df_contenthead.id: 	df_contenthead.elem.style.backgroundColor=df_contenthead.bgColorActive; df_contenthead.elem.style.color=df_contenthead.colorActive; break;
	case df_buttonart.id: 		clickedArtButton(); break;
	case df_buttonwk.id: 		clickedWkButton(); break;
	default:
		{
			if (elem.id.match('DF_locItem_')) 
			{
				for (x in df_location.objects)
					if (df_location.objects[x].id == (elem.id)) 
					{
						if (df_location.objects[x].active)
						{
						}
						else
						{
							var locid = df_location.objects[x].userdata;
							df_update('' , locid,'','');
						}
						break;
					}
			}
			if (elem.id.match('DF_catItem_')) {
				for (x in df_category.objects)
					if (df_category.objects[x].id == (elem.id))
					{ 
						if (df_category.objects[x].active)
						{	
						}
						else
						{
							var catid = df_category.objects[x].userdata;
							df_update('' , '', catid,'');
						}
						break;
					}
			}	
			if (elem.id.match('DF_contItem_')) {
				for (x in df_content.objects)
					if (df_content.objects[x].id == (elem.id))
					{ 
						if (df_content.objects[x].active)
						{	
							df_content.objects[x].active = false;
							var bgcol = df_content.objects[x].bgColor;
							var col = df_content.objects[x].color;							
						}
						else
						{
							df_content.objects[x].active = true;						
							var bgcol = df_content.objects[x].bgColorActive;
							var col = df_content.objects[x].colorActive;							
							window.location = df_content.objects[x].userdata;
						}
						df_content.objects[x].elem.style.backgroundColor=bgcol;
						df_content.objects[x].elem.style.color=col;						
						break;
					}
			}		

		}
	}
}

// df_mouseover is called when a html elements onmouseover event is triggered
function df_mouseover(elem)
{
	switch (elem.id)
	{
//	case df_locationhead.id: 	df_locationhead.elem.style.backgroundColor=df_locationhead.bgColorHover; df_locationhead.elem.style.color=df_locationhead.colorHover; break;
//	case df_categoryhead.id: 	df_categoryhead.elem.style.backgroundColor=df_categoryhead.bgColorHover; df_categoryhead.elem.style.color=df_categoryhead.colorHover; break;
//	case df_contenthead.id: 	df_contenthead.elem.style.backgroundColor=df_contenthead.bgColorHover; df_contenthead.elem.style.color=df_contenthead.colorHover; break;
	case df_buttonart.id:
		if (!df_buttonart.active) 
		{
			df_buttonart.elem.style.backgroundImage=df_buttonart.imageHover;
			df_buttonart.elem.style.backgroundColor = df_buttonart.colorHover;
		}
		break;
	case df_buttonwk.id:
		if (!df_buttonwk.active)
		{
			df_buttonwk.elem.style.backgroundImage=df_buttonwk.imageHover; 
			df_buttonwk.elem.style.color = df_buttonwk.colorHover;
		}
		break;
	default: 
		{
			if (elem.id.match('DF_locItem_')) {
				for (x in df_location.objects)
					if (df_location.objects[x].id == (elem.id)) 
					{
						if (df_location.objects[x].active == false)
						{
							var col = df_location.objects[x].colorHover;
							var bgcol = df_location.objects[x].bgColorHover;
						}
						df_location.objects[x].elem.style.color=col;
						df_location.objects[x].elem.style.backgroundColor=bgcol;						
						break;
					}
			}		
			if (elem.id.match('DF_catItem_')) {
				for (x in df_category.objects)
					if (df_category.objects[x].id == (elem.id))
					{ 
						if (df_category.objects[x].active == false)
						{	
							var col = df_category.objects[x].colorHover;
							var bgcol = df_category.objects[x].bgColorHover;
						}
						df_category.objects[x].elem.style.color=col;
						df_category.objects[x].elem.style.backgroundColor=bgcol;						
						break;
					}
			}		
			if (elem.id.match('DF_contItem_')) {
				for (x in df_content.objects)
					if (df_content.objects[x].id == (elem.id))
					{ 
						if (df_content.objects[x].active == false)
						{	
							var col = df_content.objects[x].colorHover;
							var bgcol = df_content.objects[x].bgColorHover;
						}
						df_content.objects[x].elem.style.color=col;
						df_content.objects[x].elem.style.backgroundColor=bgcol;
						break;
					}
			}		
		}

		break; 	
	}
}

// df_mouseout is called when a html elements onmouseout event is triggered
function df_mouseout(elem)
{
	switch (elem.id)
	{
//	case df_locationhead.id: 	df_locationhead.elem.style.backgroundColor=df_locationhead.bgColor; df_locationhead.elem.style.color=df_locationhead.color; break;
//	case df_categoryhead.id: 	df_categoryhead.elem.style.backgroundColor=df_categoryhead.bgColor; df_categoryhead.elem.style.color=df_categoryhead.color; break;
//	case df_contenthead.id: 	df_contenthead.elem.style.backgroundColor=df_contenthead.bgColor; df_contenthead.elem.style.color=df_contenthead.color; break;
	case df_buttonart.id: 		
		df_buttonart.elem.style.backgroundImage = df_buttonart.active ? df_buttonart.imageActive : df_buttonart.imageInactive;
		df_buttonart.elem.style.color = df_buttonart.active ? df_buttonart.colorActive : df_buttonart.color;
		break;
	case df_buttonwk.id: 
		df_buttonwk.elem.style.backgroundImage = df_buttonwk.active ? df_buttonwk.imageActive : df_buttonwk.imageInactive;
		df_buttonwk.elem.style.color = df_buttonwk.active ? df_buttonwk.colorActive : df_buttonwk.color;		
		break;
	default: 
		{
			if (elem.id.match('DF_locItem_')) {
				for (x in df_location.objects)
					if (df_location.objects[x].id == (elem.id)) 
					{
						if (df_location.objects[x].active == true)
						{
							var col = df_location.objects[x].colorActive;
							var bgcol = df_location.objects[x].bgColorActive;
						}
						else
						{
							var col = df_location.objects[x].color;
							var bgcol = df_location.objects[x].bgColor;
						}
						df_location.objects[x].elem.style.backgroundColor=bgcol;
						df_location.objects[x].elem.style.color=col;						
						break;
					}
			}		
			if (elem.id.match('DF_catItem_')) {
				for (x in df_category.objects)
					if (df_category.objects[x].id == (elem.id))
					{ 
						if (df_category.objects[x].active == true)
						{
							var col = df_category.objects[x].colorActive;
							var bgcol = df_category.objects[x].bgColorActive;
						}
						else
						{
							var col = df_category.objects[x].color;
							var bgcol = df_category.objects[x].bgColor;
						}
						df_category.objects[x].elem.style.color=col;
						df_category.objects[x].elem.style.backgroundColor=bgcol;						
						break;
					}
			}	
			if (elem.id.match('DF_contItem_')) {
				for (x in df_content.objects)
					if (df_content.objects[x].id == (elem.id))
					{ 
						if (df_content.objects[x].active == true)
						{
							var col = df_content.objects[x].colorActive;
							var bgcol = df_content.objects[x].bgColorActive;
						}
						else
						{
							var col = df_content.objects[x].color;
							var bgcol = df_content.objects[x].bgColor;
						}
						df_content.objects[x].elem.style.color=col;
						df_content.objects[x].elem.style.backgroundColor=bgcol;
						break;
					}
			}			
		}
		break; 	
	}
}

function df_checkHash()
{
	if(window.location.hash != currentHash)
	{
		currentHash = window.location.hash;
		df_updateFromHash();
	}
}

// df_init() initializes the script,
function df_init()
{
	// TODO: handle older browsers
	if (!document.getElementById) return; // bail out if this is an older browser
	df_getElements();
	df_updateFromHash();
    window.setInterval(df_checkHash, 500);	
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(ifx_getXMLHTTPrequest);
addLoadEvent(df_init);

