document.write('<script type="text/javascript" src="/js/jquery/jquery.tooltip.mod.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery/jquery.lightbox-0.5.pack.js"></script>');

var w3cDOMsupport		= (document.getElementById && document.createElement) ? true : false;
var isIE			= (document.all && !document.addEventListener) ? true : false;
var isIE50			= (isIE && !document.createEventObject) ? true : false;
var isIE55			= (isIE && document.createEventObject && !document.compatMode) ? true : false;
var isIE60			= (isIE && document.defaultCharset && document.compatMode) ? true : false;
var isFirefox			= (window.XML) ? true : false;
var isOpera			= (document.detachEvent && document.addEventListener) ? true : false;
var msgBoxEnlarged		= false;
var msgBoxWidth			= null;
var msgBoxHeight		= null;
var subnavDisplayed		= true;
var contentSubnavPaddingLeft	= null;
var categoryName 		= null;
var sntHeight 			= null;
var trailerLength		= 0;
var tabSlideshowClicked = false;

function checkFieldValue(obj)
{
	if (obj.value.substr(0,1) == '<') obj.value='';
};

/**
 *
 */

function validateForm(f)
{
	f.submitButton.value= '... Ihr Beitrag wird geschrieben - bitte etwas Geduld ...';
	f.submitButton.disabled = true;
};

/**
 *
 */

function resizeTextarea(obj)
{
	if (w3cDOMsupport) {
		var msgBox = document.getElementById(obj);
		if (msgBoxEnlarged == false) {
			msgBoxWidth = msgBox.style.width;
			msgBoxHeight = msgBox.rows;
			msgBox.style.width ="99%";
			msgBox.rows = msgBoxHeight*2;
			msgBoxEnlarged = true;
			document.getElementById("resizeButton").value = "Eingabefeld verkleinern";
			if (document.getElementById("msgHelp")) {
				document.getElementById("msgHelp").style.visibility = "hidden";
				document.getElementById("msgHelp").style.position= "absolute";
			}
		} else {
			document.getElementById("resizeButton").value = "Eingabefeld vergrößern";
			msgBox.style.width=msgBoxWidth;
			msgBox.rows=msgBoxHeight;
			msgBoxEnlarged = false;
			if (document.getElementById("msgHelp")) {
				document.getElementById("msgHelp").style.visibility = "visible";
				document.getElementById("msgHelp").style.position= "relative";
			}
		}
	}
};

/**
 *
 */

function pasteQuotation(id)
{
	if (w3cDOMsupport) {
		var thisMsgHTML = document.getElementById("msg-"+id);
		var thisMsg = thisMsgHTML.innerHTML;
		var msgBody = thisMsg.split("<p");
		msgBody[0] = msgBody[0].replace(/^\s+/, "");
		msgBody[0] = msgBody[0].replace(/\s+$/, "");
		msgBody[0] = msgBody[0].replace(/<(\/)?strong>/ig,"[$1fett]"); 
		msgBody[0] = msgBody[0].replace(/<(\/)?em>/ig,"[$1kursiv]");
		//msgBody[0] = msgBody[0].replace(/<(\/)?blockquote>/ig,"[$1zitat]");
		msgBody[0] = msgBody[0].replace(/layout/ig,"$1.gif"); 
		msgBody[0] = msgBody[0].replace(/(<([^>]+)>)/ig,""); 
		document.getElementById("msg").value = "[zitat]"+msgBody[0]+"[/zitat]";
		document.getElementById("reply2Msg").value = id;
		document.getElementById("msg").focus();
	}
};

/**
 *
 */

function pop(obj, width, height, scrolling)
{ 
	var x=(screen.width-width)/2; 
	var y=(screen.height-height)/2;
	if (scrolling) {
		scrollbars = "yes";
	} else {
		scrollbars = "no";
	}
	popUpWindow = window.open(obj.href, "", "width="+width+",height="+height+",resizable=no,scrollbars="+scrollbars+",screenX="+x+",screenY="+y+",left="+x+",top="+y);
	popUpWindow.focus();
	return false;
};

function getCookie(key) 
{
	var s, e;
	if (document.cookie) {
		s = document.cookie.indexOf(key+"=");
		if (s < 0) return null;
		s = document.cookie.indexOf("=", s) + 1;
		e = document.cookie.indexOf(";", s);
		if (e < 0) {
			e = document.cookie.length;
		}
		return unescape(document.cookie.substring(s, e));
 	} else {
 		return null;
 	}
};

