var homeAniInterval, homeSlideInterval, homeAniIndex=false;
var ie,badBrowser;
var infoImageOpacity=0.4;
var themeWorldIndex=0;
var minHeight=580;
var heightThreshold=750;
$(document).ready(function(){
	ie = jQuery.browser.msie
	badBrowser = ie && jQuery.browser.version<7;
	if($('ul.multimediaControl').length==1){
		multimediaDisplay_control();
		$('ul.multimediaControl').find('a').bind('click',multimediaDisplay_control);
	}
	window.onresize=function(){
		setBoxHeight();
	}
	setBoxHeight();
	
	$("a.infoImage").each(function(){
		var infoAnchor=$(this);
		var infoImage=$(this).children('img');
		infoImage.css({opacity:0,width:2,height:2,left:13,top:13});
		replaceTitleTag(infoAnchor);
		bubbleMe(infoImage);
	});
	$("a.infoImage").bind('mouseenter',function(){
		stopAutoSlide();
		var infoImage=$(this).children('img');
		infoImage.stop();
		infoImage.css({opacity:infoImageOpacity});
		infoImage.animate({width:14,height:14,left:7,top:7,opacity:1},50,function(){
			infoImage.animate({width:28,height:28,left:0,top:0},100,function(){
				showTooltip(infoImage);
			});
		})
	});
	
	$("a.infoImage").bind('mouseleave',function(){
		var infoImage=$(this).children('img');
		infoImage.stop();
		infoImage.animate({width:28,height:28,left:0,top:0,opacity:infoImageOpacity},700);
		hideTooltip(infoImage);
	});
	
// Produktweltenanimation - wird gestoppt bei Benutzereingriff
	$('div.homeTeaser:first-child a.hoverLink,div.homeTeaser:first-child ul a').bind('mouseenter mouseleave',function(event){
		var anchorItem=event.currentTarget;
		var anchorLength=4, anchorIndex;
		$(anchorItem).parents('div.homeTeaser').find('a').each(function(index){
			if(this==anchorItem) anchorIndex=(index/anchorLength-Math.floor(index/anchorLength))*anchorLength;
		});
		window.clearInterval(homeAniInterval);
		toggleProductWorlds('mouseleave',homeAniIndex);
		toggleProductWorlds(event.type,anchorIndex);
	});
	homeAniInterval=window.setInterval(function(){
		if(homeAniIndex!==false) {
			toggleProductWorlds('mouseleave',homeAniIndex);
			homeAniIndex=Math.floor(Math.random()*4);
			toggleProductWorlds('mouseenter',homeAniIndex);
		} else homeAniIndex=0;
	},1000);
	
// Verzögernungssteuerung für Navi und Flyouts
	initDelays(); 
	
	
	$('div#themenWelten li.bracket').css({opacity:0.5});
	$('div#themenWelten a.slideArrow').css({opacity:0}).delay(3000).animate({opacity:1},1000).animate({opacity:0.3},300);
	$('div#themenWelten a.slideArrow').bind('mouseover',function(){$(this).animate({opacity:1},100)});
	$('div#themenWelten a.slideArrow').bind('mouseout',function(){$(this).animate({opacity:0.3},400)});
	$('div#themenWelten a.slideArrow.next').bind('click',function(){slideThemeWorlds(themeWorldIndex+1);stopAutoSlide();});
	$('div#themenWelten a.slideArrow.previous').bind('click',function(){slideThemeWorlds(themeWorldIndex-1);stopAutoSlide();});
	
	
	
	$('div#themenWelten > ul li a').each(function(index){
		replaceTitleTag($(this));
		$(this).data('index',index);
		$(this).bind('mouseenter',function(event){showTooltip(event.target);});
		$(this).bind('mouseleave',function(event){hideTooltip(event.currentTarget);});
		$(this).bind('click',function(event){
			event.preventDefault();
			var themeWorldIndex=$(event.currentTarget).data('index');
			slideThemeWorlds(themeWorldIndex);
			stopAutoSlide();
		});
	});
	homeSlideInterval=window.setInterval(function(){slideThemeWorlds(themeWorldIndex+1);},7000);
//	stopAutoSlide();
	
	$('span.reminder').each(function(){
		$(this).css({display:'inline'});
		$(this).data('width',$(this).width());
		$(this).css({
			display:'none',
			position:'absolute',
			width:'1px'
		});
	});

});
function setBoxHeight(){
	var winHeight=($(window).height());
	var BoxHeight=504;
	if (winHeight<heightThreshold){
		if (winHeight<minHeight) winHeight=minHeight;
		BoxHeight=winHeight-heightThreshold+BoxHeight;
	}
	$('#themenWelten').css({height:(BoxHeight+'px')});
}
function replaceTitleTag(anchor){
	anchor.prepend('<span class="reminder" style="display:none;">'+anchor.attr('title')+'</span>');
	anchor.removeAttr('title');
};
function showTooltip(obj){
	var infoTooltip=$(obj).parent().find('span');
	infoTooltip.css({opacity:0});
	infoTooltip.animate({width:infoTooltip.data('width')+20,opacity:1},100);
}
function hideTooltip(obj){
	var infoTooltip=$(obj).parent().find('span');
	infoTooltip.animate({width:1,opacity:0},100);

}
function bubbleMe(infoImage){
	window.setTimeout(function(){
		infoImage.animate({opacity:1,width:28,height:28,left:0,top:0},1500,'easeOutElastic',function(){
			infoImage.animate({opacity:infoImageOpacity},700);
		});
	},Math.floor(Math.random()*1500)+800); //timer for run-in bubbles
}
function stopAutoSlide(){
	window.clearInterval(homeSlideInterval);
//	jp('stop');
}

