if (!window.XMLHttpRequest) { top.window.location = '/ohnoitsie'; }
if ( window.location.href.search('www.lodingo') != -1 ) { window.location = window.location.href.replace('www.lodingo','lodingo'); }

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
return null;
}

function setCookie(name, value, expires) {
	if (!expires) expires = new Date(); 
	document.cookie = name + "=" + escape(value) + ";expires=" + expires.toGMTString() + ";path=/" + ";domain=lodingo.com";
}

// See also modules.js for additional definitions
var currentCookie = '';
currentCookie = document.cookie;
currentTab = getCookie("targetTab");
if (currentTab == null) {currentTab = 'Home';}
var scrnchk = getCookie("scrnchk");
if (scrnchk == null) {
	if ( window.screen.height < 768 ) { alert('Your screen is currently set to ' + window.screen.width + ' x ' + window.screen.height + '. Note that this is less than the 1024 x 768 resolution that our site requires for some functions to work correctly.\n\nYou may need to increase your screen resolution to access some site functions.'); }
	var expdate = new Date(); // pre-set to the current time and date
	expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24); // add a day to it 
	setCookie('scrnchk',1,expdate);
}
var tabBackgroundImage = '/images/design-09/categorie_button.png';
var targetTab = '';
var workingPane = '';
var tabWidth = 792;
var iteration = tabWidth / 22;
var allPageTags = new Array();
var allPanes = new Array();
var allTabs = new Array();
var allSlides = new Array();
var allVids = new Array();
var allScrolls = new Array();
var panesCount = 0;
var slideCount = 0;
var vidCount = 0;
var scrollCount = 0;
var scrollShowing = 1;
var scrollPos = 0;
var scrollTarget = 0;
var scrollWidth = 280;
var isScrolling = false;
var thumbCount = 0;
var thumbPos = 0;
var thumbTarget = 0;
var thumbWidth = 112;
var lmargin = 0;
var currentZone = 0;
var currentCountry = 0;
var currentCity = 0;
var targetCatalog = '';
var cookieLoc = '';

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

function gotoTab(startTab,endTab) {
	document.getElementById('debug').innerHTML = 'GotoTab';
	if (startTab != endTab) {
		for (var x in allPanes) {
			document.getElementById('debug').innerHTML = 'Hiding Previous';
			document.getElementById(allPanes[x]).style.visibility = 'hidden';
			document.getElementById(allPanes[x] + '-feature').style.visibility = 'hidden';
			document.getElementById(allPanes[x] + '-tab').style.background = 'none';
		}
		currentTab = endTab;
		document.getElementById('debug').innerHTML = 'Enabling New';
		document.getElementById(currentTab).style.visibility = 'visible';
		document.getElementById(currentTab + '-feature').style.visibility = 'visible';
	}
	document.getElementById('debug').innerHTML = 'Setting Tab';
	document.getElementById(currentTab + '-tab').style.background = 'url(' + tabBackgroundImage + ') top left no-repeat';
}

function initPanes() {
	document.getElementById('debug').innerHTML = 'InitPanes';
	flowplayer("player0","/Videos/flowplayer-3.1.1.swf",{clip: {url: "/Videos/tennissample4flash.flv", autoPlay: false, autoBuffering: true}});
	flowplayer("player1","/Videos/flowplayer-3.1.1.swf",{clip: {url: "/Videos/basketballsample4flash.flv", autoPlay: false, autoBuffering: true}});
	flowplayer("player2","/Videos/flowplayer-3.1.1.swf",{clip: {url: "/Videos/ThinkDifferent.flv", autoPlay: false, autoBuffering: true}});
	allPageTags = document.getElementsByTagName("*"); 
	for (var i=0; i<allPageTags.length; i++) { 
		if (allPageTags[i].className == 'cattext') { 
			allPanes[panesCount] = allPageTags[i].id;
			panesCount++;
		}
		if (allPageTags[i].className == 'slider') { 
			allSlides[slideCount] = allPageTags[i].id;
			slideCount++;
		}
		if (allPageTags[i].className == 'player') { 
			allVids[vidCount] = allPageTags[i].id;
			vidCount++;
		}
		if (allPageTags[i].className == 'scrollitem') { 
			scrollCount++;
		}
		if (allPageTags[i].className == 'prodimg') { 
			thumbCount++;
			if (thumbCount != 1) {
				document.getElementById('thumbImage' + thumbCount).src = allPageTags[i].src;
			}
		}
	}
	gotoTab('Home',currentTab);
	// setPageHeight();
	document.getElementById('panesCover').style.visibility = 'hidden';
}

function fadeIn(thisPane) {
	document.getElementById(thisPane).style.visibility = 'visible';
	fadelevel = 0;
	workingPane = thisPane;
	fadePaneIn();
}

function fadePaneIn() {
	fadelevel = fadelevel + 0.1;
	var alphalevel = fadelevel * 100;
	document.getElementById(workingPane).style.filter = 'alpha(opacity=' + alphalevel + ')';
	document.getElementById(workingPane).style.opacity = fadelevel;
	if (fadelevel < 1) {
		setTimeout('fadePaneIn()',1);
	} else {
		document.getElementById(workingPane).style.filter = 'alpha(opacity=100)';
		document.getElementById(workingPane).style.opacity = '1.0';
	}
}

function fadeOut(thisPane) {
	fadelevel = 1;
	workingPane = thisPane;
	fadePaneOut();
}