function setCookie(key, value, lifetime)
{
	var now = new Date();
	var expiry = new Date(now.getTime() + lifetime*24*60*60*1000);
	if ((key != null) && (value != null)) {
		document.cookie = key + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/; domain=.histo-couch.de";
	}
};

function dropCookie(key) 
{
	document.cookie = key+ "=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.histo-couch.de";
};

function openMailDialogue(obj)
{
	if (w3cDOMsupport) {
		var m = obj.innerHTML;
		m = m.replace(/\s+at\s+/, '@');
		document.location = 'mailto:'+m;
	}
};

function confirmSubmit(question)
{
	var agree = confirm(question);
	return agree ? true : false;
};

function printJSDependendFunctions() {
	document.write('</li><li><a id="print" href="javascript:window.print()">Seite ausdrucken</a>');
};

function coverTooltip(anch, isReview)
{
	href = anch.href.replace('http://'+window.location.host+'/', '');
	href = 'http://www.histo-couch.de/public/images/buchcover/'+href.replace('.html', '.jpg');
	var text = 'Lesen Sie die Rezension der histo-Couch';
	tip = '<img src="'+href+'" width="80" />'+text;
	return tip;
}

$(function() {

	if ($.browser.msie) {
		isIE = true;
	}
	
	if ($('body').hasClass('home')) {
		/*	
		$('#new-publications a').tooltip({ 
		    showURL: false, 
		    bodyHandler: function() { 
		        return coverTooltip(this, true); 
		    } 
		});
		*/
	}

	if (parseInt($.browser.version.substr(0,1)) == 6) {
		$('#top-navigation li').mouseover(function(){
			if ($(this).parent().parent().parent().get(0).tagName == 'DIV') {
				$(this).addClass('hover');
			}
		}).mouseout(function(){
			if ($(this).parent().parent().parent().get(0).tagName == 'DIV') {
				$(this).removeClass('hover');
			}
		});
		$('#couch-hopper').mouseover(function(){
			$(this).addClass('hover');
		}).mouseout(function(){
			$(this).removeClass('hover');
		});
	}

	$('#couch-hopper').append('<a href="#" onclick="return false;">Couch wechseln</a><ul><li><a href="http://www.belletristik-couch.de/">Belletristik-Couch.de</a></li><li><a href="http://www.jugendbuch-couch.de/">Jugendbuch-Couch.de</a></li><li><a href="http://www.kinderbuch-couch.de/">Kinderbuch-Couch.de</a></li><li><a href="http://www.kochbuch-couch.de/">Kochbuch-Couch.de</a></li><li><a href="http://www.krimi-couch.de/">Krimi-Couch.de</a></li><li class="l"><a href="http://www.phantastik-couch.de/">Phantastik-Couch.de</a></ul>');
	
	if ($('#publisher-tip h3').length || $('#publisher-tip div').length || $('#publisher-tip span').length) {
		/*
		if ($('#video-player').length) {
			trailerLength = $('#video-player').attr('length');
		}
		*/
		$('ul#edition-topics').append('<li><a href="#"><span class="no">'+($('ul#edition-topics li').length+1)+'<span class="skip">) </span></span><span class="cat">Verlagstipp</span> '+$('#publisher-tip-name').text()+'</a></li>');
	}

	var tabSlideshow = $('ul#edition-topics').tabs('div#panes > div.pane', {
		current: 'active',
		effect: 'fade',
		rotate: false,
		onBeforeClick: function(event, tabIndex) {
			if (tabSlideshowClicked && typeof(event.pageX) == 'undefined') {
				return false;
			}		
		},
		onClick: function(event, tabIndex) {
			if (typeof(event.pageX) != 'undefined') {
				tabSlideshowClicked = true;
			}

			if (tabIndex == $('ul#edition-topics li').length-1) {				
				if (trailerLength > 0) {
					var myInterval = trailerLength;
				} else {
					var myInterval = tabSlideshow.getConf().interval;
				}
				
				if (!$.browser.msie) {
					setTimeout(function(obj) { obj.click(0); tabSlideshowClicked = true; }, myInterval, this);
				} else {
					var obj = this;
					setInterval(function () { obj.click(0); tabSlideshowClicked = true; }, myInterval);
				}
			}
		}
	}).slideshow({autoplay: true, interval: 7500, clickable: true, api: true});
});

//if (parent.frames.length) window.top.location.replace(document.location.href);