function slideThemeWorlds(index){
	var last=($('div#themenWelten li').length)-2;
	if (index<0) index=last;
	if (index>last) index=0;
	themeWorldIndex=index;
	$('div#themenWelten li.bracket').stop();
	$('div#themenWelten li.bracket').animate({left:65*index},800,'easeInOutQuart',function(){
		$('div#themenWelten li.bracket').animate({opacity:1},300);
		$('div#themenWelten li.bracket').animate({opacity:0},300);
		$('div#themenWelten li.bracket').animate({opacity:1},300);
		$('div#themenWelten li.bracket').animate({opacity:0.5},300);
	});
		$('div.scrollbox').animate({marginLeft:-(880+59)*index},800,'easeInOutQuart',function(){
		$("a.infoImage").each(function(){
			var infoAnchor=$(this);
			var infoImage=$(this).children('img');
//			infoImage.stop();
			infoImage.animate({opacity:infoImageOpacity,width:10,height:10,left:9,top:9},200);
			bubbleMe(infoImage);
		});
	});
}

function toggleProductWorlds(type,anchorIndex){
	var anchors=$('div.homeTeaser:first-child a.hoverLink');
	var listElements=$('div.homeTeaser:first-child ul li');
	if(type=='mouseenter'){
		$(anchors[anchorIndex]).addClass('hover');
		$(listElements[anchorIndex]).addClass('hover');
	}else{
		$(anchors[anchorIndex]).removeClass('hover');
		$(listElements[anchorIndex]).removeClass('hover');
	}
}
/********************************** MULTIMEDIA DISPLAY CONTROLS *********************************************/
var multimediaDisplayStatus = 'gallery'; //  galleryZoomed; 360; 
var movieStatus;

