if (typeof console === 'undefined') console = {};
if (typeof console.log === 'undefined') console.log = function(){};
$(function() {});

$(document).ready(function() {
//	$('#myCarousel1').jcarousel({});
     $('#nav li').hover(  
         function () {  //show its submenu  
             $('ul', this).slideDown(100);  
   
         },   
         function () {  //hide its submenu  
             $('ul', this).slideUp(100);           
         }  
     );  

	var slideHeight = 315;	
	var curImg = 1;
	var curSlide = 1;
	$(".galleryNav .thumbs H3").hide();
//	$(".galleryBunch").hide();
	var str = $("#galleryCombo option:first-child").attr("value");
	$(".gallery"+str).show();	
	var firstImgUrl = $(".gallery"+str+" A:first-child IMG").attr("src");
	if(firstImgUrl){
		var fileName = firstImgUrl.substring(firstImgUrl.lastIndexOf("/")+1,firstImgUrl.length)
		var filePath = firstImgUrl.substring(0,firstImgUrl.lastIndexOf("/"));
			newFilePath = filePath.substring(0,filePath.lastIndexOf("/")+1);
		if (firstImgUrl){
			$(".img IMG").attr("src",newFilePath+fileName); 
//			$(".img IMG").attr("src",newFilePath+fileName); // stupid ie6
//			$(".img imgCanvas").html('<img width="100" height="100" title="" alt="" src="'+newFilePath+fileName+'" style="margin-top: 0px;">');
			$(".img IMG").css({"width":"auto", "height":"auto"}); 
			$(".img .description").html($(".gallery"+str+" A:first-child IMG").attr("alt")); 
		}
		var maxImg = $(".thumbs A:visible").length;
		var maxSlide = Math.ceil(maxImg/15);
		if(maxSlide>1){
			$("#nextSlide").addClass("on");
			$(".thumbs").css("height",slideHeight*maxSlide+"px");
		} else{
			$(".thumbs").css("height",slideHeight+"px");
		}
		if(maxSlide>1) $("#nextSlide").addClass("on");
	}
	$("#galleryCombo").change(function () {
		$(".img IMG").attr("src", "img/loading.gif");
		$(".img IMG").css({"margin-top":"180px"}); 
//		alert("dd")
		str = $(this).attr("value");
		newImgContent = "";
//		newImgContent += "<h3>"+poleTyVole[str][1]+"</h3>";
		newImgContent += "<p class=\"galleryBunch gallery"+poleTyVole[str][0]+"\">";
		for(i=2;i<poleTyVole[str].length-1;i++){ // poleTyVole[str].length-1 = maxImg
			newImgContent += '<a href="#"><img src="'+poleTyVole[str][i][0]+'" width="58" height="58" alt="'+poleTyVole[str][i][1]+'" title="'+poleTyVole[str][i][1]+'" /></a>';
		}
		newImgContent += "</p>";
		$(".dynamicImgContent").html(newImgContent);
		curSlide = 1; curImg = 1;
		maxImg = $(".thumbs A:visible").length;
		maxSlide = Math.ceil(maxImg/15);
		if(maxSlide>1){
			$("#nextSlide").addClass("on");
			$(".thumbs").css("height",slideHeight*maxSlide+"px");
		} else {
			$("#nextSlide").removeClass("on");
			$(".thumbs").css("height",slideHeight+"px");
		}
		$(".thumbs").animate({top:0},400);
		/* reset */
		if(maxImg>1){
			$("#nextImg").addClass("on");
		}
		$("#prevSlide").removeClass("on");
		$("#prevImg").removeClass("on");
		firstImgUrl = $(".galleryBunch A:first-child IMG").attr("src");
/*		fileName = firstImgUrl.substring(firstImgUrl.lastIndexOf("/")+1,firstImgUrl.lastIndexOf("-150x150.jpg"))+".jpg";
		filePath = firstImgUrl.substring(0,firstImgUrl.lastIndexOf("/")+1);
		if (firstImgUrl){
			$(".img IMG").attr("src", filePath+fileName);
		}*/
		var fileName = firstImgUrl.substring(firstImgUrl.lastIndexOf("/")+1,firstImgUrl.length)
		var filePath = firstImgUrl.substring(0,firstImgUrl.lastIndexOf("/"));
			newFilePath = filePath.substring(0,filePath.lastIndexOf("/")+1);
		if (firstImgUrl){
//			alert(newFilePath+fileName); 
			$(".img IMG").attr("src",newFilePath+fileName);
			if ($.browser.msie && $.browser.version.substr(0,1)<7) { // stupid ie6 
				$(".img .imgCanvas").html('<img id="stupidIE6" title="" alt="" src="'+newFilePath+fileName+'">');
				$("#stupidIE6").load(function() {
					$("#stupidIE6").css({"width":"100", "height":"100"}); 
					$("#stupidIE6").css({"width":"auto", "height":"auto"}); 
				});
			}
			$(".img IMG").css({"width":"auto", "height":"auto", "margin-top":"0px"}); 
			$(".img .description").html($(".galleryBunch A:first-child IMG").attr("alt")); 
		}
		$(".thumbs A:first").addClass("on")
		$(".thumbs A").click(function(){
			$(".thumbs A").removeClass("on");
			$(this).addClass("on");
//			alert($(this).children().attr("src")); 
			var firstImgUrl = $(this).children().attr("src");
/*			var fileName = firstImgUrl.substring(firstImgUrl.lastIndexOf("/")+1,firstImgUrl.lastIndexOf("-150x150.jpg"))+".jpg";
			var filePath = firstImgUrl.substring(0,firstImgUrl.lastIndexOf("/")+1);
			$(".img IMG").attr("src",filePath+fileName); */
			var fileName = firstImgUrl.substring(firstImgUrl.lastIndexOf("/")+1,firstImgUrl.length)
			var filePath = firstImgUrl.substring(0,firstImgUrl.lastIndexOf("/"));
			if (firstImgUrl){
				$(".img IMG").attr("src",newFilePath+fileName); 
				if ($.browser.msie && $.browser.version.substr(0,1)<7) { // stupid ie6 
					$(".img .imgCanvas").html('<img id="stupidIE6" width="" title="" alt="" src="'+newFilePath+fileName+'">');
					$("#stupidIE6").load(function() {
						$("#stupidIE6").css({"width":"100", "height":"100"}); 
						$("#stupidIE6").css({"width":"auto", "height":"auto"}); 
					});
				}
				$(".img IMG").css({"width":"auto", "height":"auto"}); 
				$(".img .description").html($(this).children().attr("alt")); 
			}
			curImg = $(".thumbs A").index($(this))+1;
//			console.log(curImg+" a "+$(this).attr("href"));
			highlightImgArrows();
			return false;
		});
		$('#prevSlide').unbind('click');
		$("#prevSlide").click(function(){
			if(curSlide>1){
				curSlide--;
				desiredPosition = -((curSlide*slideHeight)-slideHeight);
	//			console.log(curSlide+" a "+desiredPosition)
				$(".thumbs").animate({top:desiredPosition},400);
				highlightArrows();
			}
			return false;
		});
		$('#nextSlide').unbind('click');
		$("#nextSlide").click(function(){
			if(curSlide<maxSlide){
				desiredPosition = -curSlide*slideHeight;
				$(".thumbs").animate({top:desiredPosition},400);
				curSlide++;
				highlightArrows();
			}
			return false;
		});
		$('#prevImg').unbind('click');
		$("#prevImg").click(function(){
			if(curImg>1){
				curImg--;
				$(".thumbs A").eq(curImg-1).click();
				highlightImgArrows();
//				console.log(Math.ceil(curImg/15));
				if(curSlide!=Math.ceil(curImg/15)){
					if(curSlide>1){
						curSlide--;
						desiredPosition = -((curSlide*slideHeight)-slideHeight);
						$(".thumbs").animate({top:desiredPosition},400);
						highlightArrows();
					}
				}
			}
			return false;
		});
		$('#nextImg').unbind('click');
		$("#nextImg").click(function(){
			if(curImg<maxImg){
				curImg++;
				$(".thumbs A").eq(curImg-1).click();
				highlightImgArrows();
//				console.log(Math.ceil(curImg/15));
				if(curSlide!=Math.ceil(curImg/15)){
					if(curSlide<maxSlide){
						desiredPosition = -curSlide*slideHeight;
						$(".thumbs").animate({top:desiredPosition},400);
						curSlide++;
						highlightArrows();
					}
				}
			}
			return false;
		});
		function highlightArrows(){
			if(curSlide==maxSlide) $("#nextSlide").removeClass("on");
			else $("#nextSlide").addClass("on");
			if(curSlide!=1) $("#prevSlide").addClass("on");
			else $("#prevSlide").removeClass("on");
		}
		function highlightImgArrows(){
			if(curImg==maxImg) $("#nextImg").removeClass("on");
			else $("#nextImg").addClass("on");
			if(curImg!=1) $("#prevImg").addClass("on");
			else $("#prevImg").removeClass("on");
		}
	
	})
	/* right album displayed accordingth URL parameter */
	var parameter = window.location.toString();
	parameter = parseInt(parameter.substring(parameter.lastIndexOf("#")+1));
	if (parameter){
		parameter = parameter-1;
		$("#galleryCombo OPTION").removeAttr("selected");
		$("#galleryCombo OPTION").eq(parameter).attr("selected","selected");
	}
	$("#galleryCombo").change();
	$("#enqGeneral").click(function(){
		$(".toggle").hide();
		$(".toggle INPUT").removeClass("required");
	})	 
	$("#enqMembership").click(function(){
		$(".toggle INPUT").addClass("required");
		$(".toggle").show();
	})
	$(".enter").click(function(){
//		$(this).children("img").attr("src","wp-content/themes/dugs/img/btn-entered.gif");
//		$(this).attr("src","wp-content/themes/dugs/img/btn-entered.gif");
//		alert($(this).length)
//		return false;
	})
});

$(window).resize(function() {});



