/**
* @var array aSettings Setting Array in dem die gepeicherten Einstellungen zwischen gespeichert werden
*/
var aSettings = Array();
/**
* Initialisieren der Gadget spezifischen Konfiguration
*
*/
function mInitGadgetConfig() {
	var http = this.aConfig["sServerURL"]+"/igoogle/images/sternzeichen/";
	this.aConfig["aIcons"] = new Array();
	this.aConfig["aIcons"]["Widder"] = http+"widder.png";
	this.aConfig["aIcons"]["Stier"] = http+"stier.png";
	this.aConfig["aIcons"]["Zwilling"] = http+"zwillinge.png";
	this.aConfig["aIcons"]["Krebs"] = http+"krebs.png";
	this.aConfig["aIcons"]["Löwe"] = http+"loewe.png";
	this.aConfig["aIcons"]["Jungfrau"] = http+"jungfrau.png";
	this.aConfig["aIcons"]["Waage"] = http+"waage.png";
	this.aConfig["aIcons"]["Skorpion"] = http+"skorpion.png";
	this.aConfig["aIcons"]["Schütze"] = http+"schuetze.png";
	this.aConfig["aIcons"]["Steinbock"] = http+"steinbock.png";
	this.aConfig["aIcons"]["Wassermann"] = http+"wassermann.png";
	this.aConfig["aIcons"]["Fische"] = http+"fische.png";
	
	this.aConfig["sLinkText_daily"] = ">>Weiter im Tageshoroskop";
	this.aConfig["sLinkText_weekly"] = ">>Weiter im Wochenhoroskop";
	this.aConfig["sLinkText_personal"] = ">>Weiter im persönlichen Horoskop";
	
	this.aConfig["sHeadlineText_daily"] = "IHR TAGESHOROSKOP";
	this.aConfig["sHeadlineText_weekly"] = "IHR WOCHENHOROSKOP";
	this.aConfig["sHeadlineText_Partner_daily"] = "IHR PARTNER TAGESHOROSKOP";
	this.aConfig["sHeadlineText_Partner_weekly"] = "IHR PARTNER WOCHENHOROSKOP";
	this.aConfig["sHeadlineText_personal"] = "IHR PERSÖNLICHES HOROSKOP";
	this.aConfig["sPixelPathWiga"] = "horoskop_igoogle";
	
}



/**
* Horoskop aktualisieren
*
*/
function mRefreshHoroskop() {
	
	switch(this.aSettings["sView"]) {
	
	case "personal":
		sURL = this.aConfig["sGetPersonalHoroskop"].replace(/{name}/g, escape(this.aSettings["sName"]));
		sURL = sURL.replace(/{date}/g, escape(this.aSettings["sDate"]));
		sURL = sURL.replace(/{time}/g, escape(this.aSettings["sTime"]));
		sURL = sURL.replace(/{sex}/g, escape(this.aSettings["sSex"]));
		sURL = sURL.replace(/{city}/g, escape(this.aSettings["sCity"]));
		this.mGetDataFromServerForIframe(sURL+"&PixelPathWiga="+ this.aConfig["sPixelPathWiga"], this.mWritePersonalHoroskopData);
		break;
		
	case "daily":
	case "weekly":
		this.mGetDataFromServerForIframe(this.aConfig["sGetHoroskop"]+"?PixelPathWiga="+ this.aConfig["sPixelPathWiga"], this.mWriteHoroskopData);
		break;
		
	default:
		this.mGetDataFromServerForIframe("gethoroskop.php?PixelPathWiga="+ this.aConfig["sPixelPathWiga"], this.mWriteHoroskopData);
		break;
		
	}
}


/**
* Horoskop in HTML-Seite schreiben
*
* @param string sContent übergabe des Contents
*/
function mWriteHoroskopData(sContent) {
	oTime = new Date();
	
	// sContent ist das ergebnis aus gethoroskop.php
	this.sContent = sContent; //TEST!
	this.oJSONHoroskop = eval('(' + sContent + ')');
	
	// z.b.: daily
	var sView = this.aSettings["sView"];
	// z.b.: Widder
	var sSternzeichen = this.aSettings["sActiveHoroskop"];
	// href des sternzeichen- icons
	var sIconURL = this.aConfig["aIcons"][sSternzeichen];
	// dailyhoroscope oder weeklyhoroscope daten
	var oHoroscope = this.oJSONHoroskop[sSternzeichen][sView + "horoscope"];
	// sHref z.b.: http://horoskop.t-online.de/tageshoroskop/index.php?type=short&zodiac1=1
	var sHref = "javascript:mURLExtern('" + oHoroscope["sLink"] + "')";
	// von wann bis wann das sternzeichen gilt
	aFromdate = this.oJSONHoroskop[sSternzeichen]["fromdate"].split("-");
	aTodate = this.oJSONHoroskop[sSternzeichen]["todate"].split("-");
	
	// zeigt das sternzeichen- icons
	sText = '<div id="Sternzeichen">'
	+ '<img src="' + sIconURL + '" border="0" />'
	+ '</div>';
	Element.replace("Sternzeichen", sText);
	
	// z.b.: Widder 21.03. - 20.04.
	sText = '<div id="HoroskopHeadline">'
	+ '<strong>' + sSternzeichen + '</strong> '
	+ aFromdate[2] + "." + aFromdate[1] + ". - " + aTodate[2] + "." + aTodate[1] + "."
	+ '</div>';
	Element.replace("HoroskopHeadline", sText);
	
	// z.b.: Liebe und Leidenschaft
	sText = '<div id="HoroskopText">'
	+ '<strong>' + oHoroscope["sTitle"] + '</strong><br />'
	+ oHoroscope["sText"]
	+ '</div>';
	Element.replace("HoroskopText", sText);
	
	sText = '<div id="Link">'
	+ '<a href="' + sHref + '">'
	+ this.aConfig["sLinkText_" + sView] + '</a></div>';
	Element.replace("Link", sText);
	
}