function multimediaDisplay_hideAll (){
	$('div.multimediaDisplay').children('div').each(function(index){
		if (index>0 ) $(this).css({'display':'none'});
	});
}
function multimediaDisplay_control (event){ // call from event
	
	var func;
	var source;
	var listObjects = new Object;
	var imageObjects = new Object;
	//get available controls
	$('ul.multimediaControl').children('li').each(function(){
		image=$(this).children('a').children('img')[0];
		source=image.src;
		func=source.substring(source.lastIndexOf('_')+1,source.lastIndexOf('.'));
		listObjects[func]=this;
		imageObjects[func]=image;
		if(func=='movie') movieFilename=$(this).children('a').attr('href');
	});
	if (typeof(event)=='object'){
		event.preventDefault();
		source=event.target.src;
		movieFilename=event.currentTarget.href;
		func=source.substring(source.lastIndexOf('_')+1,source.lastIndexOf('.'));
		
	} else if(typeof(event)=='string'){ // call from function
		func=event;
	} else { //first run
		/**/if(listObjects['movie']) {
			func='movie';
		}
		else if(listObjects['360']) func='360'; 
		else func='gallery';
		
		$('#multimediaDisplay_galleryThumbs a').bind('click',changeImage);
		mouseObject=$('#multimediaDisplay_surface');
		mouseObject.bind('mousedown',surfaceMouseDown);
		mouseObject.bind('mouseup',surfaceMouseUp);
		mouseObject.bind('click',surfaceMouseClick);
		mouseObject.bind('drag',{distance: 1},surfaceMouseDrag);
		mouseObject.bind('dragstart',surfaceMouseDragStart);
		mouseObject.bind('dragend',surfaceMouseDragEnd);
		mouseObject.bind('dragout',surfaceMouseDragOut);
		mouseObject.bind('dragoutend',surfaceMouseDragOutEnd);
	}
	if(	listObjects[func].className!='active' ){ //ignore selfclick
		multimediaDisplay_hideAll();
		var className='';
		var show=func;
		var status=func;
		
		switch(func){
			case 'gallery':
				movieControls(listObjects,false);
				
				if($('#multimediaDisplay_gallery').children('img').length==1){
					$('#multimediaDisplay_galleryThumbs').css({'display':'block'});
					setCursor('zoomIn');
				} else {
					setCursor('zoomOut');
					status='galleryZoomed';
				}
				
			break;
			case '360':
				movieControls(listObjects,false);
				className='active';
				setCursor('rotate');
				load360();
			break;
			case 'movie':
				if (!movieClip) initMovie(movieFilename);
				className='active';
				movieControls(listObjects,true);
				setCursor('');
				movieStatus='running';
			break;
			case 'movieStop':
				listObjects['movie'].className='active';
				show='movie';
				imageObjects[func].src='img/icon_movieStart.png';
				movieClip.pause();
				movieStatus='stopped';
			break;
			case 'movieStart':
				listObjects['movie'].className='active';
				show='movie';
				imageObjects[func].src='img/icon_movieStop.png';
				movieClip.play();
				movieStatus='running';
			break;
			case 'movieSoundOff':
				show='movie';
				imageObjects[func].src='img/icon_movieSoundOn.png';
				movieClip.unmute();
			break;
			case 'movieSoundOn':
				show='movie';
				imageObjects[func].src='img/icon_movieSoundOff.png';
				movieClip.mute();
			break;
			case 'movieBack':
				show='movie';
				if(movieStatus=='running') multimediaDisplay_control ('movieStop');
				movieClip.stop();
				movieStatus='start';
			break;
			default:
		}
		for(var key in listObjects) listObjects[key].className='';
		listObjects[func].className=className;
		listObjects[show].className='active';
		multimediaDisplayStatus=status;
		$('.multimediaDisplay').children('#multimediaDisplay_'+show).css({'display':'block'});
	}
}
function movieControls(listObjects,show){
	var movieColtrolKeys=new Array('movieStop','movieStart','movieBack','movieSoundOn','movieSoundOff');
	var display=show?'block':'none';
	for(var key in movieColtrolKeys)if(listObjects[movieColtrolKeys[key]]) listObjects[movieColtrolKeys[key]].style.display=display;
}
/********************************** MOUSE-DETECTION *********************************************/
var mouseObject;
var mouseStatus = 'idle'; // down; dragged;
var mouseRelativeX;
var mouseRelativeY;

var mouseVelocityX = 0; // pixel per millisecond
var mouseVelocityY = 0; // pixel per millisecond


