$(document).ready(function() {
	
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
		return false;
	
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
	
	var hoverIntentConfig = {    
     sensitivity: 5,    
     interval: 50,    
     over: function(){dropdown = "DD"+$(this).attr("id");
					  shortDropdown = $(this).attr("id");
					  $("#"+dropdown).show();
					  },   
     out: function(){}  
    };

	$("#header ul a").hoverIntent(hoverIntentConfig);
	var dropdown, shortDropdown;
	$("#header ul a").hover(function(){
	                                    dropdown = "DD"+$(this).attr("id");
									},function(){
										$("#"+dropdown).hide();
										});
	$(".dropdown").hover(function(){
								  $("#"+dropdown).show();
								  $("#"+shortDropdown).addClass("hover");
								  },function(){
									  $("#"+dropdown).hide();
									  $("#"+shortDropdown).removeClass("hover");
								  });
    $("a.youtube").click(function() {
        $.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'title'			: this.title,
			'width'		: 720,
			'height'		: 430,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {'wmode'		: 'transparent',
				               'allowfullscreen'	: 'true'},
	        'callbackOnClose': function() {$("#fancy_content").empty();} 
		});
		return false;
    });
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});
    //$('a[href="#"]').addClass("badLink");
    
    //handle form links
    $('a.formLink').click(function() {
        var xID = $(this).attr('href');
        $.get(xID + '?tfrm=4', function(data) {
           var url = $(data).find('FormDocument').text();
           if (url.length <= 0) {
            url = $(data).find("Page[Name='FormLink']").attr("URL");
           } else {
            url = "Documents/" + url;
           }
           window.location.href = url;
        })
        return false;        
    });

});

$.urlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (!results) { return 0; }
	return results[1] || 0;
}
