/*
Javascript function HASHes
copyright codemountain 2007 and gotire 2007


gotire

*/

/*****************************************************************/
var paginate = {

	init:function(elType, elID, textPage, pageDiv, linesPage){
		if(elType=="table"){
				contentCopy = $$("#"+elID+" tbody").first();
		}
		if(elType=="list"){
				contentCopy = $(elID);
		}
		//console.log(elType+" "+elID+" "+textPage+" "+pageDiv+" "+linesPage);
		menu_section_id = elID;
		linesCopy = contentCopy.childElements();
		noLines = linesCopy.length;
		linesPerPage = linesPage;
		noPages = Math.ceil(noLines/linesPerPage);
		navWord = textPage;
		divNav = pageDiv;
		
		if(noLines > linesPerPage){
			this.hideLines();
			this.buildNav();
			this.showLines(0,(linesPerPage-1),firstPage);
		}
	},
	
	hideLines:function(){
		linesCopy.invoke('hide');
	},
	
	showLines:function(from,to,id){
		this.hideLines();
		//console.log(linesCopy);
		for(i = from; i <= to;i++){
			//console.log("i="+i);
			linesCopy[i].show();	
		}	
		this.activePage(id);
	},
	
	buildNav:function(){
		navStr = "";
		navStr = navWord;
		for(i=1; i <= noPages;i++){
			from = (i-1)*(linesPerPage);
			to = from+(linesPerPage-1);
			if(to>noLines){to=noLines-1}
			//console.log("TO:"+to);
			navStr += "  <span class='pageNav' onclick='paginate.showLines("+from+","+to+",this.id)' id='"+menu_section_id+"_page_"+i+"'>"+i+"</span>";
		
		}
		$(divNav).update(navStr);
		
		allPageNav = $$("#"+divNav+" .pageNav");
		firstPage = allPageNav.first().id;
	},
	
	activePage:function(id){
		console.log("activePage:"+id);
		allPageNav.each(function(e){
			e.removeClassName('active');
		});
		$(id).addClassName('active');
	}

}

var slideshow = {

	init:function(){
		allLinks = $$('div.thumbnav ul li');
		allThumbs = $$('div.thumbnav ul li img');
		allLarge = $$('div.img_container img');
		allLinks.each(function(e){
			e.observe('click',function(evt) {slideshow.clickshow(this.id) });					   
							   
		});
		this.showFirst();
	
		start_slideshow(1, 6, 3000);
		
	},
	
	clickshow:function(id){
		if(slideplayer1) {clearTimeout(slideplayer1);}
		if(slideplayer2) {clearTimeout(slideplayer2);}
		allLarge.invoke('hide');
		this.show(id);	
	},
	
	show:function(id){
		//console.log("id:"+id);
		allLarge.invoke('hide');
		Effect.Appear("slideshow"+id);
		this.activeMenu(id);
	},
	
	activeMenu:function(id){
		//console.log("activemenu : "+id);
		allThumbs.each(function(e){
			e.removeClassName('active');
		});
		$$("#"+id+" img").first().addClassName('active');
	},

	showFirst:function(){
		//find first menu a href id to run sections.show on first link
		var menuId = allLinks.first().id;
		this.show(menuId);
	}
	
}



var restomenu = {

	init:function(elType,linesInMenu){
		allLinks = $$('ul.menuresto1 li');
		allSections = $$('div.sections');
		noLinestoShow = linesInMenu;
		typeElement = elType;
		allLinks.each(function(e){
			e.observe('click',function(evt) {restomenu.show(this.id) });					   
							   
		});
		this.showFirst();
	

		
	},
	
	show:function(id){
		//console.log("id:"+id);
		allSections.invoke('hide');
		sectionId = id.split("_")[1];
		
		//paginate menu if required;
		
		paginate.init(typeElement,"menu_section_"+sectionId,"Page ","pages"+sectionId,noLinestoShow);
		
		Effect.Appear("section_"+sectionId);
		this.activeMenu(id);
	},
	
	activeMenu:function(id){
		//console.log("activemenu : "+id);
		allLinks.each(function(e){
			e.removeClassName('active');
		});
		$(id).addClassName('active');
	},

	showFirst:function(){
		//find first menu a href id to run sections.show on first link
		var menuId = allLinks.first().id;
		this.show(menuId);
	}
	
}

var wines = {

	init:function(){
		allLabelLinks = $$('.wineLabel');
		allLabels = $$('img.labels');

		allLabelLinks.each(function(e){
			e.observe('click',function(evt) {wines.show(this.id) });					   
							   
		});
		$('close_label').observe('click',function(evt) {wines.hideContainer() });	
		
	},
	
	show:function(id){
		//console.log("id:"+id);
		allLabels.invoke('hide');
		$('labelImg').show();//this is the container
		
		sectionId = id.split("_")[1];
		Effect.Appear("label_"+sectionId);
		
		this.activeMenu(id);
	},
	
	activeMenu:function(id){
		//console.log("activemenu : "+id);
		allLabelLinks.each(function(e){
			e.src="../img/icn_label_off.png";
		});
		$(id).src="../img/icn_label_on.png";
	},
	
	hideContainer:function(){
		allLabels.invoke('hide');
		$('labelImg').hide();
		allLabelLinks.each(function(e){
			e.src="../img/icn_label_off.png";
		});
	
	}	
}

/*****************************************************************/
    function start_slideshow(start_frame, end_frame, delay) {
    setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
                        
function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        Effect.Fade('slideshow' + frame);
        if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
				//console.log("frame :"+frame);
        //setTimeout("Effect.Appear('slideshow" + frame + "');", 2000);
        slideplayer2 =  setTimeout("Effect.Appear('slideshow" + frame + "');slideshow.activeMenu("+frame+");", 1000);
        slideplayer1 = setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 3000);
    })
}


/*****************************************************************/



function clickclear(thisfield, defaulttext) {
		if (thisfield.value == defaulttext) {
		thisfield.value = "";
		}
		}
		
		function clickrecall(thisfield, defaulttext) {
		if (thisfield.value == "") {
		thisfield.value = defaulttext;
		}
}