function surfaceMouseDown(event){
	mouseStatus = 'down';
	if(zoomImage){
		zoomImageLeft = zoomImage.position().left;
		zoomImageTop = zoomImage.position().top;
	}
	if(multimediaDisplayStatus == '360') threesixy_lastPosition=threesixy_position;
}
function surfaceMouseUp(event){
	if(mouseStatus=='down' && multimediaDisplayStatus == '360') sharpen360();
}
function surfaceMouseClick(event){
	if( mouseStatus == 'down' ){
		mouseRelativeX = (event.pageX - mouseObject.offset().left); // recognize click pos for zooming
		mouseRelativeY = (event.pageY - mouseObject.offset().top);
		if(multimediaDisplayStatus.substring(0,7)=='gallery') {
			galleryZoom();
		}
	}
}
function surfaceMouseDrag(event){
	if(multimediaDisplayStatus == 'galleryZoomed'){
		zoomImage.css({
			left:limit(originalImageWidth-zoomImageWidth,event.offsetX - mouseObject.offset().left + zoomImageLeft,0),
			top:limit(originalImageHeight-zoomImageHeight,event.offsetY - mouseObject.offset().top + zoomImageTop,0)
		}); 
	}
	if(multimediaDisplayStatus == '360'){
		set360(event.offsetX - mouseObject.offset().left + threesixy_lastPosition);
	}
}
function surfaceMouseDragStart(event){mouseStatus = 'dragged';}
function surfaceMouseDragEnd(event){
	mouseStatus = 'idle';
}
function surfaceMouseDragOut(event){
	if(event.type=='dragout'){
		mouseStatus = 'dragout';
//		jp('dragout:' +(event.offsetX - mouseObject.offset().left + threesixy_lastPosition));
		if(multimediaDisplayStatus == 'galleryZoomed'){
			zoomImage.css({
				left:limit(originalImageWidth-zoomImageWidth,event.offsetX - mouseObject.offset().left + zoomImageLeft,0),
				top:limit(originalImageHeight-zoomImageHeight,event.offsetY - mouseObject.offset().top + zoomImageTop,0)
			}); 
		}
		if(multimediaDisplayStatus == '360') set360(event.offsetX - mouseObject.offset().left + threesixy_lastPosition);
	} else sharpen360(); // intro-run sharpen
}
function surfaceMouseDragOutEnd(event){
	sharpen360();
}

function setCursor(cursor){
	mouseObject.removeClass('zoomIn zoomOut pan rotate');
	mouseObject.addClass(cursor);
}
/********************************** GALLERY *********************************************/
var thumbImage_apx='';
var viewerImage_apx='_gross.jpg';
var zoomImage_apx='_zoomimage.jpg';

var zoomImageWidth=1417;
var zoomImageHeight=983;
var zoomImageTimeout=20;
var zoomImageTimer=false;
var zoomImage;

var originalImage;
var originalImageWidth=506;
var originalImageHeight=351;
var zoomImageLeft;
var zoomImageTop;


function changeImage(event){
	event.stopPropagation();
	event.preventDefault();
	
	if(multimediaDisplayStatus == 'gallery'){
		var anchor=event.currentTarget;
		var fadeInImage=$( '<img src="'+anchor.href+'"/>' );
		fadeInImage.css({'display':'none'});
		var fadeOutImage=$('#multimediaDisplay_gallery').children('img:first-child');
		
		if(!$(anchor).hasClass('active')){
			
			$(anchor).addClass('active');
			$(anchor).siblings().removeClass('active');

			fadeOutImage.before(fadeInImage);
			fadeOutImage.fadeOut(500,function(){
				fadeOutImage.remove();
			});
			fadeInImage.load(function(){
				fadeInImage.fadeIn(500);
			});
		}
	}
}
function galleryZoom(){
	originalImage=$('#multimediaDisplay_gallery').children('img');
	if(multimediaDisplayStatus=='gallery'){
		$('#multimediaDisplay_galleryThumbs').fadeOut(500);
		var source=originalImage.attr('src');
		var filename=source.substring(0,source.lastIndexOf('_'));
		zoomImage=$( '<img src="'+filename+zoomImage_apx+'"/>' );
		var zoomFactor=zoomImageWidth/originalImageWidth;
		zoomImageLeft=limit((originalImageWidth-zoomImageWidth),(originalImageWidth/2)-mouseRelativeX*zoomFactor,0);
		zoomImageTop=limit((originalImageHeight-zoomImageHeight),(originalImageHeight/2)-mouseRelativeY*zoomFactor,0);
		originalImage.before(zoomImage);
		zoomImage.load(function(){
			setCursor('pan');
			multimediaDisplayStatus = 'galleryZoomed';
			zoomImage.css({'left':zoomImageLeft+'px','top':zoomImageTop+'px'});
			originalImage.fadeOut(500);
		});
		originalImage.animate({'left':zoomImageLeft+'px','top':zoomImageTop+'px','width':zoomImageWidth+'px','height':zoomImageHeight+'px'},500);
	} else {
		$('#multimediaDisplay_galleryThumbs').fadeIn(500);
		originalImage.css({left:zoomImageLeft,top:zoomImageTop});
		zoomImage.remove();
		zoomImage = false;
		originalImage.animate({'left':'0px','top':'0px','width':'506px','height':'351px'},500, function(){
			multimediaDisplayStatus = 'gallery';
			setCursor('zoomIn');
		});
	}
}