function fadePaneOut() {
	fadelevel = fadelevel - 0.1;
	var alphalevel = fadelevel * 100;
	document.getElementById(workingPane).style.filter = 'alpha(opacity=' + alphalevel + ')';
	document.getElementById(workingPane).style.opacity = fadelevel;
	if (fadelevel > 0) {
		setTimeout('fadePaneOut()',1);
	} else {
		document.getElementById(workingPane).style.filter = 'alpha(opacity=0)';
		document.getElementById(workingPane).style.opacity = '0.0';
		document.getElementById(workingPane).style.visibility = 'hidden';
	}
}

function fadeTo(thisTab) {
	document.getElementById('debug').innerHTML = 'FadeTo';
	if (currentTab == thisTab) {exit;}
	fadeIn('cattextcover');
	gotoTab(currentTab,thisTab);
	fadeOut('cattextcover');
}

function switchTo(hoverTab) {
	document.getElementById('debug').innerHTML = 'SwitchTo';
	fadeTo(hoverTab);
}

function showSelected() {
	var expdate = new Date(); // pre-set to the current time and date
	expdate.setTime(expdate.getTime() + 1000 * 30); // add 60 seconds to it 
	cookieLoc = String(currentZone + '.' + currentCountry + '.' + currentCity + '.');
	setCookie("currentLoc",cookieLoc,expdate);
	window.location = targetCatalog;
}

function showZone(tZone,tURL) {
	currentZone = parseInt(tZone);
	currentCountry = 0;
	currentCity = 0;
	targetCatalog = tURL;
	showSelected();
}

function showScroller(thisDiv) {
	for (var x in allSlides) {
		animatedcollapse.hide(allSlides[x]);
		document.getElementById(allSlides[x] + '-title').style.backgroundColor = '#f0f0f0';
		document.getElementById(allSlides[x] + '-title').style.color = '#666666';
	}
	animatedcollapse.show(thisDiv);
	document.getElementById(thisDiv + '-title').style.backgroundColor = '#e42246';
	document.getElementById(thisDiv + '-title').style.color = 'white';
}

function showVideo(thisVid) {
	for (var x in allVids) {
		// document.getElementById(allVids[x]).style.height = '0px';
		flowplayer(allVids[x]).stop();
	}
	var vidTop = 0 - (203 * thisVid);
	document.getElementById('playerframe').style.top = vidTop + 'px';
	flowplayer('player' + thisVid).play();
}

function scrollIt() {
	if (scrollTarget < scrollPos) {
		scrollPos = scrollPos - 20;
		thumbPos = thumbPos - 8;
	} else {
		scrollPos = scrollPos + 20;
		thumbPos = thumbPos + 8;
	}
	document.getElementById('scrolldetailframe').style.left = scrollPos + 'px';
	document.getElementById('scrollthumbframe').style.left = thumbPos + 'px';
	if (scrollTarget != scrollPos) {
		isScrolling = true;
		setTimeout('scrollIt()',1);
	} else {
		isScrolling = false;
	}
}

function scrollerLeft() {
	if ((scrollShowing != scrollCount) && !isScrolling) {
		document.getElementById('rightArrow').src = '/images/design-09/icons/16x16/next.png';
		scrollTarget = scrollPos - scrollWidth;
		thumbTarget = thumbPos - thumbWidth;
		scrollIt();
		scrollShowing++;
		// if (scrollShowing == scrollCount) { document.getElementById('leftArrow').src = '/images/design-09/icons/16x16/back-gry.png'; }
		if (scrollShowing == scrollCount) { document.getElementById('leftArrow').src = '/images/spacer1x1.gif'; }
	}
}

function scrollerRight() {
	if ((scrollShowing != 1) && !isScrolling) {
		document.getElementById('leftArrow').src = '/images/design-09/icons/16x16/back.png';
		scrollTarget = scrollPos + scrollWidth;
		thumbTarget = thumbPos + thumbWidth;
		scrollIt();
		scrollShowing--;
		// if (scrollShowing == 1) { document.getElementById('rightArrow').src = '/images/design-09/icons/16x16/next-gry.png'; }
		if (scrollShowing == 1) { document.getElementById('rightArrow').src = '/images/spacer1x1.gif'; }
	}
}

function setPageHeight() {
	var myHeight = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight + document.body.offsetTop;
	document.getElementById('pagefader').style.height = myHeight + 'px';
}


// Start Popup Content modules - used by pop-up overlay - duplicated in modules.js & template-menu-tab.js

function hideDashboard() {
	document.getElementById('dbholder').style.visibility = 'hidden';
	document.getElementById('pagefader').style.visibility = 'hidden';
}

function showDashboard() {
	document.getElementById('dbholder').src = '/clientlogin';
	document.getElementById('pagefader').style.visibility = 'visible';
	document.getElementById('dbholder').style.visibility = 'visible';
}

function hidePopupContent() {
	document.getElementById('dbholder').style.visibility = 'hidden';
	document.getElementById('pagefader').style.visibility = 'hidden'; // Remove this line for module.js
}

function showPopupContent(contentTitle,contentURL) {
	// document.getElementById('gifloader').innerHTML = '<strong>' + contentTitle + '</strong>';
	document.getElementById('dbholder').src = '/overlay.html?fetch=' + contentURL + '&title=' + escape(contentTitle);
	// setPageHeight();
	document.getElementById('pagefader').style.visibility = 'visible'; // Remove this line for module.js
	document.getElementById('dbholder').style.visibility = 'visible';
}

// End Popup Content modules

// window.onresize = setPageHeight;

if (window.attachEvent) window.attachEvent("onload", sfHover);
