/* SUCHT DIE RICHTIGE FEHLERMELDUNG AUS DEM TEXTARRAY HERAUS */
function matchErrorMessage(needle,haystack){
	for(xindex in haystack){
		if(haystack[xindex]['option']==needle){
			return haystack[xindex]['content'];
		}
	}
}
/* LIEST DEN LOGINSTATUS DES USER AUS */
function returnUserStatus(){
	if(u_UID){
		return true;
	}else{
		return false;
	}
}
/* FORMULAR-SUBMIT: LEITET BEI NICHT VORHANDENEM LOGIN AUF LOGINFORMULAR UM */
function checkFormSubmit(formID){
	if(u_UID){
		f=document.forms[formID];
		f.submit();
	return true;
	}else{
		showStandardLayer.htmlRequest('914','','');
		return false;
	}
}
/* KLICK AUF LINK: LEITET BEI NICHT VORHANDENEM LOGIN AUF LOGINFORMULAR UM */
function checkLinkSubmit(){
	if(u_UID){
		return true;
	}else{
		showStandardLayer.htmlRequest('914','','');
		return false;
	}
}



/* POPUP */
function popup(url, title, width, height, otherSettings) {
	if (!width) {
		var width = 636;
	}
	if (!height) {
		var height = 500;
	}
	if (!otherSettings) {
		var otherSettings = ",top=100,left=100,directories=no,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=no,dependent=no,fullscreen=no";
	}
	var settings = "width=" + width + ",height=" + height + otherSettings;
	popUpWin = window.open(url, title, settings);
	popUpWin.focus();
}
/* BINDET ALLE POPUPLINKS AN DIE ENTSPRECHENDE FUNKTION */
var newWindowLinks = {
	init : function() {
		if (!document.getElementById || !document.createTextNode) { return; }
		$("a[rel='popup']").bind("click", function(e) {
			if (!e) {
				var event = window.event;
			} else {
				var event = e;
			}
			if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
				return true;
			} else {
				var link = $(this).attr("href");
				popup(link, "popUp", 636, 583);
				return false;
			}
		});
	}
}

var to = null;

/* LANGUAGE */
function toggleDivDisplay(div)
{
	var container = document.getElementById(div);

	var closeDiv = function()
	{
		$(container).unbind('mouseover');
		$(document.body).unbind('mouseover');
		$(document.body).unbind('click');
		container.style.display = "none";
		if(to)
			window.clearTimeout(to);
		to = null;
	}

	var startTimeout = function()
	{
		if(!to)
		{
			to = window.setTimeout(function()
			{
				closeDiv();
			}, 3000);
		}
	}

	if (container.style.display == "none")
	{
		container.style.display = "block";
		$(container).mouseover(function(ev)
		{
			ev.stopPropagation();
			ev.preventDefault();
			if(to)
			{
				window.clearTimeout(to);
				to = null;
			}
		});

		$(document.body).mouseover(function()
		{
			startTimeout();
		});
	}
	else
	{
		closeDiv();
	}
}

/* DEV */
function var_dump(obj) {
	if (typeof obj == "object") {
		return "Type: " + typeof(obj) + ((obj.constructor) ? "\nConstructor: " + obj.constructor : "") + "\nValue: " + obj;
	} else {
		return "Type: " + typeof(obj) + "\nValue: " + obj;
	}
}

/* USERPROFIL*/
function toggleDiceFlashes()  {
	$("#flashDiceWhitewall").css("display","none");
	$("#flashDiceAnimation").css("display","none");
	return false;
}
function initDiceFlashes()  {
	return false;
}
function switchProfileLayer(layer)  {
	//&&& Funktion implementieren
	//console.log('Neuer Layer: ' + layer);
	return false;
}

/* CAPTCHA*/
function getNewCaptcha()  {
	newSrc = '/image/captcha?area=register&reset=true&tsj='+Date.parse(new Date());
	$("#formCaptchaImg").attr({ src : newSrc });
	/* console.log(newSrc); */
	return false;
}