/********************************** MOVIE *********************************************/
var movieFilename;
var movieClip=false;
function initMovie(filename){
	movieClip = flowplayer("multimediaDisplay_movie", {src: "ext/flowplayer/flowplayer-3.1.5.swf", wmode: 'opaque'},{
		//onBeforeClick: function (){return false;},
		onLoad:function () { this.unmute();multimediaDisplay_control('movieSoundOff'); },
		
		clip: { 
        	url: filename, 
        	autoPlay: true,
        	autoBuffering: true,
        	onFinish: function () { multimediaDisplay_control('movieBack'); },
        	onBegin: function () {  }
    	}, 
		plugins: {
			controls: null
		},
    	play:{
			opacity:0
		}
	});
}
/********************************** TREESIXTY *********************************************/
var threesixty_images, threesixty_loadcount=0, threesixy_position=0, threesixy_lastPosition=0;
var threesixty_active=false;

function load360(){
	if(!threesixty_images){
		$('#multimediaDisplay_360').children('img:first-child').clone().appendTo('#multimediaDisplay_360');
		threesixty_images=$('#multimediaDisplay_360').children('img');
		threesixty_images.each(function(){
			if(!this.complete){
				$(this).bind('load',function(){
					threesixty_loadcount ++; // image loaded
					progressbar(threesixty_loadcount/(threesixty_images.length));
					if(threesixty_loadcount==(threesixty_images.length-1)) window.setTimeout(init360,300);
				});
			} else {
				threesixty_loadcount ++; // image already complete
				progressbar(threesixty_loadcount/(threesixty_images.length));
				if(threesixty_loadcount==(threesixty_images.length-1)) window.setTimeout(init360,300);
			}
		});
	}
}
function init360(){
	$('#multimediaDisplay_360').addClass('loaded');
	set360(0);
	$.event.special.drag.remoterun();
}
function set360(mouseX){
	
	threesixy_position=mouseX;
	if(threesixty_active!==false) {
		threesixty_images[threesixty_active].style.display='';
		threesixty_images[threesixty_active+1].style.display='';
		threesixty_images[threesixty_active+1].style.opacity='';
		if(ie)threesixty_images[threesixty_active+1].style.filter='';
	};
	var pointer = 1-((0.5*mouseX/originalImageWidth)-Math.floor(0.5*mouseX/originalImageWidth));
	if (pointer==1) pointer=0;
	pointer*=threesixty_images.length-1;
	threesixty_active=Math.floor(pointer);
	var interframe=pointer-Math.floor(pointer);
	var opacity=limit(0,(interframe-0.5)*2+0.5,1);
	threesixty_images[threesixty_active].style.display='block';
	threesixty_images[threesixty_active+1].style.display='block';
	threesixty_images[threesixty_active+1].style.opacity=opacity*1;
	if(ie)threesixty_images[threesixty_active+1].style.filter='Alpha(opacity='+Math.round(opacity*100)+')';

}
function sharpen360(){
	if(multimediaDisplayStatus == '360'){
		var opacity=$(threesixty_images[threesixty_active+1]).css('opacity'); //ie hack hack
		if(ie)threesixty_images[threesixty_active+1].style.filter=''; //ie hack hack
		$(threesixty_images[threesixty_active+1]).css({'opacity':opacity}); //ie hack hack
		
		if(opacity<0.5){
			$(threesixty_images[threesixty_active+1]).animate({'opacity':0},500);
		} else {
			$(threesixty_images[threesixty_active+1]).animate({'opacity':1},500);
		}
	}
}

function progressbar(percentage){
	if($('#multimediaDisplay_progressbar').css('display')=='none') $('#multimediaDisplay_progressbar').fadeIn(500);
	percentage=Math.round(percentage*100);
	$('.progressbar span span').css({'width':percentage*2+'px'});
	$('.progressbar span b').text(percentage+'%');
	if (percentage==100) $('#multimediaDisplay_progressbar').fadeOut(500);
}


/******************************************************************************/



wedoWorlds=Array('Office','School','Creative','Gifts');

/************************ PRELOADER **************************************/

