// JavaScript Document
window.addEvent("load", function(){
	$$("#scroller a").each(function(e, i) {
		var d = document;
		d.maxScroll = $("content").getSize().scrollSize.y-$("content").getSize().size.y;
		if (d.maxScroll <= 0) {
			e.setStyle("display", "none");
		}
		d.contentScroll = new Fx.Scroll("content", {
			wait: false,
			duration: d.maxScroll*20,
			transition: Fx.Transitions.linear
		});
		e.addEvent("mouseover", function(event){
			var scroll = $("content").getSize().scroll.y;
			if (e.title == "up") {
				d.contentScroll.options.duration = scroll*13;
				d.contentScroll.toTop();
			} else {
				d.contentScroll.options.duration = (d.maxScroll-scroll)*13;
				d.contentScroll.toBottom();
			}
		});
		e.addEvent("mouseout", function(event){
			d.contentScroll.stop();
		});
	});

	$$("#scrollerWine a").each(function(e, i) {
		var d = document;
		d.maxScroll = $("contentWine").getSize().scrollSize.y-$("contentWine").getSize().size.y;
		if (d.maxScroll <= 0) {
			e.setStyle("display", "none");
		}
		d.contentScroll = new Fx.Scroll("contentWine", {
			wait: false,
			duration: d.maxScroll*20,
			transition: Fx.Transitions.linear
		});
		e.addEvent("mouseover", function(event){
			var scroll = $("contentWine").getSize().scroll.y;
			if (e.title == "up") {
				d.contentScroll.options.duration = scroll*13;
				d.contentScroll.toTop();
			} else {
				d.contentScroll.options.duration = (d.maxScroll-scroll)*13;
				d.contentScroll.toBottom();
			}
		});
		e.addEvent("mouseout", function(event){
			d.contentScroll.stop();
		});
		/*e.addEvent("click", function(event){
			var alertStr = "";
			alertStr += "scrollSize = "+$("contentWine").getSize().scrollSize.y+"\n";
			alertStr += "size = "+$("contentWine").getSize().size.y+"\n";
			alertStr += "maxScroll = "+d.maxScroll+"\n";
			alertStr += "scroll = "+$("contentWine").getSize().scroll.y+"\n";
			alert(alertStr);
		});*/
	});
/*	
	parent.changeTitle(sSectionId);
	if (DropDownMenu && $('mainnav'))
	{
		var menu = new DropDownMenu($('mainnav'));
	}
	*/
	//
	//
	//
	if (!document.soBody) showContent(1);
	
	
	
	fInitSlideShow();
});

var setVisible=function(status){
	$("nextweekFrame").setStyle("visibility",status);
}

var changeTitle = function(pos) {
	if (typeof(flashMovie) == "undefined") return false;
	var myFlash = new flashMovie("headerFlash");
	myFlash.set("oPos",pos);
}
var setIframe = function(h) {
	if ($("homeFrame")) $("homeFrame").setStyle("height", h+"px");
}

var setPage = function(p){
	if ($("homeFrame")) $("homeFrame").setProperty("src", p);
}

/*var setHeader = function(m){
	$("header").setProperty("src", m);
}*/

function AjaxRequestCountry(objid){
	
	$$("a").each(function(i){
					i.removeClass('active');
							}
							);
	$("wine_"+objid).addClass('active');
	
	url = "indexajax.php?nav1=title&id="+objid;
	var TitleAjax = new Ajax(url,
							   {
								   method:'get',
								   update:$('h2title')
							   }
							   );
	TitleAjax.request();
	
	url = "indexajax.php?nav1=country&id="+objid;
	var MyAjax = new Ajax(url,
						  {
							  method:'get',
							  update:$('blkcountry')
						  }
						  ); 
	MyAjax.request();
		
	url = "indexajax.php?nav1=winecontent&id="+objid;
	var ContentAjax = new Ajax(url,
							   {
								   method:'get',
								   update:$('contentWine')
							   }
							   );
	ContentAjax.request();	
		
}

