	$(function(){
		if($('body').height() > 1000) $('#back_to_top').parent().show()
	})
	
	function mainNav() {
		this.innerSection = 0;
		this.currentSection = 0;
	}

	mainNav.prototype.menuOver = function(id, state) {
		if(id != this.currentSection) {
			which = document.getElementById("menu"+id);
			this.clearSides();
			if(state==1){
				l =  (id == 1) ? "b" : "";
				document.getElementById("menu"+id+"L").src = "img/menu_left" + l + ".jpg";
				if(this.innerSection != id) { rollOver(which); }
				document.getElementById("menu"+(id+1)+"L").src = "img/menu_right.jpg";
			} else {
				if(this.innerSection != id) { rollOut(which); }
			}
		}
	}
	
	mainNav.prototype.clearSides = function(){
		for(i=1; i < 7; i++){
			if(i != this.currentSection) {
				off = (i==1) ? "img/trans.gif" : "img/menu_off.gif"
				document.getElementById("menu" + i + "L").src = off;
				if( i < 6) {
					document.getElementById("menu" + (i + 1) + "L").src = "img/menu_off.jpg";
				}
			}
		}
		if (this.currentSection != 0) {
			l =  (this.currentSection == 1) ? "b" : "";
			document.getElementById("menu" + this.currentSection + "L").src = "img/menu_left" + l +".jpg";
			document.getElementById("menu" + (this.currentSection + 1) + "L").src = "img/menu_right.jpg";
		}
	}
	
	mainNav.prototype.showSection = function(which){
		if(this.currentSection != which){
			this.hideLastSection();
			var left = document.getElementById("frameSideLeft")
			if (left != null) left.style.height = "389px";
			var right = document.getElementById("frameSideRight")
			if (right != null) right.style.height = "389px";	
		}
		document.getElementById("MenuSection" + which).style.display = "block";
		this.currentSection = which;
		this.clearSides();
		if(brandS) { brandS.scrollerObj.refresh(); }
	}

	mainNav.prototype.hideLastSection = function() {
		if (this.currentSection != 0) {
			if(this.innerSection != this.currentSection) {
				rollOut(document.getElementById("menu" + this.currentSection));
			}
			document.getElementById("MenuSection" + this.currentSection).style.display = "none";
		}
	
		var left = document.getElementById("frameSideLeft")
		if (left != null) left.style.height = "93px";
		
		var right = document.getElementById("frameSideRight")
		if (right != null) right.style.height = "93px";

		this.currentSection = 0;
		this.clearSides();
		
		if(this.innerSection != 0) {
			this.inSection(this.innerSection);
		}
	}

	mainNav.prototype.inSection = function(which){
		this.innerSection = which;
		rollOver(document.getElementById("menu" + which));
		this.currentSection = 0;
		this.clearSides();
		this.currentSection = which;
	}

	function findBrand(x,y) {
		d = document.getElementById("brandBottles");
		if(document.all) {
			b = document.documentElement;
		} else {
			b = document.body;
		}
		divX = d.offsetLeft - b.scrollLeft;
		templateX = (b.clientWidth - 975) / 2;
		if (templateX < 0) { templateX =0; }
		cliX = (divX + templateX);
		relX = (x - cliX - 20);
		bx = relX + d.scrollLeft;
		brandS.selectBrand(Math.min(Math.floor(bx / 50),13));
	}

	function checkBrandRollOver(x,y) {
		d = document.getElementById("brandBottles");
		if(document.all) {
			b = document.documentElement;
		} else {
			b = document.body;
		}
		divX = d.offsetLeft - b.scrollLeft;
		templateX = (b.clientWidth - 975) / 2;
		if (templateX < 0) { templateX =0; }
		cliX = (divX + templateX);
		relX = (x - cliX - 20);
		bx = relX + d.scrollLeft;
		
		targ = Math.floor(bx / 50);
		if(targ >=0 && targ < brandS.brandImage.length) {
			i = document.getElementById("bott"+targ);
			if(i.src.indexOf("_of") > 0) {
				lastRO=(i);
				rollOver(i);
			}
			for (j=0; j < brandS.brandImage.length; j++){
				if(j != targ) {
					if(document.getElementById("bott"+j).src.indexOf("_ov") > 0) {
						rollOut(document.getElementById("bott"+j));
					}
				}
			}
		}
	}

	function communityObj(me) {
		this.me = me;
		this.selectedCommunity = null;
		
		this.player= null;
		
		this.types = new Array();
		this.sources = new Array();
		this.thumbnails = new Array();
	}

	communityObj.prototype.init = function () {
		// write community thumbnails
		this.player= document.getElementById("communityPlayer");
		var h = ''
		for (id in this.thumbnails){
			h+= '<A href="javascript:community.show('+id+');"><img src="' + this.thumbnails[id]+ '" /></A>';
		}
			/*
		h = '<A href="javascript:community.show(0);"><img src="' + this.thumbnails[0]+ '" /></A>';
		h+= '<A href="javascript:community.show(1);"><img src="' + this.thumbnails[1]+ '" /></A>';
		h+= '<A href="javascript:community.show(2);"><img src="' + this.thumbnails[2]+ '" /></A>';*/
		document.getElementById("sectionCommunityThumbnails").innerHTML = h;	
		this.show(0);
	}
	
	communityObj.prototype.addBlock = function(type, source, thumbnail){
		this.types.push(type);
		this.sources.push(source);
		this.thumbnails.push(thumbnail);
	}
	
	communityObj.prototype.show = function(which){ 
		document.getElementById("communityText"+(this.selectedCommunity+1)).style.display = "none";
		if(this.types[which] == "video") {
			this.writeVid(which);
		} else {
			this.writeImage(which);
		}
		this.selectedCommunity = which;
		document.getElementById("communityText"+(this.selectedCommunity+1)).style.display = "block";
	}
	
	communityObj.prototype.writeVid = function(which) {
		var so = new SWFObject('mediaplayer.swf','mpl','341','209','7');
		so.addParam('allowfullscreen','true');
		so.addVariable('file', this.sources[which]);
		so.addVariable('image', this.thumbnails[which]);
		so.addVariable('width','341');
		so.addVariable('height','209');
		so.addVariable('backcolor','0xFFFFFF');
		so.addVariable('autostart','false');
		so.write('communityPlayer');
	}
	
	communityObj.prototype.writeImage = function(which) {
		 this.player.innerHTML = '<img src="'+this.sources[which]+'" width="341" height="209" />';
	}

	function rollOver(which){ which.src = which.src.replace("_of","_ov"); }
	function rollOut(which){ which.src = which.src.replace("_ov","_of"); }
	
	function goto(which) {
		top.document.location.href = which;	
	}
	function openNewWindow(URLtoOpen, windowName, windowFeatures)
	{
	 newWindow=window.open(URLtoOpen, windowName, windowFeatures);
	 newWindow.focus();
	}