var ALL_BRANDS = -1;
var ALL_CATEGORIES = -1;
var ALL_COLORS = -1;
var timer = null;
var t = 0;

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function setBodyMargin() {
	var clientHeight = document.documentElement.clientHeight;
  var main = document.getElementById('main');
  var mainHeight = main.offsetHeight + 33;
  if (clientHeight > mainHeight) {
		var topSpace = ((clientHeight - mainHeight) / 2);
		if (IE) {
			main.style.marginTop = (topSpace + 30) + "px";
		} else {
			main.style.marginTop = (topSpace) + "px";
		}
  }
}

function showAfterAddBasket() {
  clearInterval(timer);
  timer = null;
  var basket = document.getElementById("basket-thumb");
  var main = document.getElementById("main");

  var x = main.offsetLeft + main.offsetWidth;
  basket.style.left = x + "px";
  basket.style.visibility = "visible";
  t = 0;
  if (!timer) {
    timer = window.setInterval(timerTickBoth, 18.2);
  }
}

function showBasketThumb() {
  clearInterval(timer);
  timer = null;
  var basket = document.getElementById("basket-thumb");
  var main = document.getElementById("main");

  var x = main.offsetLeft + main.offsetWidth;
  basket.style.left = x + "px";
  basket.style.visibility = "visible";
  if (!timer) {
    timer = window.setInterval(timerTickUp, 18.2);
  }
}

function timerTickUp() {
  var basket = document.getElementById("basket-thumb-content");
  if (basket.offsetLeft < -10) {
    var left = basket.offsetLeft;
    left += 10;
    basket.style.left = left + "px";
  } else {
    clearInterval(timer);
    timer = null;
  }
}

function timerTickDown() {
  var basket = document.getElementById("basket-thumb-content");
  if (basket.offsetLeft > -80) {
    var left = basket.offsetLeft;
    left -= 10;
    basket.style.left = left + "px";
  } else {
    clearInterval(timer);
    timer = null;
  }
}

function timerTickBoth() {
  var SHOW_TIME = 50;
  var HIDE_TIME = 300;
  var END_TIME = 500;
  var basket = document.getElementById("basket-thumb-content");
  t++;

  if (basket.offsetLeft < -10 && t >= SHOW_TIME && t < HIDE_TIME) {
    var left = basket.offsetLeft;
    left += 10;
    basket.style.left = left + "px";
  } else if (basket.offsetLeft > -80 && t >= HIDE_TIME && t < END_TIME) {
    var left = basket.offsetLeft;
    left -= 10;
    basket.style.left = left + "px";
  } else if (t >= END_TIME) {
    clearInterval(timer);
    timer = null;
  }
}

function hideBasketThumb() {
  clearInterval(timer);
  timer = null;
  var basket = document.getElementById("basket-thumb");
  if (!timer) {
    timer = window.setInterval(timerTickDown, 18.2);
  }
}

function setScrollPos(scrollPos) {
  var scrollPosInput = document.getElementById("scroll_pos");
  scrollPosInput.value = scrollPos;
}

function scrollBarLink(base, params) {
  var scrollPos = document.getElementById("scroll_pos").value;

  var link = base + "?scroll_pos=" + scrollPos;
  if (params != "") {
    link += "&" + params;
  }
  window.location.href = link;
  return false;
}

function link(url, gender) {
  var separator = (url.indexOf('?') > -1) ? '&' : '?';
  self.location.href = url + separator + 'gender=' + gender;
}

var SMALL_PLUS_SIZE = 20;
var BIG_PLUS_SIZE = 26;
var PLUS_GROWTH_SPEED = 2;
var plusGrowth = 1;

function pulsePlus() {
  window.setInterval(plusTimerTick, 100);
}

function plusTimerTick() {
  var plusImage = $("more-info-plus");
  if (plusImage.width > BIG_PLUS_SIZE || plusImage.width < SMALL_PLUS_SIZE) {
    plusGrowth = plusGrowth*(-1);
  }
  plusImage.width = plusImage.height += plusGrowth * PLUS_GROWTH_SPEED;
  var margin = plusImage.parentNode.offsetWidth - (plusImage.offsetLeft + plusImage.offsetWidth) - (plusGrowth * (PLUS_GROWTH_SPEED/2));
  plusImage.setStyle({bottom: margin + "px", right: margin + "px"});

}

