/* (c) Scientec Internet Applications + Media GmbH - www.scientec.de */
init();
function init()
{
  if(document.referrer.indexOf(self.location.host) == -1)
  {
    dummyImg = new Image();
    var ref=encodeURI(document.referrer).replace(/\&/,"__");
    dummyImg.src = "http://www.onwatch.de/referrer.php?referrer="+ref+"&location="+location.href+"&pid="+pid;
  }
  mail();
  LINKS = document.getElementsByTagName("A");
  for(var i = 0; i < LINKS.length; i++)
  {
    var thisLink= LINKS[i];
    if(thisLink.href.indexOf(self.location.host) == -1){thisLink.onmousedown = function(){onwatch(this,location);this.removeAttribute('onmousedown')};}
    var thisParentTag=thisLink.parentNode.tagName.toLowerCase();
    if(thisParentTag=="cite"){thisLink.title="Zur externen Homepage"; thisLink.target="_blank"}
    else if(thisParentTag=="span"){thisLink.childNodes[0].title="Informationen zum Ranking"}
    else if(thisParentTag=="h2"){thisLink.title="Details anzeigen"}
  }
}
function onwatch(link,location)
{
  dummyImg = new Image();
  dummyImg.src = "http://www.onwatch.de/onclick.php?url="+link.href+"&location="+location.href+"&pid="+pid;
}

function suche(){
  if(document.getElementById("qs").value.length<3)return false
  else return true
}
function mail(){
  var EMs=document.getElementById("inhalt").getElementsByTagName("em");
  if(EMs.length>0){
    for(var i=0;i<EMs.length;i++){
      var thisEM=EMs[i];
      if (thisEM.firstChild.tagName=="A"){
        var thisA=thisEM.firstChild;
        thisA.title=thisA.title.replace(/~AT~/,"@");
        thisA.href="mai"+"lto:"+String(thisA.title);
        thisA.title="E-Mail senden";
        thisA.innerHTML=thisA.innerHTML.replace(/~AT~/,"@");
      }
    }
  }
}

if(typeof(hid)!="undefined")
{
  if(hid)
  {
    document.getElementById("hlink").innerHTML = '<a href="http://www.hotel.de/Booking.aspx?lng=DE&han=1158134&h_hmid='+hid+'" target="_blank" onmousedown="onwatch(this,location);this.removeAttribute(\'onmousedown\')" ><img src="../_grafik/buchen.gif" alt="Info & buchen" title="Info & buchen" border=0></a>';
  }
}

