/* START: configuration */
var USE_CSS_BROWSER_FLAG;
USE_CSS_BROWSER_FLAG = USE_CSS_BROWSER_FLAG !== undefined ? USE_CSS_BROWSER_FLAG : true; // set default

var SAFARI_STYLESHEET_REFERENCE = "./../_resources/css/styles_safari.css";

/* END: configuration */
/********************************************************************/
/*START: Fix IE 6 Text Selection Bug & Flickering Background Images */
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat" && !window.XMLHttpRequest) {

	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}
/*END: Fix IE 6 Text Selection Bug & Flickering Background Images   */
/********************************************************************/
/* START: browser detection                                         */

if(Info !== undefined){
	if (window.console && window.console.log) window.console.log(Info, '[Info] variable collision: Info already defined');
}

var Info = new function() {

	var userAgent = navigator.userAgent.toLowerCase();

	// check user agent
	function is(str) { return userAgent.indexOf(str) > -1; }

	// version detection
	function version() {
		var versionString = '';
		var specificOffset = 0;
		var specificLength = 1;

		if(b.isIE)      { versionString = 'msie'; specificOffset = 1; }
		if(b.isFirefox) { versionString = 'firefox/'; specificLength = 3; }
		if(b.isSafari)  { versionString = 'version/'; } // note: detects only safari 3+
		if(b.isChrome)  { versionString = 'chrome/'; }
		if(b.isOpera)   { versionString = 'version/'; specificLength = 2;
			// for Opera version < 10
			if(userAgent.indexOf(versionString) == -1) {
				versionString = 'opera/'; specificLength = 1;
			}
		}

		return parseFloat((userAgent.substr(userAgent.indexOf(versionString) + versionString.length + specificOffset, specificLength)));
	}

	// browser detection
	var b = {};
	b.isOpera      = typeof window.opera != 'undefined';
	b.isIE         = is('msie') && b.isOpera == false;
	b.isWebkit     = is('webkit');
	b.isChrome     = is('chrome');
	b.isSafari     = is('safari') && (b.isChrome == false) && is('version'); // note: detects only safari 3+
	b.isMozilla    = is('gecko') && b.isWebkit == false && b.isSafari == false && b.isChrome == false && b.isOpera == false;
	b.isFirefox    = b.isMozilla == true && is('firefox');
	b.isKonqueror  = navigator.product != null && navigator.product.toLowerCase().indexOf('konqueror') > -1;
	this.browser   = b;

	//browser version initialization
	b.version = version();
	if(b.version == 0 || isNaN(b.version)) { b.version = false; }

	// backward compatibility, use b.version to detect browser version in new scripts
	b.isSafari3    = b.isSafari && (b.version == 3);
	b.isSafariGte3 = b.isSafari && (b.version >= 3);
	b.isIE7        = b.isIE && (b.version == 7);
	b.isIEpre8     = b.isIE && (b.version < 8);
	b.isIEpre7     = b.isIE && (b.version < 7);
	b.isIEpre6     = b.isIE && (b.version < 6);

	//OS detection
	var os = {};
	os.isLinux     = (navigator.platform.indexOf("Linux") == 0),
	os.isMac       = (navigator.platform.indexOf("Mac") == 0),
	os.isWin       = (navigator.platform.indexOf("Win") == 0)
	this.os        = os;
	
	// windows version detection >> 5.0=2000 5.1=XP, 5.2=2003, 6.0=Vista, 6.1=Win7
	if(this.os.isWin) {
		this.os.winVersion = parseFloat(userAgent.substr(userAgent.indexOf('nt') + 3, 3));
	}
	
	//has transparency support detection
	this.hasTransparencySupport = true;
	if(this.os.isLinux || this.browser.isKonqueror || (this.os.isMac && !(this.browser.isSafari && b.version >= 3))) {
		this.hasTransparencySupport = false;
	}

	//CSS classes
	function setCss() {
		var h = document.getElementsByTagName('html')[0],
		classes=[
			(
				b.isIE      ? ('ie ie' + b.version) :
				b.isFirefox ? ('firefox firefox' + (b.version.toString().replace(/\./ig, ''))) :
				b.isChrome  ? ('chrome chrome' + b.version) :
				b.isSafari  ? ('safari safari' + b.version) :
				b.isOpera   ? ('opera opera' + b.version)	: ''
			),
			(
				b.isMozilla ? 'gecko' :
				b.isWebkit  ? 'webkit' : ''
			),
			(
				os.isWin    ? 'win' :
				os.isMac    ? 'mac' :
				os.isLinux  ? 'linux' : ''
			),
			'js'
		];
		h.className += h.className == '' ? classes.join(' ') : ' ' + classes.join(' ');
		return classes;
	}

	if(USE_CSS_BROWSER_FLAG) setCss();
	
	this.hasFlash = false;
}

