$(document).ready(function(){


    // Open external links in new window
	$("a[href^=http://]").click(function(){
	   window.open(this.href);
	   return false;
	});
	
    // Add class to sidebar nav
	$("#sidebar dd a").each(function(){
		if(location.href.match(this.href))
			$(this).addClass("currentPage");
	});
	
	// Cycle the littel connect icons in the footer
	$("#cycle").cycle({
        fx: "scrollDown",
        speed: 500,
        timeout: 3000
    });
	
	$("#homeNewsRotate").cycle({
        fx: "fade",
        speed: 500,
        timeout: 5000
    });
    
    // Font replacement - http://cufon.shoqolate.com/generate/
        Cufon.replace("h2, h3");
        Cufon.now();
        
    // Map Pop Up
    $('#openMap').click(function(){
        var flashvars = {};
		var params = {};
		params.wmode = "transparent";
		var attributes = {};
		swfobject.embedSWF("map/ith_map.swf", "mapObject", "980", "660", "9.0.0", false, flashvars, params, attributes);
		$('#overlay').css({
            "height": $(document).height()
        });
        $('#nav').css({"visibility":"hidden"});
        $('#theMap, #overlay').show();
        
        return false;
    });
    
    // Close Map Pop Up
    $('#closeTheMap').click(function(){
        $('#nav').css({"visibility":"visible"});
        $('#theMap, #overlay').hide();
    });

    // Newsletter Pop Up
    $('#popUpNewsletter').fancybox({
        'frameWidth': 298,
        'frameHeight': 330,
        'hideOnContentClick': false,
        'overlayShow': true
    });
    
// Earlier Overlay code, now using fancybox.
    
//    $('#popUpNewsletter').click(function(){
//        $('#overlay').css({
//            "height": $(document).height()
//        });
//        $('#newsletterSignUp').show();
//        $("#overlay").fadeIn(500);
//        return false;
//    });
//    
    // Close Newsletter Pop Up
//    $('#closeNl').click(function(){
//        $('#newsletterSignUp, #overlay').hide();
//    });

    
    // Share Pop Up
    $('#popUpShare').click(function(){
        $('#overlay').css({
            "height": $(document).height()
        });
        $('#share, #overlay').show();
        return false;
    });
    
    // Close Share Pop Up
    $('#closeShare').click(function(){
        $('#share, #overlay').hide();
    });
    
    // Video Gallery
    $(".video").click(function(){
    
        $('#overlay').css({
            "height": $(document).height()
        });
        
        $('#videoGalleryWrapper').show();
        $("#overlay").fadeIn(1000);
    
        var i = $(this).parent().attr("rel");
        var j = $(this).attr("href")
        
        $("#videoGallery object").remove();
        
        $("#videoGallery").append('<div id="' + i + '"></div>');
                
        var flashvars = {};
    	var params = {};
    	params.wmode = "transparent";
    	var attributes = {};
    	swfobject.embedSWF(j, i , "570", "420", "9.0.0", false, flashvars, params, attributes);
    	        
        // Prevent browser from following link
        return false;
        
    });

    // Corbin Video
        $(".videoEmbed").click(function(){
    
        $('#overlay').css({
            "height": $(document).height()
        });
        
        $('#videoGalleryWrapper').show();
        $("#overlay").fadeIn(1000);
            
        // Prevent browser from following link
        return false;
        
    });
    
    // Kill video
    $('#closeEmbedVideo').click(function(){
        $('#videoGalleryWrapper, #overlay').hide();
    });

    // Kill video
    $('#closeVideo').click(function(){
        $('#videoGalleryWrapper, #overlay').hide();
        $('#videoGallery object').remove();
        
    });

    // Corbin Downloads
    $('#corbinDownload').click(function(){
        $('#overlay').css({
            "height": $(document).height()
        });
        $('#corbinStuff, #overlay').show();
        return false;
    });
    
    // Close Share Pop Up
    $('#closeDownload').click(function(){
        $('#corbinStuff, #overlay').hide();
    });
    
    // Photo Gallery
     $('#photoGallery li a').fancybox({
        'overlayShow' : false,
        'zoomSpeedIn' : 600,
        'zoomSpeedOut' : 500,
        'easingIn' : 'easeOutBack',
        'easingOut' : 'easeInBack'
    });
    
    //Tour Videos
        $(".videoTour").click(function(){
    
        $('#overlay').css({
            "height": $(document).height()
        });
        
        $('#videoGalleryWrapper').show();
        $("#overlay").fadeIn(1000);
    
        var i = $(this).parent().attr("rel");
        var j = $(this).attr("title")
        
        $("#tourVideoGallery object").remove();
        
        $("#tourVideoGallery").append('<div id="' + i + '"></div>');
                
        var flashvars = {};
    	var params = {};
    	params.wmode = "transparent";
    	var attributes = {};
    	swfobject.embedSWF(j, i , "570", "420", "9.0.0", false, flashvars, params, attributes);
    	        
        // Prevent browser from following link
        return false;
        
    });



    // Kill video
    $('#closeVideo').click(function(){
        $('#videoGalleryWrapper, #overlay').hide();
        $('#tourVideoGallery object').remove();
        
    });
    
    
    // Pop up the video music widgets
    $('#openVideoWidget').fancybox({
        'frameWidth': 330,
        'frameHeight': 300,
        'hideOnContentClick': false,
        'overlayShow': true
    });
    $('#openMusicWidget').fancybox({
        'frameWidth': 240,
        'frameHeight': 421,
        'hideOnContentClick': false,
        'overlayShow': true
    });
    $('#openWidgetBuilder').fancybox({
        'frameWidth': 720,
        'frameHeight': 650,
        'hideOnContentClick': false,
        'overlayShow': true
    });
    
    // Share
    $('#shareDel a').sharehelper('delicious');
    $('#shareFacebook a').sharehelper('facebook');
    $('#shareMyspace a').sharehelper('myspace');
    $('#shareTwitter a').sharehelper('twitter');
    $('#shareDigg a').sharehelper('digg');
    
    
    // Mobile Alerts
    $('.popUpMobileAlerts').fancybox({
        'frameWidth': 298,
        'frameHeight': 328,
        'hideOnContentClick': false,
        'overlayShow': true
    });
    
    
    $("#timeline").tabs();
    
    
});

$(window).load(function() {
	// Fancy pants scroll bars
	$(".scrollPane").jScrollPane({scrollbarWidth:18, scrollbarMargin:10, dragMaxHeight: 48, dragMinHeight: 48});
});