/* Author: 

*/

var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		if (o < 0.5){
			o = 0;
		}
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

$(document).ready(function() {
	
	//When page loads...
	$("#galleryWindow").hide();
	$(".gallery_content").hide(); //Hide gallery box content
	$("#gallerynav li:first").addClass("active").show(); //Activate first tab
	$(".gallery_content:first").show(); //Show first tab content
	
	//On Click Event CLose Image Button
		$("#closeimg").click(function() {

			$("#galleryWindow").slideToggle(300);
			$("#featured-banner").slideToggle(300);
			return false;
		});
	
		// On Click Event on the Tabs Content
		$("#gallerynav li").click(function() {

			$("#gallerynav li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".gallery_content").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
		
		// On Click Event on the Tabs Content
		$("#imglink li").click(function() {

			$("#imglink li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$("#featured-banner").hide(); //Hide all tab content
			$("#galleryWindow").fadeIn();
			
			$('#imgWindow').find("img").remove();
			$('#imgWindow').addClass('loading');
			
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			
			//Ajax call for the images
			var imgSrc = $(this).find("img").attr("src");
			var path = $(this).find("img").attr("src");
			imgSrc = imgSrc.substring(imgSrc.lastIndexOf("/"));
			path = path.substr(0,path.lastIndexOf("gallery"));
			imgSrc = path + 'gallery/large' + imgSrc;
			//alert(imgSrc);
			
			$(function () {
			        var img = new Image();
			        $(img).load(function () {
			            $(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
			            $(this).fadeOut();
						
			            $('#imgWindow').removeClass('loading').append(this);
						//$('#imgWindow').find("img").remove();
			            $(this).fadeIn(600);
			        }).error(function () {
			            //$('#imgWindow').find("img").remove();
						$('#imgWindow').addClass('loading').append(this);
			        }).attr('src', imgSrc );
			    });

			
			return false;
		});
		
		$('#imgWindow').bind('contextmenu', function(e){ 
		    //alert('right mouse button is pressed');
			return false;
		});
		
		$('#tour').tinycarousel({ display: 2 });

		$('#scrollpane').tinyscrollbar();
	
});



















