Cufon.replace('.header');

var loc;
var loc2;

$(document).ready(function() {
/** Nav ****************************/	
$('#smoothmenu1').load('includes/nav.html', function() {
	ddsmoothmenu.init({
		mainmenuid: "smoothmenu1",
		orientation: 'h', 
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	});
	
	
if($('.splashcontent').length !== 0) {
loc = $('.splashcontent').attr('class').split('splashcontent ');
//alert(ucfirst(String(loc)));

	$('.splashtextcontent').click(function() {
		document.location.href=ucfirst(String(loc))+'_Intro';

	});
}

});

function ucfirst(str) {
var removeLetter = str.slice(0,1);
var firstLetter = str.slice(1,2);
return firstLetter.toUpperCase() + str.substring(2);
}

/** subnav ****************************/
$('#subnav').load('includes/subnav.html');

});


/** scrollbar ****************************/
var scroller  = null;
var scrollbar = null;

window.onload = function () {
/** fade in ****************************/
$(".hold").delay(200).fadeIn(800, function() { 
	if($(".calendar").length === 1){
		loadCal();
		setFancyBoxes();
	}else if($(".gallerycontent").length === 1){
		setFancyBoxes();
	}else{
		showText();
	}
 });
};

function showText(){
	if(!$.browser.msie){
		if($(".textcontent").length === 0) {
			$('.splashtextcontent').fadeIn(400);
			setFancyBoxes();
		}else{
			$(".textcontent").fadeIn(400);
			$('.header').delay(200).fadeIn(400);
			$('.breadcrumb').delay(200).fadeIn(400);
			$('.divline').delay(200).fadeIn(400);
			setScrollbar();
		}    
	}else{
		if($(".textcontent").length === 0) {
			$('.splashtextcontent').fadeIn(400);
			setFancyBoxes();
		}else{
			$('.header').delay(10).fadeIn(10);
			setScrollbar();
		}
		//$('.splashheader').delay(10).fadeIn(10);
	}
}

function setScrollbar(){
		var pane = $("#ctl00_MainContent_textfield");
		pane.jScrollPane({showArrows: true});
		var api = pane.data("jsp");
		api.getContentPane().html(JavaScriptFunction());
		api.reinitialise();
		setFancyBoxes();			
}

/** temperature ****************************/
$.temp({
		success: function(t) {
			$("#temp").html("<img class='t' src='"+t.thumbnail+"' height='26px' width='47px'><a href='"+t.link+"' target='_blank'>Currently: "+t.temp+"&deg;</a>");
		},
		error: function(error) {
			$("#temp").html("Currently: 67&deg;");
		}
});


/** calendar ****************************/
function loadCal(){
	$(".calendar").fullCalendar({
			header: {
				left: "prev,next today",
				center: "title",
				right: "month,basicWeek,basicDay"
			},
			editable: true,
			
		events: function(start, end, callback) {
        $.ajax({
            url: '/calendar.xml',
            dataType: 'xml',
            success: function(doc) {
                var events = [];
                $(doc).find('event').each(function() {

                    events.push({
                        title: $(this).find('title').text(),
                        description: $(this).find('description').text(),
                        start: $(this).find('start').text(),
                        end: $(this).find('end').text()
                    });
                });

                callback(events);
            }
        });
    },
    		
			eventRender: function(event, element) {
        		element.qtip({
					content: {
						text: event.description,
      					attr: "title",
      					title: {
         					text: event.title
      						}},
					position: {
						my: "top center", // Use the corner...
               			at: "bottom center", // ...and opposite corner
						viewport: $(".calbkg")
					}
        		});
    		}
		});
}
