// JavaScript Document
$(document).ready(function(){
	
	//Video Overlay
	$.videoOverlay = function(){
		$("a.preview").click(function(){
			$("body").prepend('<div id="canvas"></div>');
			$(".left").before('<div id="overlay"><span></span></div>');
		}).overlay({ 
			onLoad: function(content, link) { 
				content.find("span").load(link.attr("href"));
			},
			onClose: function(){
				$("#overlay, #canvas").remove();
			}
		});	
	}
	
	$("ul.menu a").click(function(){
		
		var class = $(this).attr('class');
		
		if(class=='packages') return;
		
		$("#content").load($(this).attr('href') + " div.right div.content", {}, function(){
				
				//Unbind click events so they don't fire more than once
				$('a.next').unbind('click');
				$('a.prev').unbind('click');
				
				//Heading and Video settings
				$(".heading").html( class + " > " );
				if(class=='video'){ 
					$("p.nav").css({"display": "block"}); 
					$("#content").css({"height": "420px"});
				}else{ 
					$("p.nav").css({"display": "none"});
					$("#content").css({"height": "auto"});
				}
				
				$.videoOverlay();
				
				//Video Scrolling
				i = 0;
				size = $("div.videoholder").size() - 1;
				$("#i").html(i + 1); $("#size").html(size + 1);
				
				$('a.next').click(function(){
					var getHeight = $('.videoholder').height();
					if(i==size){
						$('.right .content').animate({marginTop: "+="+(getHeight*size)+"px"}, 500);
						i = 0;
					} else {
						$('.right .content').animate({marginTop: "-="+getHeight+"px"}, 500);
						i++;
					}
					$("#i").html(i + 1);
					return false;
				});
				
				$('a.prev').click(function(){
					var getHeight = $('.videoholder').height();
					if(i!=0){
						$('.right .content').animate({marginTop: "+="+getHeight+"px"}, 500);
						i--;
					}
					$("#i").html(i + 1);
					return false;
				});			
			
		});
		return false;
	});
	
});