/* HEADER NAV*/
var showSubNav = {

	init : function() {
		showSubNav.setEvents();
	},
	setEvents : function() {
		$(".showSubNav").bind("mouseenter", showSubNav.openSubNavDiv);
		$(".showSubNav").bind("mouseleave", showSubNav.closeSubNavDiv);
	},
	openSubNavDiv : function(event) {
		showSubNav.subNavID = $(this).attr('value');
		$("ul#subNav_" + showSubNav.subNavID).css("display","block");
		return false;
	},
	closeSubNavDiv : function(event) {
		showSubNav.subNavID = $(this).attr('value');
		$("ul#subNav_" + showSubNav.subNavID).css("display","none");
		return false;
	}
}

/* CUBE NAV 311*/
var animateCubeNav = {
    positions : new Array(0,210,370),

	init : function() {
		animateCubeNav.setEvents();
        animateCubeNav.hideAllInfo();
    },
	setEvents : function() {
		$(".animateCubeNav").bind("mouseenter", animateCubeNav.highlightCube);
		$(".animateCubeNav").bind("mouseleave", animateCubeNav.deactivateCube);
	},
	highlightCube : function(event) {
		animateCubeNav.infoID = $(this).attr('value');
        $("div#cubeElement_" + animateCubeNav.infoID + "_a").css("left",animateCubeNav.positions[animateCubeNav.infoID]);
        $("div#cubeInfo_" + animateCubeNav.infoID).css("display","block");
		return false;
	},
	deactivateCube : function(event) {
		animateCubeNav.infoID = $(this).attr('value');
        $("div#cubeElement_" + animateCubeNav.infoID + "_a").css("left","-50000px");
        $("div#cubeInfo_" + animateCubeNav.infoID).css("display","none");
		return false;
	},
	hideAllInfo : function() {
		$("div#cubeInfo_0").css("display","none");
        $("div#cubeInfo_1").css("display","none");
        $("div#cubeInfo_2").css("display","none");
		return false;
	}
}
/* CITY CUBE NAV 400*/
var animateCityCubeNav = {
	init : function() {
		animateCityCubeNav.setEvents();
    },
	setEvents : function() {
		$(".us_animateCubeNav").bind("mouseenter", animateCityCubeNav.highlightCityCube);
		$(".us_animateCubeNav").bind("mouseleave", animateCityCubeNav.deactivateCityCube);
	},
	highlightCityCube : function(event) {
		animateCityCubeNav.infoID = $(this).attr('value');
        $("div#us_cubeElement_" + animateCityCubeNav.infoID + "_a").css("left","0");
		return false;
	},
	deactivateCityCube : function(event) {
		animateCityCubeNav.infoID = $(this).attr('value');
        $("div#us_cubeElement_" + animateCityCubeNav.infoID + "_a").css("left","-50000px");
		return false;
	}
}

/* FAQ ANIMATION */
var animateFaq = {

	init : function() {
		animateFaq.hideAll();
		animateFaq.setEvents();
	},
	setEvents : function() {
		$(".faq a.animateFaq").bind("click", animateFaq.toggleCopy);
	},
	toggleCopy : function(event) {
		animateFaq.elementID = this.id.replace('faqLink_', "");
		$(".faq p#faqCopy_" + animateFaq.elementID).slideToggle("slow");
		return false;
	},
	hideAll : function(event) {
		$(".faq p.hideAll").slideToggle(1);
		return false;
	}

}

/* ANIMATE TOP BANNER ON HOMEPAGE */
var animateTopBanner = {

	init : function() {
		animateTopBanner.setEvents();
        animateTopBanner.setBanner();
	},
	setEvents : function() {
		$("#hideTopBanner").bind("click", animateTopBanner.hideTopBanner);
        $("#showTopBanner").bind("click", animateTopBanner.showTopBanner);
	},
    setBanner : function() {
        if(returnUserStatus()){
            animateTopBanner.hideState();
        }
    },
	hideTopBanner : function(event) {
		$("#topBanner").slideToggle(500);
        $("#showTopBanner").show();
        $("#hideTopBanner").hide();
		return false;
	},
	showTopBanner : function(event) {
		$("#topBanner").slideToggle(500);
        $("#showTopBanner").hide();
        $("#hideTopBanner").show();
		return false;
	},
	hideState : function(event) {
		$("#topBanner").hide();
        $("#showTopBanner").show();
        $("#hideTopBanner").hide();
		return false;
	}

}