/**
* Persönliches Horoskop in HTML-Seite schreiben
*
* @param string sContent übergabe des Contents
*/
function mWritePersonalHoroskopData(sContent) {
	oTime = new Date();
	
	// sContent ist das ergebnis aus getpersonalhoroskop.php
	this.sContent = sContent; //TEST!
	this.oJSONHoroskop = eval('(' + sContent + ')');
	
	// z.b.: Widder
	var sSternzeichen = this.oJSONHoroskop["sign"];
	// href des sternzeichen- icons
	var sIconURL = this.aConfig["aIcons"][sSternzeichen];
	// dailyhoroscope (default) oder weeklyhoroscope daten
	var oHoroscope = this.oJSONHoroskop["dailyhoroscope"];  // dailyhoroscope weeklyhoroscope personalhoroscope
	// sHref z.b.: http://horoskop.t-online.de/tageshoroskop/index.php?type=long&zodiac1=1
	var sHref = "javascript:mURLExtern('" + oHoroscope["sLink"] + "');";
	// von wann bis wann das sternzeichen gilt
	var aFromdate = this.oJSONHoroskop["fromdate"].split("-");
	var aTodate = this.oJSONHoroskop["todate"].split("-");
	
	// zeigt das sternzeichen- icons
	sText = '<div id="Sternzeichen">'
	+ '<img src="' + sIconURL + '" border="0" />'
	+ '</div>';
	Element.replace("Sternzeichen", sText);
	
	// z.b.: Widder 21.03. - 20.04.
	sText = '<div id="HoroskopHeadline">'
	+ '<strong>' + sSternzeichen + '</strong> '
	+ aFromdate[2] + "." + aFromdate[1] + ". - " + aTodate[2] + "." + aTodate[1] + "."
	+ '</div>';
	Element.replace("HoroskopHeadline", sText);
	
	// z.b.: Liebe und Leidenschaft
	sText = '<div id="HoroskopText">'
	+ '<strong>' + oHoroscope["sTitle"] + '</strong><br />'
	+ oHoroscope["sText"]
	+ '</div>';
	Element.replace("HoroskopText", sText);
	
	sText = '<div id="Link">'
	+ '<a href="' + sHref + '">'
	+ this.aConfig["sLinkText_personal"] + '</a></div>';
	Element.replace("Link", sText);

}



/**
* Topmeldung in HTML-Seite schreiben
*
* @param string sContent übergabe des Contents
*/
function mWriteMessageData(sContent) {
	this.oJSONMessage = eval('(' + sContent + ')');
	
	var sHref = "javascript:mURLExtern('" + this.oJSONMessage["aTopmeldung"]["aItem1"]["sLink"] + "');";
	sText = '<div id="Lifestyle"><a href="' + sHref + '" ><strong>'
	+ this.oJSONMessage["aTopmeldung"]["aItem1"]["sTitle"] + '</strong><br />' 
	+ this.oJSONMessage["aTopmeldung"]["aItem1"]["sDescription"] + '</a></div>';
	Element.replace("Lifestyle", sText);
}


/**
* Tobmeldung aktualisieren
*
*/
function mRefreshMessage() {
	this.mGetDataFromServer(this.aConfig["sGetTopMessageFile"], this.mWriteMessageData);
}


/**
* Initialisieren der Applikation
*
* @param string sView übergabe der Anzuzeigenden Ansicht
*/
function mInitApp() {
	
	this.mInitConfig();
	this.mLoadSettings();
	this.Count = 0;
	
	this.aSettings["sActiveHoroskop"]=this.aSettings["sHoroskop"];
	if (this.aSettings["sShowPartnerHoroskop"] != "false")
	{
	  	this.aSettings["sActiveHoroskop"]=this.aSettings["sHoroskopPartner"];
	}
	
	if (!this.aSettings["sView"]) this.aSettings["sView"] = "daily";
	
	this.oMessageInterval = window.setInterval("this.mRefreshMessage()", this.aConfig["lMessageIntervalTime"]);
	this.oHoroskopInterval = window.setInterval("this.mRefreshHoroskop()", this.aConfig["lHoroskopIntervalTime"]); 
	
	// direkt, aber etwas später aufrufen wegen IE
	window.setTimeout("this.mRefreshMessage()", 50);
	window.setTimeout("this.mRefreshHoroskop()", 100);
}

/**
* Pixel senden
*
* @param string URL des Pixels
*/
function mSendPixel(sURL) {
	sText = '<div id="Pixel">';
	sText += '<img src="' + sURL + '&na=' + Date.parse(new Date())  + '" width="1" height="1" border="0" />';
	sText += '</div>';
	Element.replace("Pixel", sText);
}