function setFiltered() {
	if ($("sizes-selection").selectedIndex == 0) {
		$("filtered-input").value="no";
	}
}

function blockEnter(e,obj) {
	if (e.keyCode == 13) {
		obj.form.submit();	
		return false;
		
	}
	return true;
}

function highlightLabel(label, gender) {
	$(label).src = "/img/logos/" + label + "act" + gender + ".gif";
	var listLabel = $("list-" + label);
	if (listLabel != null) {
		//listLabel.style.textDecoration = "underline";	
	}
}

function dehighlightLabel(label, gender) {
	$(label).src = "/img/logos/" + label + "pas.gif";
	var listLabel = $("list-" + label);
	if (listLabel != null) {
		//listLabel.style.textDecoration = "none";	
	}
}

/*
function setCurtain() {
	if ($("curtain") != null) {
		$("curtain").style.top = -$("main").offsetTop +"px";
		$("curtain").style.left = -$("main").offsetLeft +"px";
		$("curtain").style.width = (document.documentElement.clientWidth) + "px"
		$("curtain").style.height = (document.documentElement.clientHeight) + "px"
		$("curtain").style.display = "block"
		$("guidepost").style.display = "block"
	}
}
*/

function setCurtain() {
	if ($("curtain") != null) {
		$("curtain").style.top = -$("main").offsetTop +"px";
		$("curtain").style.left = -$("main").offsetLeft +"px";
		$("curtain").style.width = (document.documentElement.clientWidth) + "px";
//		$("curtain").style.height = (document.documentElement.clientHeight) + "px";
		$("curtain").style.height = (document.body.offsetHeight + 165) + "px";
		$("curtain").style.display = "block";
		
		screenHeight = document.documentElement.clientHeight;
		stripHeight = $("guidepost").getHeight();
		offset = (screenHeight/2)-(stripHeight/2)-30;

		$("guidepost-bck").style.left = -$("main").offsetLeft +"px";
		$("guidepost-bck").style.width = (document.documentElement.clientWidth) + "px";
		$("guidepost-bck").style.display = "block";
		$("guidepost-bck").style.top = (offset) + "px";
		
		$("guidepost").style.display = "block";
		$("guidepost").style.top = (offset-10) + "px";
	}
}

function sitemapShowItems(identifier) {
	if ($(identifier).style.display == "block") {
		$(identifier).style.display = "none";
	} else {
		$(identifier).style.display = "block";
	}
}

function setColumnsHeight() {
	MAIN_STANDARD_HEIGHT = 625;
	MIN_EXTENDER_HEIGHT = 24;
	FACEBOOK_HEIGHT = 50;
	h = document.getElementById('main-center').offsetHeight - MAIN_STANDARD_HEIGHT;
	showFacebook = h + 19 >= MIN_EXTENDER_HEIGHT + FACEBOOK_HEIGHT;
	if ($('facebook') != null) {
		if (showFacebook && $('facebook')) {
			$('facebook').style.display = "block";
		} else {
			$('facebook').style.display = "none";
		}
	}
	
	if (h + 19 >= MIN_EXTENDER_HEIGHT) {
		$('left-extender').style.display = "block";
		$('left-extender-content').style.height = h + 'px';
		if ($('right-extender-content') != undefined) {
			$('right-extender').style.display = "block";
			if (showFacebook) {
				$('right-extender-content').style.height = (h-FACEBOOK_HEIGHT) + 'px';
			} else {
				$('right-extender-content').style.height = h + 'px';
			}
		}
	} else if (h + 19 > 0) {
		$('login-content').style.height = ($('login-content').offsetHeight + h + 19) + 'px';
		if ($('friends-content') != null) {
			$('friends-content').style.height = ($('friends-content').offsetHeight + h + 19) + 'px';
		} 
	}
}

function setVerticalPosition(element, topId, bottomId) {
	top = $(topId).offsetTop + $(topId).offsetHeight;
	bottom = $(bottomId).offsetTop;
	h = ((bottom - top - $(element).offsetHeight)/2) + top;
	diff = 3 + h - $(element).offsetTop;
	$(element).style.position = 'relative';
	$(element).style.top = diff + 'px';
}

function hideDetailSelects() {
	if ($('item-detail-size') != null) {
		$('item-detail-size').style.visibility="hidden";
	}
}

function showDetailSelects() {
	if ($('item-detail-size') != null) {
		$('item-detail-size').style.visibility="visible";
	}
}