/* SELECT-LINK USERSTATUS */
var userStatusLinklist = {

	init : function() {
		userStatusLinklist.setEvents();
	},
	setEvents : function() {
		$("#userStatusLinklist").change(userStatusLinklist.loadUrl);
	},
	loadUrl : function(event) {
        if(this.value != 0){
            top.location.href = this.value;
        }
		return false;
	}

}

/* TOOLTIPS USERSTATUS */
var userStatusTooltips = {

	init : function() {
		userStatusTooltips.setEvents();
	},
	setEvents : function() {
		$(".newsIcon").bind("mouseenter",userStatusTooltips.showTooltip);
        $(".newsLink").bind("mouseenter",userStatusTooltips.showTooltip);
		$(".newsIcon").bind("mouseleave",userStatusTooltips.hideTooltip);
        $(".newsLink").bind("mouseleave",userStatusTooltips.hideTooltip);
    },
	showTooltip : function(event) {
        userStatusTooltips.elementID = this.id.replace('showStatusTooltip_', "");
        userStatusTooltips.topPos = this.offsetTop+20;
        userStatusTooltips.leftPos = this.offsetLeft+10;
        $("#statusTooltip_" + userStatusTooltips.elementID).css("top",userStatusTooltips.topPos);
        $("#statusTooltip_" + userStatusTooltips.elementID).css("left",userStatusTooltips.leftPos);
        $("#statusTooltip_" + userStatusTooltips.elementID).show();
		return false;
	},
    hideTooltip : function(event) {
        userStatusTooltips.elementID = this.id.replace('showStatusTooltip_', "");
        $("#statusTooltip_" + userStatusTooltips.elementID).hide();
		return false;
	}

}

/* GALLERY SUBNAV ANIMATION */
var animateGalleryNav = {

	init : function() {
		animateGalleryNav.hideAll();
		animateGalleryNav.setEvents();
	},
	setEvents : function() {
		$("#us_imageGallery_nav a.animateGalleryNav").bind("click", animateGalleryNav.toggleNav);
	},
	toggleNav : function(event) {
		animateGalleryNav.elementID = this.id.replace('galleryNavLink_', "");
		$("#us_imageGallery_nav #us_subContentNav_" + animateGalleryNav.elementID).slideToggle("slow");
		return false;
	},
	hideAll : function(event) {
		$("#us_imageGallery_nav li.subNavHideAll").slideToggle(1);
		return false;
	}

}

/* TRACKING PIXEL */
var trackEvents = {
	init : function() {
		trackEvents.setEvents();
	},
	setEvents : function() {
		$(".trackImageDownload").bind("click", trackEvents.trackingRequest);
        $(".trackFileDownload").bind("click", trackEvents.trackingRequest);
	},
	trackingRequest : function(theevent) {
		trackEvents.theevent = this.id;
		trackEvents.doRequest();
	},
	doRequest : function () {
		$.ajax({
		  url: "/tracking/pixel.jpeg?event=" + trackEvents.theevent,
		  cache: false,
		  dataType: "html",
		  success: function(){
			return false;
		  }
		});
	},
	trackEvent : function(theevent) {
		trackEvents.theevent = theevent;
		trackEvents.doRequest();
	}
}

/* ===================================================
DOCUMENT.READY
=================================================== */
$(document).ready(function(){
	//POPUPLINKS
	newWindowLinks.init();
	//DIE SUBNAV
	showSubNav.init();
    //SMARTTIMES CUBENAV
    animateCubeNav.init();
    //URBANSTAGE CUBENAV
    animateCityCubeNav.init();
	//LOGINFORMULAR  IN LAYERN AKTIVIEREN
	initLogin();
	//AUFKLAPPANIMATION F�R DIE FAQ
	animateFaq.init();
    //GALLERY SUBNAV ANIMATION
    animateGalleryNav.init();
	//TRACKING INITIALISIEREN
	trackEvents.init();
	//PROFILLAYER AKTIVIEREN
	showShortProfile.init();
	//LAYER AKTIVIEREN
	showStandardLayer.init();

    userStatusLinklist.init();
    userStatusTooltips.init();
    animateTopBanner.init();
});