function OJ_preload(images){
	i=0;
	imageObjects = new Array;
	while (typeof(images[i])!="undefined"){
		imageObjects[i]= new Image(); 
		imageObjects[i].src="img/home/"+images[i];
		i++;
	}
}
/************************ COMMERCE CONNECTOR **************************************/

function OJ_openCConnector (eanCode){
//	window.open('cConnector.php?eanCode='+eanCode, "CommerceConnectorPopup", "width=805,height=686,top=100,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=yes");
	window.open('cConnector.php?eanCode='+eanCode, "CommerceConnectorPopup", "width=935,height=750,top=100,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=yes");
}

function OJ_openOnlineshop (deeplink){
	//deeplink='http://www.printus.de/webapp/wcs/stores/servlet/ProductDisplay?storeId=20&langId=-3&catalogId=1&productId=3491&topCategoryStyleId=ff';
	window.open(deeplink, "OnlineShopWindow", "width=1100,height=900,top=100,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes");

}

/************************ DELAYS **************************************/
var activeThumbnail=false;
var activeFlyout=false;
var activeFlyoutTimer=false;
var activeFlyoutHideTimer=false;
var mousex = false;
var mousey = false;

var pathnaviElement=false;
var pathnaviTimer=false;
var pathnaviHideTimer=false;

function initDelays(){
	var Flyouts=document.getElementsByName('tooltip');
	for ( var i = 0; i < Flyouts.length; i++) { //init events for thumbnails
		Flyouts[i].onmousemove=showFlyout;
		Flyouts[i].onmouseout=hideFlyout;
	}
	var reminders=document.getElementsByName('reminder');
	for ( var i = 0; i < reminders.length; i++) { //init events for thumbnails
		reminders[i].onmouseover=hideReminder;
		reminders[i].id='reminder_'+i;
		window.setTimeout('showReminder("reminder_'+i+'")',4000);
	}
	if (document.body.addEventListener)  //trace mouse position
		document.body.addEventListener('mousemove',getMouseCoordinates,false);
	else if(document.body.attachEvent)
		document.body.attachEvent('onmousemove',getMouseCoordinates);

	if (document.getElementById('pathNavi')){ //set styles and init events for path Navi
		var navi=document.getElementById('pathNavi');
		navi.className = 'off';
		navi.onmouseover = showSubsEvent;
		navi.onmouseout = hideSubsEvent;
	}
}
/************************ PATHNAVI **************************************/
function getMouseCoordinates (e){
	var event = window.event || e;
	mousex = event.pageX || event.clientX;
	mousey = event.pageY || event.clientY;
}
function showSubsEvent(e){
	var event = window.event || e;
	var target = event.srcElement || event.target;
	pathnaviElement = target.parentNode.getElementsByTagName('UL')[0];
	if(pathnaviHideTimer){
		window.clearTimeout(pathnaviHideTimer);
		pathnaviHideTimer=false;
	}
	if(!pathnaviTimer) pathnaviTimer=window.setTimeout('showSubs()',300)
}
function hideSubsEvent(){
	if(pathnaviTimer){
		window.clearTimeout(pathnaviTimer);
		pathnaviTimer=false;
	}
	if(!pathnaviHideTimer) pathnaviHideTimer=window.setTimeout('hideSubs()',300)
}
function showSubs(){
	var navi=document.getElementById('pathNavi');
	navi.className = 'on';
	pathnaviTimer = false;
	if(pathnaviElement){ //buggy ie des not re-render
		pathnaviElement.style.visibility='visible'; 
		pathnaviElement.onmouseover=function(){
			pathnaviElement.style.visibility='';
			pathnaviElement.onmouseover=null;
		}
	}
}

function hideSubs(){
	var navi=document.getElementById('pathNavi');
	navi.className = 'off';
	pathnaviHideTimer = false;
}
/************************ REMINDER **************************************/

function showReminder(id){
	var reminder=document.getElementById(id);
	var span=reminder.getElementsByTagName('SPAN')[0];
	reminder.style.display='block';
	if(span.style.width) {
		var width=parseInt(span.style.width);
		span.style.width=(width+10)+'px';
		if (width<140) window.setTimeout('showReminder("'+id+'")',20);
		else window.setTimeout('hideReminder("'+id+'")',3000)
	} else {
		span.style.width='0px';
			window.setTimeout('showReminder("'+id+'")',500);
		}
}
function hideReminder(id){
	if (id) document.getElementById(id).style.display="none";
	else {
		this.style.display="none";
		
	}
}