function AjaxRequestContent(objid,parentid){
	
	$$("a").each(function(i){
					i.removeClass('active');
							}
							);
	$("wine_"+parentid).addClass('active');
	$("country_"+objid).addClass('active');
	
	url = "indexajax.php?nav1=content&id="+objid;
	var ContentAjax = new Ajax(url,
							   {
								   method:'get',
								   update:$('contentWine')
							   }
							   );
	ContentAjax.request();
}

function AjaxRequestMenusListItem(objid){
	
	$$("a").each(function(i){
					i.removeClass('active');
							}
							);
	$("menus_"+objid).addClass('active');
	
	url = "indexajax.php?nav1=title&id="+objid;
	var TitleAjax = new Ajax(url,
							   {
								   method:'get',
								   update:$('h2title')
							   }
							   );
	TitleAjax.request();
	
	url = "indexajax.php?nav1=menuscontent&id="+objid;
	var ContentAjax = new Ajax(url,
							   {
								   method:'get',
								   update:$('contentWine'),
								   onComplete: function(){
									   if ($('contentWine')) $('contentWine').scrollTop = 0;
								   }
							   }
							   
							   );
	ContentAjax.request();
}

function f_show(){
	if (typeof(flashMovie) == "undefined") return false;
	var myFlash = new flashMovie("headerFlash");
	myFlash.set("oStart",true);
}
function f_headerStop(){
	if (typeof(flashMovie) == "undefined") return false;
	var myFlashHeader = new flashMovie("headerFlash");
	if (myFlashHeader) myFlashHeader.set("oHeader",true);
}
function f_Res(){
	if (typeof(flashMovie) == "undefined") return false;
	var myFlashRes = new flashMovie("headerFlash");
	if (myFlashRes) myFlashRes.set("oHeader","res");
}

//
//
//
function showContent(val){
	if ($("header")) $("header").setOpacity(val);
	if ($("lang")) $("lang").setOpacity(val);
	if ($("footer")) $("footer").setOpacity(val);
}





function fInitSlideShow(){
	var aPlace = $$("div.photoList");
	if (aPlace.length == 0) return false;
	var aList = aPlace[0].getElements("a");
	
	if (aList.length <= 9) {
		$("scrollerPhoto").setStyle("visibility", "hidden");
		return;
	}
	var iIndex = 0;
	var oldImage = null;
	$("photoTotal").setHTML((iIndex+1)+"/"+aList.length);
	aList.each(function(el, i){
		el.addEvent("click", function(e){
			new Event(e).stop();
			loadImgIndex(i);
		});
	});
	//
	if ($("slideBtnLeft")) {
		$("slideBtnLeft").addEvent("click", function(e){
			new Event(e).stop();
			if (iIndex == 0) return;
			iIndex--;
			loadImgIndex(iIndex);
		});
	}
	if ($("slideBtnRight")) {
		$("slideBtnRight").addEvent("click", function(e){
			new Event(e).stop();
			if (iIndex == aList.length-1) return;
			iIndex++;
			loadImgIndex(iIndex);
		});
	}
	//
	function loadImgIndex(i) {
		if (!$(aList[i]).getFirst()) return;
		var src = $(aList[i]).getFirst().src.split("?");
		if (src.length != 2) return;
		//
		if (oldImage) {oldImage.setStyle("border-color", "")}
		if ($("extraPhoto")) $("extraPhoto").getFirst().src = src[1];
		//
		$(aList[i]).getParent().setStyle("border-color", "#fff");
		oldImage = $(aList[i]).getParent();
		iIndex = i;
		//
		$("photoTotal").setHTML((iIndex+1)+"/"+aList.length);
		//
		if (iIndex % 9 == 0) {
			var fxScroll = new Fx.Scroll(aPlace[0]);
			fxScroll.toElement(aList[i]);
		}
		if (iIndex % 9 == 8 && iIndex != 0) {
			var fxScroll = new Fx.Scroll(aPlace[0]);
			fxScroll.toElement(aList[i-8]);
		}
	}
	loadImgIndex(0);
}