OJ_timers=new Object;
OJ_timer=false;
OJ_homeAniTimer=false;
OJ_homeAniInterval=false;

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){
	window.open(deeplink, "OnlineShopWindow", "width=1100,height=900,top=100,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes");

}
/************************ HOME show Products **************************************/

function OJ_showTopRecommended(object){
	id='popups'+object.id.substr(6,object.id.length-6);
	if(typeof OJ_timers[id] == "undefined") OJ_timers[id] = false;
	if(OJ_timers[id]) window.clearTimeout(OJ_timers[id]);
//	document.getElementById(id).style.visibility='visible';
	OJ_timers[id] = window.setTimeout('document.getElementById("'+id+'").style.visibility="visible"',500);
}
function OJ_hideTopRecommended(object){
	id='popups'+object.id.substr(6,object.id.length-6);
	if(OJ_timers[id]) window.clearTimeout(OJ_timers[id]);
	OJ_timers[id] = window.setTimeout('document.getElementById("'+id+'").style.visibility="hidden"',500);
}

/************************ HOME ANI **************************************/

function initHomeAni(){
	if (OJ_homeAniTimer) window.clearTimeout(OJ_homeAniTimer);
	OJ_homeAniTimer = window.setTimeout('startHomeAni();',5000);
}
function startHomeAni(){
    if (OJ_homeAniInterval)window.clearTimeout(OJ_homeAniInterval);
    OJ_homeAniInterval = window.setTimeout ("changeWorld (false);", 5000);
}
function changeWorld (world){
	if (world) hideWorld(world);
	while ((nextWorld = wedoWorlds[Math.floor(Math.random()*4)])==world){}; //nicht die gleiche nochmal
	delay=(Math.random()>0.7)?5000:500;
	showWorld(nextWorld);
    OJ_homeAniInterval = window.setTimeout ("changeWorld ('"+nextWorld+"');", delay);
	
}
function stopHomeAni(){
	if (OJ_homeAniTimer) window.clearTimeout(OJ_homeAniTimer);
    if (OJ_homeAniInterval){
		i=0;
		while(typeof(wedoWorlds[i])!='undefined') hideWorld(wedoWorlds[i++]);
		window.clearInterval(OJ_homeAniInterval);
		OJ_homeAniInterval=false;
	}
	initHomeAni();
}

function showWorld(name){
	object=document.getElementById('square'+name);
	filename = name.toLowerCase();
	object.getElementsByTagName('a')[0].style.backgroundImage="url('img/home/"+filename+".jpg')";
	object.getElementsByTagName('span')[0].style.visibility="hidden";
	OJ_timers['name'] = window.setTimeout ('OJ_showTopRecommendedAni("popups'+name+'");',1000);
}
function hideWorld(name){
	if(typeof(OJ_timers['name'])=='number') window.clearTimeout(OJ_timers['name']);
	object=document.getElementById('square'+name);
	object.getElementsByTagName('a')[0].style.backgroundImage='';
	object.getElementsByTagName('span')[0].style.visibility='';
	OJ_hideTopRecommendedAni("popups"+name);
}

function OJ_showTopRecommendedAni (id){
	object=document.getElementById(id);
	OJ_showTopRecommended (object);
}
function OJ_hideTopRecommendedAni (id){
	if(typeof(OJ_timers['id'])=='number') window.clearTimeout(OJ_timers['id']);
	object=document.getElementById(id);
	OJ_hideTopRecommended (object);
}
/************************ DELAYS **************************************/
var activeThumbnail=false;
var activeTooltip=false;
var activeTooltipTimer=false;
var activeTooltipHideTimer=false;
var mousex = false;
var mousey = false;

var pathnaviElement=false;
var pathnaviTimer=false;
var pathnaviHideTimer=false;

function initDelays(){
	var tooltips=document.getElementsByName('tooltip');
	for ( var i = 0; i < tooltips.length; i++) { //init events for thumbnails
		tooltips[i].onmousemove=showTooltip;
		tooltips[i].onmouseout=hideTooltip;
	}
	var reminders=document.getElementsByName('reminder');
	for ( var i = 0; i < reminders.length; i++) { //init events for thumbnails
		
		reminders[i].id='reminder_'+i;
//		jp('id:'+reminders[i].id);
//		if (navigator.appCodeName == "Mozilla"){
			reminders[i].onmouseover=hideReminder;
//		}else reminders[i].onmouseover=hideReminder;
		window.setTimeout('showReminder("reminder_'+i+'")',4000+200*i);
	}
	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+document.documentElement.scrollLeft;
	mousey = event.pageY || event.clientY+document.documentElement.scrollTop;
}
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(e){
	if (typeof(e)=='string') var target=document.getElementById(e);
	else {
		var event = window.event || e;
		var target = event.srcElement || event.target;
		while (target.className!='reminder')target=target.parentNode;
	}
	target.style.display="none";	
}

/************************ TOOLTIPS **************************************/
function showTooltip(e){
	var event = window.event || e;
	activeThumbnail = event.srcElement || event.target;
	while(activeThumbnail.tagName!='A')activeThumbnail=activeThumbnail.parentNode;
	if ( activeTooltip && (activeTooltip != activeThumbnail.nextSibling ) ) { 
		activeTooltip.style.display='none';
		activeTooltip = activeThumbnail.nextSibling;
		setTooltip();
	}
	activeTooltip = activeThumbnail.nextSibling;
	if (activeTooltip.style.display=='block') setTooltip();
	else if(!activeTooltipTimer) activeTooltipTimer=window.setTimeout("setTooltip(true);",500);
	if(activeTooltipHideTimer) { 
		window.clearTimeout(activeTooltipHideTimer);
		activeTooltipHideTimer = false;
		//setTooltip();
		}
}
function setTooltip(init){
	if(activeTooltip || init){
		activeTooltip.style.left=(mousex-getPos(activeThumbnail.offsetParent).left-223)+'px';
		activeTooltip.style.top=(mousey-getPos(activeThumbnail.offsetParent).top-150)+'px';
		activeTooltip.style.display='block';
	}
}
function hideTooltip(e){
	var event = window.event || e;
	var target = event.srcElement || event.target;
	if(!activeTooltipHideTimer) activeTooltipHideTimer=window.setTimeout("hideActiveTooltip()",50);
}
function hideActiveTooltip(){
	if(activeTooltip){
		activeTooltip.style.display='none';
		window.clearTimeout(activeTooltipTimer);
		activeTooltipTimer=false;
		activeTooltip=false;
		activeTooltipHideTimer=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;
}
/**************************** 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){
	var text ='';
	if (typeof(obj)=='object'){
		for(var key in obj) {
			if (key!='channel'){
				if (obj[key]&&(typeof(obj[key])!='function')) text+=key+" => "+obj[key]+"\n";
			}
//			if (obj[key]) text+=key+" => "+obj[key]+"\n";
		}
		jp(text);
	}
}

/************************ Search **************************************/

function is_search(){
	if (document.forms[0].search.value=='')return;
	else document.forms[0].submit();
}

/************************ Image **************************************/

function image_change (url,id) {
	 document.getElementById(id).src = url;
}