function isUrl(url)
{
  if(url.match(/https{0,1}:\/\//))
  {
    return true;
  }
  else
  {
    alert("Verwenden Sie bitte die komplette URL, z.B. 'http://www.domainname.de'");
    return false;
  }
}


/**** Karl ****/
window.addEvent('domready', function(){
  var test = new layer($$('.screen'),{});
  if(document.getElementsByName("ref")[0]){document.getElementsByName("ref")[0].value="jsok";}
});
/*
var test = new layer($$('.itemcont'),{
    initialize:function(){
        this.fx1 = new Fx.Style(this.toolTip, 'opacity', {duration: 0, wait: false}).set(0);
        this.fx2 = new Fx.Style(this.toolTip, 'opacity', {duration: 0, wait: false}).set(0);
      },
      onShow: function(toolTip) {
        this.fx1.start(1);
      },
      onHide: function(toolTip) {
        this.fx2.start(0);
      }
});
*/

var navUA = navigator.userAgent;
var navAN = navigator.appName;
var navAV = navigator.appVersion;
var dom=(document.getElementById)?1:0;
function FV_appName(){
 if (navAN.indexOf("Microsoft") != -1){return "IE";}
 else if(navAN.indexOf("Netscape") != -1){ return "NS";}
 else { return "Other";}
}
function FV_appVersion(){
  if (FV_appName()=="IE" && navAV.substring(0,1)==4 && navUA.indexOf("MSIE 5")!=-1){return 5;}//IE5 bug
  else if (FV_appName()=="IE" && navAV.substring(0,1)==4 && navUA.indexOf("MSIE 6")!=-1){return 6;}
  else if (FV_appName()=="IE" && navAV.substring(0,1)==4 && navUA.indexOf("MSIE 7")!=-1){return 7;}
  else {return navAV.substring(0,1);}
}
function FV_appNameVersion(){
  {return FV_appName()+FV_appVersion()}
}
var IE6 = (FV_appNameVersion() == "IE6")? true:false;

var layer = new Class({
	options: {
		onShow: function(tip){
			tip.setStyle('visibility', 'visible');
		},
		onHide: function(tip){
			tip.setStyle('visibility', 'hidden');
		},
		showDelay: 100,
		hideDelay: 100,
		className: 'tool',
		offsets: {'x': 5, 'y': 5},
		fixed: false,
		box: window
	},

	initialize: function(elements, options){
		this.setOptions(options);
		this.toolTip = new Element('div', {
			'class': this.options.className + '-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'visibility': 'hidden'
			}
		}).inject(document.body);
		this.wrapper = new Element('div').inject(this.toolTip);
		$$(elements).each(this.build, this);
		if (this.options.initialize) this.options.initialize.call(this);
	},

	build: function(el){
	  if(el.style.backgroundImage.indexOf("screenshots060") != -1)
	  {
		if(el.tagName == "DIV")
		{
		  imgDummy = el.style.backgroundImage.replace("screenshots060","screenshots200");
		  el.store('myImage', imgDummy);
		  el.store('myText', '');
		}
		el.addEvent('mouseenter', function(event){
			this.start(el);
			if (!this.options.fixed) this.locate(event);
			else this.position(el);
		}.bind(this));
		if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
		var end = this.end.bind(this);
		el.addEvent('mouseleave', end);
		el.addEvent('trash', end);
	  }
	},

	start: function(el){
		this.wrapper.empty();
			this.title = new Element('div', {'class': 'imagecont1'}).inject(this.wrapper);
			this.title.setStyle('background-image', el.retrieve('myImage'));
			this.text = new Element('div', {'class': 'text1'}).inject(this.wrapper);
			this.text.innerHTML = el.retrieve('myText');
		$clear(this.timer);
		this.timer = this.show.delay(this.options.showDelay, this);
	},

	end: function(event){
		$clear(this.timer);
		this.timer = this.hide.delay(this.options.hideDelay, this);
	},

	position: function(element){
		var pos = element.getPosition();
		this.toolTip.setStyles({
			'left': pos.x + this.options.offsets.x,
			'top': pos.y + this.options.offsets.y
		});
	},

	locate: function(event){
		if(this.options.box == window)
		{
			var win = {'x': window.getWidth(), 'y': window.getHeight()};
			if(window.innerWidth)
			{
			  win = {'x': window.innerWidth, 'y': window.innerHeight};
			}
			if(document.body.clientWidth)
			{
			  win = {'x': document.body.clientWidth, 'y': document.body.clientHeight};
			}
		}
		else
		{
			var win = {'x': this.options.box.offsetWidth, 'y': this.options.box.offsetHeight};
		}

		var scroll = {'x': window.getScrollLeft(), 'y': window.getScrollTop()};
		var tip = {'x': this.toolTip.offsetWidth, 'y': this.toolTip.offsetHeight};
		var prop = {'x': 'left', 'y': 'top'};
		for (var z in prop){
			var pos = event.page[z] + this.options.offsets[z];
  			if ((pos + tip[z] - scroll[z]) > (win[z]-4))
  			{
  			  pos = event.page[z] + this.options.offsets[z] - tip[z];
  			  if(!IE6)
  			  {
  			    this.toolTip.style.backgroundImage = "url('http://www.lokal.ws/_grafik/viewer-oben.png')";
  			    this.toolTip.style.paddingTop = "13px";
  			    this.toolTip.style.paddingLeft = "39px";
  			  }
  			}
  			else if(!IE6)
  			{
  			  this.toolTip.style.backgroundImage = "url('http://www.lokal.ws/_grafik/viewer-unten.png')";
  			  this.toolTip.style.paddingTop = "18px";
  			  this.toolTip.style.paddingLeft = "40px";
  			}
    			this.toolTip.setStyle(prop[z], pos);
		};
	},

	show: function(){
		if (this.options.timeout) this.timer = this.hide.delay(this.options.timeout, this);
		this.fireEvent('onShow', [this.toolTip]);
	},

	hide: function(){
		this.fireEvent('onHide', [this.toolTip]);
	}

});

layer.implement(new Events, new Options);