/************************ FLYOUTS **************************************/
function showFlyout(e){
	var event = window.event || e;
	activeThumbnail = event.srcElement || event.target;
	while(activeThumbnail.tagName!='A')activeThumbnail=activeThumbnail.parentNode;
	if ( activeFlyout && (activeFlyout != activeThumbnail.nextSibling ) ) { 
		activeFlyout.style.display='none';
		activeFlyout = activeThumbnail.nextSibling;
		setFlyout();
	}
	activeFlyout = activeThumbnail.nextSibling;
	if (activeFlyout.style.display=='block') setFlyout();
	else if(!activeFlyoutTimer) activeFlyoutTimer=window.setTimeout("setFlyout(true);",500);
	if(activeFlyoutHideTimer) { 
		window.clearTimeout(activeFlyoutHideTimer);
		activeFlyoutHideTimer = false;
		//setFlyout();
		}
}
function setFlyout(init){
	if(activeFlyout || init){
//		var scrollOffset=(document.documentElement.scrollTop)?document.documentElement.scrollTop:0; //ie scroll offset
		var scrollOffset=ie?document.documentElement.scrollTop:0; //ie scroll offset
		activeFlyout.style.left=(mousex-getPos(activeThumbnail.offsetParent).left-223)+'px';
		activeFlyout.style.top=(mousey-getPos(activeThumbnail.offsetParent).top-150+scrollOffset)+'px';
		activeFlyout.style.display='block';
	}

}
function hideFlyout(e){
	var event = window.event || e;
	var target = event.srcElement || event.target;
	if(!activeFlyoutHideTimer) activeFlyoutHideTimer=window.setTimeout("hideActiveFlyout()",50);
}
function hideActiveFlyout(){
	activeFlyout.style.display='none';
	window.clearTimeout(activeFlyoutTimer);
	activeFlyoutTimer=false;
	activeFlyout=false;
	activeFlyoutHideTimer=false;

}

function getPos (obj) {
	var output = new Object();
	var mytop=0, myleft=0;
	while( obj) {
		mytop+= obj.offsetTop;
		myleft+= obj.offsetLeft;
		obj= obj.offsetParent;
	}
	output.left = myleft;
	output.top = mytop;
	return output;
}
/**************************** HELPERS *********************************************/

function limit(min,value,max){
	if (value<min) value = min;
	if (value>max) value = max;
	return value;
}
function pyth (a,b){
	return Math.sqrt(a*a+b*b);
}
/**************************** DEBUGGING *********************************************/

var jsPromptPre = "";

function jp(promptTXT){
	promptTXT +=' ';
	if(document.getElementById('jsPrompt')){
		lines=promptTXT.split("\n");
		for (i=0;i<lines.length;i++){
			var newP = document.createElement("p");
			var newTXT = document.createTextNode(lines[i]);
			newP.appendChild(newTXT);
			document.getElementById('jsPrompt').appendChild(newP);
		}
	} else jsPromptPre+="\n"+promptTXT;
}
function jd(obj,hideFuncs){
	var text ="******************_object_dump_********************\n";
	if (typeof(obj)=='object'){
		for(var key in obj) {
			if (key!='channel'){
				if (obj[key]) 
					var string=""+obj[key];
//					if(typeof(obj[key])!='function' && typeof(obj[key])!='undefined') text+=typeof(obj[key])+" => "+ key+" => "+string+"\n";
					if(typeof(obj[key])!='function' && typeof(obj[key])!='undefined') text+=key+" => "+string+"\n";
					else if(!hideFuncs)text+=key+" => "+string.substring(0,string.indexOf('{'))+"\n";
			}
//			if (obj[key]) text+=key+" => "+obj[key]+"\n";
		}
		jp(text+"*********************_end_dump_********************\n");
	}
}
function jc(){
	if(document.getElementById('jsPrompt')){
		document.getElementById('jsPrompt').innerHTML='';
	} else jsPromptPre="";
	
}

/************************ Search **************************************/

function is_search(){
	if (document.forms[0].search.value=='')return;
	else document.forms[0].submit();
}