$(document).ready(function () {
	$('.box1000').cycle({
		after:afterCycle,
		prev:'#cycleNav .prev',
		next:'#cycleNav .next',
		delay:2000,
		timeout:5000,
		speed:1000,
	})
	$("#cycleNav").show();
	tooltip();
});

function afterCycle(curr, next, opts, fwd){
	var $ht = $(this).height();
	$(this).parent().css("height", $ht);
}	

function showhide(elem) {
	if(elem.nextSibling.style.display==''){
			elem.nextSibling.style.display='block';
	} else {
		if(elem.nextSibling.style.display=='none') {
			elem.nextSibling.style.display='block';
		} else {
			elem.nextSibling.style.display='none';
		}
	}
}

this.tooltip = function(){	
	$("a.preview").hover(function(e){
		this.img = this.style.backgroundImage.replace("url(","").replace(")","").replace(/\"/g,"").replace("_s_","_l_");
		$(".previewbox img").attr("src", this.img);		
    });
	$("div.preview").hover(function(e){	
		this.img = this.getAttribute("name");
		$(".previewbox img").attr("src", this.img);		
    });
};

function showWood(wood) {
	var allLinks = document.getElementById("gallerySelect").childNodes;
	for (var i = 0; i < allLinks.length; i++) {
		if(allLinks[i].nodeName=="A") {
			var thisId = allLinks[i].getAttribute("id").substring(5, 7);
			if(thisId==wood+"-" || thisId==wood) allLinks[i].style.backgroundColor = '#bbe902';
			else allLinks[i].style.backgroundColor = '#f0f0f0';
		}
	}
	if(wood=="0") document.getElementById("link-0").style.backgroundColor = '#bbe902';
	var allWoods = document.getElementById("galleryWoods").childNodes;
	for (var i = 0; i < allWoods.length; i++) {
		if(allWoods[i].nodeName=="DIV") {
			var thisId = allWoods[i].getAttribute("id").substring(5, 7);
			if(wood!="0" && thisId!=wood+"-" && thisId!=wood) allWoods[i].style.display = 'none';
			else allWoods[i].style.display = 'block';
		}
	}
}

function checkRecommend (recipient, sender) {
	if (document.getElementById("recipient").value.indexOf("@")==-1 
		|| document.getElementById("recipient").value.indexOf(".")==-1 
		|| document.getElementById("recipient").value.length<7) {
		alert(recipient);
		document.getElementById("recipient").style.backgroundColor='#ffcccc';
		document.getElementById("recipient").focus();
		return false;
	} else {
		document.getElementById("recipient").style.backgroundColor='#ffffff';
	}
	if (document.getElementById("sender").value.length < 2) {
		alert(sender);
		document.getElementById("sender").style.backgroundColor='#ffcccc';
		document.getElementById("sender").focus();
		return false;
	} else {
		document.getElementById("sender").style.backgroundColor='#ffffff';
	}
	return true;
}