/* END: browser detection                                           */
/********************************************************************/
/* START: flash detection                                           */
if(typeof Info != "undefined" && swfobject){
	var flashVersion = swfobject.getFlashPlayerVersion();
	Info.flash = {};
	Info.flash.major = flashVersion.major;
	Info.flash.minor = flashVersion.minor;
	Info.flash.rev = flashVersion.rev;
	Info.hasFlash = (flashVersion.major > 0);
	if(Info.hasFlash){
		var h = document.getElementsByTagName('html')[0];
		h.className += h.className == '' ? 'flash' : ' flash';
	}
}
/* END: flash detection                                             */
/********************************************************************/
/*START: browser detection*/
function BrowserDetection()
{
	var sUserAgent = navigator.userAgent.toLowerCase();

	// browser name
	this.isIE = (sUserAgent.indexOf('msie') != -1);
	this.isIE7 = (this.isIE && typeof window.XMLHttpRequest != "undefined");
	this.isSafari = (sUserAgent.indexOf('safari') != - 1);
	this.isMozilla = (sUserAgent.indexOf('gecko') != -1 && this.isSafari == false);
	this.isFirefox = (this.isMozilla == true && sUserAgent.indexOf('firefox') != -1);
	this.isOpera = (sUserAgent.indexOf('opera') != -1 || typeof window.opera != "undefined");
}

var oBrowser = new BrowserDetection();
/*END: browser detection*/
/********************************************************************/
/********************************************************************/
/*START: Safari Browser Detection and Serve Styles */
if (oBrowser.isSafari)
{
	document.write ("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + SAFARI_STYLESHEET_REFERENCE + "\" />");
}
/*END: Safari Browser Detection and Serve Styles */
/********************************************************************/

window.onload = replaceSifr;


function replaceSifr()
{
	
	if(oBrowser.isIE && browserIeVersion() < 7)
	{
		if(deconcept.SWFObjectUtil.getPlayerVersion().major <= 9)
		{
			$("html").removeClass("sIFR-hasFlash");
			return; 
		}
	}
	
	var color = rgbToHex($("div.sifr h2").css("color"));
	
	if(typeof sIFR == "function")
	{
		sIFR.replaceElement(named({sSelector:"div.sifr", sFlashSrc: "./../_resources/swf/bell.swf", sColor:color, sWmode:"transparent", sFlashVars:"textalign=center"}));
	}
}

/***************************** Helper Functions *******************************************/

function rgbToHex(rgb)
{
	if(rgb)
	{
		var ex = /^#/;
		var result =  ex.test(rgb);
		if (result == false)
		{
			  rgb = rgb.split(/\(|,|\)/);
			  var hexstr = "#";
			  for (var i = 1; i < rgb.length-1; i++)
			  {
			    var c = parseInt(rgb[i]).toString(16);
			    hexstr += c.length == 1 ? "0"+c : c;
			  }
			  return hexstr.toUpperCase();
		}
		else
		{ 
			return rgb;
		}
	}
	else return '#000000';
}

function emToPx(valuePx)
{
	if(typeof valuePx != "undefined")
	{
		if(valuePx.indexOf("em") != -1)
		{// em
			var valueEm = parseFloat(valuePx);
			valueEm *= 10; // in int und px umwandeln
		}
		else
		{
			var valueEm = valuePx.replace("px","");
	
			valueEm *= 1; // in int umwandeln
			
		}
	}
	else
	{
		valueEm = 0;
	}
	return valueEm;
}

function getAbsolutePosition(element)
{
     var r = { x: element.offsetLeft, y: element.offsetTop };
     if (element.offsetParent) {
       var tmp = getAbsolutePosition(element.offsetParent);
       r.x += tmp.x;
       r.y += tmp.y;
     }
     return r;
}

function getWindowInnerSize()
{
	var objWin = new Object();

	if (self.innerHeight) {
	// all except Internet Explorer
		objWin.width = self.innerWidth;
		objWin.height = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
	// Explorer 6 Strict Mode
		objWin.width = document.documentElement.clientWidth;
		objWin.height = document.documentElement.clientHeight;
	} else if (document.body) {
	// other Explorers
		objWin.width = document.body.clientWidth;
		objWin.height = document.body.clientHeight;
	}
	return objWin;
}


/**
  *   COOKIE handling
  */

function createCookie(name,value,days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function browserIeVersion()
{
	var browser = navigator.userAgent.toLowerCase();
	if(browser.indexOf('msie') != -1)
	{
		return parseInt(browser.substr(browser.indexOf('msie')+5, 1));
	}
	else return false;
}



/***************************** Helper Functions *******************************************/

/**
  *   Array convenience method to check for membership.
  *
  *   @param object element
  *   @returns boolean
  */
Array.prototype.contains = function(obj)
{
      var i, listed = false;
      for (i=0; i<this.length; i++)
	 {
	if (this[i] === obj)
	   {
	  listed = true;
	  break;
	}
      }
      return listed;
};


Array.prototype.indexOf = function(obj)
{
	var i, idx = -1;
	for (i=0; i<this.length; i++)
	{
		if (this[i] === obj)
		{
		      idx = i;
		      break;
		    }
	  }
	return idx;
};


