$(function() {

    // sub-navigation accordion
    var subnavs = $(".level-2");
    if(subnavs.length > 0) {
        // get the current body id attribute
        var bodyID = $("body").attr("id");
        
        // set an active index to false (don't open anything)
        var activeIndex = false;
        
        subnavs.each(function(){
            // loop through each subnav
            var subnav = $(this);
            // get the li tags for each subnav, see if we have a match
            var liTags = subnav.find(" > li");
            liTags.each(function(index){
                if($(this).hasClass(bodyID)){
                    activeIndex = index;
                }
            });
            // create the accordion, referencing our activeIndex (int or false)
            subnav.accordion({
                header:'li span',
                active: activeIndex,
                collapsible: true,
                autoHeight: false,
                icons:{
                    header:"ui-icon-plus",
                    headerSelected:"ui-icon-minus"
                }
            });
        });
    }

    /* itinerary accordion */
    $(".itinerary").accordion({
        header:'h4',
        active: false,
        collapsible: true,
        autoHeight: false,
        icons:{
            header:"ui-icon-plus",
            headerSelected:"ui-icon-minus"
        }
    });
    
    /* general accordion */
    $(".accordion").accordion({
        header:'h4',
        active: false,
        collapsible: true,
        autoHeight: false,
        icons:{
            header:"ui-icon-plus",
            headerSelected:"ui-icon-minus"
        }
    });

    /*  lesson plans & videos accordion */
    $(".lesson-plans-accordion").accordion({
        header:'h3',
        active: false,
        collapsible: true,
        autoHeight: false,
        icons:{
            header:"ui-icon-plus",
            headerSelected:"ui-icon-minus"
        }
    });

    // var getPhotos = $("a.photo").attr['rel'] == 'shadowbox';
    $("a.photo").prepend("<span></span>");
    
    // add print button to destination comparison
    if($("body").hasClass("destination-comparison")) {
        if(window.print !== undefined) {
            var printBtn = $('<p id="print-btn">Print</p>');
            printBtn.bind("click", function(){
                window.print();
            });
            $("#center-column h1").after(printBtn);
        }
    }

    // add back button to interactive maps and destination comparison
    if($("body").hasClass("interactive-map") || $("body").hasClass("destination-comparison")) {
        if(history.length > 0) {
            var backBtn = $('<p id="back-btn">Back</p>');
            backBtn.bind("click", function(){
                history.go(-1);
            });
            $("#center-column h1").after(backBtn);
        }
    }

    /* destination comparison logic */
    if($("#destinations.destination-comparison").length > 0){
        // data containers
        var selectedDestinations;
        
        // element references
        var container = $(".destination-comparison-container").eq(0);
        var checkboxes = $("#destinations-list input:checkbox");
        
        // stripe table rows
        container.find('table tr:even').addClass('alt');
        
        // close (x) icons on table headers - remove this destination from table
        container.find(".close-btn").each(function(index){
            $(this).bind("click", function(){
                var checkbox = $("#destinations-list input:checkbox[value="+(index+1)+"]");
                checkbox.removeAttr("checked");
                checkbox.trigger("change");
            });
        });
        
        // hide the container initially
        container.hide();
        
        // what to do when a checkbox is clicked - only allow 5 destinations
        checkboxes.bind("click change", function(){
            selectedDestinations = checkboxes.filter(":checked");
            var unchecked = checkboxes.not(":checked");
            if(selectedDestinations.length == 5){
                unchecked.attr("disabled", "disabled");
                unchecked.parent("label").addClass("disabled");
            } else {
                checkboxes.removeAttr("disabled");
                unchecked.parent("label").removeClass("disabled");
            }
            updateComparisonTable(container, selectedDestinations);
        });
    }

    /* destination comparison logic */
    if ($("#destinations-2012.destination-comparison").length > 0) {
        // data containers
        var selectedDestinations;

        // element references
        var container = $(".destination-comparison-container").eq(0);
        var checkboxes = $("#destinations-list input:checkbox");

        // stripe table rows
        container.find('table tr:even').addClass('alt');

        // close (x) icons on table headers - remove this destination from table
        container.find(".close-btn").each(function(index) {
            $(this).bind("click", function() {
            var checkbox = $("#destinations-list input:checkbox[value=" + (index + 1) + "]");
                checkbox.removeAttr("checked");
                checkbox.trigger("change");
            });
        });

        // hide the container initially
        container.hide();

        // what to do when a checkbox is clicked - only allow 5 destinations
        checkboxes.bind("click change", function() {
            selectedDestinations = checkboxes.filter(":checked");
            var unchecked = checkboxes.not(":checked");
            if (selectedDestinations.length == 5) {
                unchecked.attr("disabled", "disabled");
                unchecked.parent("label").addClass("disabled");
            } else {
                checkboxes.removeAttr("disabled");
                unchecked.parent("label").removeClass("disabled");
            }
            updateComparisonTable(container, selectedDestinations);
        });
    }


    /* destination2013 comparison logic */
    if ($("#destinations-2013.destination-comparison").length > 0) {
        // data containers
        var selectedDestinations;

        // element references
        var container = $(".destination-comparison-container").eq(0);
        var checkboxes = $("#destinations-list input:checkbox");

        // stripe table rows
        container.find('table tr:even').addClass('alt');

        // close (x) icons on table headers - remove this destination from table
        container.find(".close-btn").each(function (index) {
            $(this).bind("click", function () {
                var checkbox = $("#destinations-list input:checkbox[value=" + (index + 1) + "]");
                checkbox.removeAttr("checked");
                checkbox.trigger("change");
            });
        });

        // hide the container initially
        container.hide();

        // what to do when a checkbox is clicked - only allow 5 destinations
        checkboxes.bind("click change", function () {
            selectedDestinations = checkboxes.filter(":checked");
            var unchecked = checkboxes.not(":checked");
            if (selectedDestinations.length == 5) {
                unchecked.attr("disabled", "disabled");
                unchecked.parent("label").addClass("disabled");
            } else {
                checkboxes.removeAttr("disabled");
                unchecked.parent("label").removeClass("disabled");
            }
            updateComparisonTable(container, selectedDestinations);
        });
    }
    


    // twitter status widget (hide until success)
    $("#twitter-feed").hide();	
	if($("body").has("#twitter-feed").length > 0) {
		var twitterURL = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=discoverytrips&count=3";
		$.ajax({
			url: twitterURL,
			dataType: "jsonp",
			success: function(data, status, xhr){
				$("#twitter-feed").show();
				
				var currTweets = '';
				var urlRegEx;
				var fullURL = '';
				var displayedURL = '';
				var linkifiedURL = '';
				var startIndex;
							
				//$("#twitter_update_list").html("<li>" + data[0].text + "</li><br><li>" + data[1].text + "</li><br><li>" + data[2].text + "</li>");
				for(var i = 0; i <3; i++){
					var myTweetString = '';								
					var myTweet = data[i].text;
					
					urlRegEx = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/im;
					fullURL = urlRegEx.exec(myTweet);
					startIndex = 0;
							
					while (fullURL != null)
					{					
						displayedURL = fullURL[0];
							
						if (fullURL[0].length > 25)
						{							
							displayedURL = fullURL[0].substring(0,25) + '...';							
						}
						linkifiedURL = "<a href='" + fullURL[0] + "' title='" + fullURL[0] + "' target='_blank'>" + displayedURL + "</a>";
						myTweet = myTweet.replace(fullURL[0], linkifiedURL);
						startIndex = myTweet.lastIndexOf(linkifiedURL) + linkifiedURL.length;
						fullURL = urlRegEx.exec(myTweet.substring(startIndex));
					}
					
					myTweetString = myTweet;				  				  
					currTweets = currTweets + "<br><li>" + myTweetString + "</li>";
				}			
				$("#twitter_update_list").html(currTweets);
			}
		});
	}
	
	// twitter HASH status widget (hide until success)
    $("#twitter-feed-hash").hide();
	if($("body").has("#twitter-feed-hash").length > 0) {
		var hashTag = $("#hiddenHash").val();
		var twitterURL = "http://search.twitter.com/search.json?q=%23" + hashTag + "&from%3A100272344&result_type=recent";
		$.ajax({
			url: twitterURL,
			dataType: "jsonp",
			success: function(data, status, xhr){
				$("#twitter-feed-hash").show();
				
				var currTweets = '';
				var urlRegEx;
				var fullURL = '';
				var displayedURL = '';
				var linkifiedURL = '';
				var startIndex;
				var tweetCount = data.results.length;
				
				if (tweetCount > 3)
				{
					tweetCount = 3;
				}
							
				for(var i = 0; i < tweetCount; i++){
					var myTweetString = '';								
					var myTweet = data.results[i].text;
					
					urlRegEx = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/im;
					fullURL = urlRegEx.exec(myTweet);
					startIndex = 0;
							
					while (fullURL != null)
					{					
						displayedURL = fullURL[0];
							
						if (fullURL[0].length > 25)
						{							
							displayedURL = fullURL[0].substring(0,25) + '...';							
						}
						linkifiedURL = "<a href='" + fullURL[0] + "' title='" + fullURL[0] + "' target='_blank'>" + displayedURL + "</a>";
						myTweet = myTweet.replace(fullURL[0], linkifiedURL);
						startIndex = myTweet.lastIndexOf(linkifiedURL) + linkifiedURL.length;
						fullURL = urlRegEx.exec(myTweet.substring(startIndex));
					}
					
					myTweetString = myTweet;				  				  
					currTweets = currTweets + "<br><li>" + myTweetString + "</li>";
				}			
				$("#twitter_hash_list").html(currTweets);
			}
		});
	}

    // home page swf
    var videoPlayer = $("#home #video-player");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/player-home.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // home page swf
    var videoPlayer = $("#campaigns #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-home.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // chicago tribune landing page swf
    var videoPlayer = $("#experience #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-experience.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // costa rica contest landing page swf
    var videoPlayer = $("#contest #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-contest.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // de eblast landing page swf
    var videoPlayer = $("#discovery #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-discovery.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // ib conference landing page swf
    var videoPlayer = $("#conference #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-conference.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // science trip landing page swf
    var videoPlayer = $("#young-scientist #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-science.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // pay per click landing page swf
    var videoPlayer = $("#ppc #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-ppc.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // pay per click landing page students and parents swf
    var videoPlayer = $("#ppc-sp #video-player");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/player-ppc-sp.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-player", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-home.swf", "video-player", "580", "440", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    // destination page swfs
    var videoPlayer = $("#destinations #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-overview.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // destination page swfs
    var videoPlayer = $("#destinations-2012 #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-2012-overview.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // destination page swfs
    var videoPlayer = $("#destinations-2013 #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-2012-overview.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    

    var videoPlayer = $("#arctic #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-arctic.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#grand-canyon #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-arizona-grand-canyon.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#australia #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-australia.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    var videoPlayer = $("#australia-newzealand #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-australia-newzealand.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#china #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-china.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#costa-rica #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-costa-rica.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#ecuador-galapagos #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-ecuador-galapagos.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#france-germany #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-france-germany.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#italy-greece #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-italy-greece.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#london-paris #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-london-paris.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#new-zealand-australia #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-new-zealand-australia.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#scotland-london-paris #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-scotland-london-paris.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#south-africa #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-south-africa.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#spain-portugal #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-spain-portugal.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#washington-dc #video-trips");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/destination-washington-dc.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    var videoPlayer = $("#yellowstone #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-yellowstone.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    var videoPlayer = $("#france-spain #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-france-spain.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    var videoPlayer = $("#england-france #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-england-france.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    var videoPlayer = $("#australia-new-zealand #video-trips");
    if (videoPlayer.length > 0) {
        var flashvars = { xmlPath: "/media/xml/destination-australia.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "video-trips", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "video-trips", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    // about us swfs
    var videoPlayer = $("#about-us.hear-from-our-travelers #videoplayer");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/about-hear-travelers.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "videoplayer", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "videoplayer", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    var videoPlayer = $("#about-us.make-a-difference #videoplayer");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/about-make-difference.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "videoplayer", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "videoplayer", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    // students swfs
    var videoPlayer = $("#students #videoplayer");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/student-overview.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "videoplayer", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "videoplayer", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    // parents swfs
    var videoPlayer = $("#parents #videoplayer");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/parent-overview.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "videoplayer", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "videoplayer", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
    
    // teacher page swfs
    var videoPlayer = $("#teachers #videoplayer");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/teacher-overview.xml" };
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "videoplayer", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "videoplayer", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }

    var videoPlayer = $("#teachers.getting-started #videoplayer");
    if(videoPlayer.length > 0){
        var flashvars = { xmlPath: "/media/xml/teacher-getting-started.xml" }; 
        var params = { wmode: "transparent", allowFullScreen: "true" };
        var attributes = { id: "videoplayer", name: "flash-player" };
        swfobject.embedSWF("/media/swf/player-trips.swf", "videoplayer", "460", "365", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params, attributes);
    }
});

function limitToCharsAndSpaces(evt) {
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if((charCode > 32 && charCode < 47)|(charCode > 47 && charCode < 65)|(charCode > 90 && charCode < 97) |(charCode > 122 && charCode <127)){
		status = "This field accepts characters and spaces only."
		return false
	}
	status = ""
	return true
}

function limitToCharsSpacesNumbers(evt) {
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if((charCode > 32 && charCode < 47)|(charCode > 58 && charCode < 65)|(charCode > 90 && charCode < 97) |(charCode > 122 && charCode <127)){
		status = "This field accepts characters, spaces, and numbers only."
		return false
	}
	status = ""
	return true
}

function updateComparisonTable(container, selectedDestinations){
    // data containers
    var selectedIndicies = [];
    
    // get the table rows
    var tableRows = $("#destination-table tr");
    
    // get the value of each checkbox (which is an integer)
    selectedDestinations.each(function(){
        selectedIndicies.push($(this).val());
    });
    
    // get the width of the entire table and the first column
    var tableWidth = container.width();
    var firstColumnWidth = container.find("tr:first th:first").width();
    var dataWidth = tableWidth - firstColumnWidth;
    
    if(selectedDestinations.length > 1){
        // 2 or more destinations were checked, show the container
        container.show();
        
        // calculate the width each column should be
        var colWidth = dataWidth / selectedDestinations.length;
        
        // determine which is the last column so we can add a "last" class to it
        var lastIndex = selectedIndicies[selectedIndicies.length - 1];
        
        // loop through each row and hide the column if necessary
        tableRows.each(function(){
            var columns = $(this).children();
            columns.each(function(index, col){
                var column = $(col);
                column.removeClass("last");
                if(index != 0){
                    if($.inArray(index.toString(), selectedIndicies) != -1){
                        if(index == lastIndex) column.addClass("last");
                        column.css("width", colWidth);
                        column.show();
                    } else {
                        column.hide();
                    }
                }
            });
        });
    } else {
        // less than 2 destinations were checked, hide the container
        container.hide();
    }
}



// quotes test


function rotateText(el, textGroup) {
    setOpacity(el, 0);
    var t = rotateText.texts[textGroup];
    var t = t[Math.floor(Math.random() * (t.length - 1))];
    el.innerHTML = t;
    unfadeText(el, textGroup);
}
rotateText.texts = {
    quotes: [
    "I truly believe that a child learns and retains more if they read about it, see it, and then experience it. That's what a Discovery journey is all about.<br/><span>Lisa T., Teacher</span>",
    "I had the best time of my life and am so lucky that I got to experience this incredible journey. <br/><span>Jessica G., Student</span>",
    "What an amazing trip! I know that my son is never going to be the same. I can see how much it has expanded his horizons.<br/><span>Alice O., Parent</span>",
    "We spent every waking moment doing something extraordinary and learning so much.<br/><span>Maestra C., Teacher</span>",
    "I will never forget these experiences and the awe and joy I felt and my trip.<br/><span>Jude M., Student</span>",
    "Cultural and historical immersion, scientific exploration, conservation, service, and adventure - our students delved into these aspects again and again.<br/><span>Denise G., Teacher</span>",
    "It was a life-changing and wonderful experience for the kids. It provided them the opportunity to meet new and different people, and see things that they may only get to see on TV.<br/><span>Kathy G., Parent</span>",
    "What an amazing trip! I know that Daniel is never going to be the same. I can see how much it has expanded his horizon. He is so excited - and so am I!<br/><span>Alice O., Parent</span>",
    "Our trip was an intense, educational life journey that is valuable now - and will forever remain valuable.<br/><span>Ken S., Teacher</span>",

"Our son's Grand Canyon trip was amazing. Accommodations, food, and activities were top-notch and he returned with a new confidence.<br/><span>Vernae W, Parent</span>",

"My trip was like watching a documentary on the Discovery Channel. I feel like I just woke up from an awesome dream.<br/><span>Meagan G., Teacher</span>",

"Snorkeling on the Great Barrier Reef was amazing. I liked it so much I want to be a marine biologist so I can explore the underwater world as a job.<br/><span>Shea S, Student</span>",

"Follow the guidance of the Discovery team and the teacher and your child will have a safe, exceptional and educational experience like no other.<br/><span>Liz D., Parent</span>",

"Firsthand knowledge of ecology, geography, and science are just the beginning of what my students learned. It was an incredible life lesson!<br/><span>Carol M., Teacher</span>",

"It was amazing to pray with monks in China; definitely an experience many people will never get to have - and one I am so grateful for.<br/><span>Kim G., Student</span>",

"It was magical watching students explore the Great Barrier Reef with marine biologists. Every teacher needs to have a learning experience like this with their students.<br/><span>Jannita D., Teacher</span>",

"I gained a better understanding of my own role in the world and appreciation of everything I have.<br/><span>Mary O., Student</span>",

"Discovery Student Adventures made sure my child was safe and gave her an adventure of a lifetime.<br/><span>Dana S., Parent</span>",

"Safety and accountability are big concerns for me. Discovery answered all my questions.<br/><span>Lisa T., Teacher</span>",

"It was so exciting to share my passion for the undersea world with my students.<br/><span>Jennifer J., Teacher</span>",

"We camped at the Great Wall, learned kung fu from the masters, cooked with a famous chef, went dragon boat racing, and spent a morning with Buddhist monks. Amazing!<br/><span>Maha E., Student</span>",

"Exploring Africa with Discovery was the experience of a lifetime - from diving with sharks, to meeting with a local tribe.<br/><span>Danae S., Student</span>",

"Learning outside the traditional classroom setting inspired my students in ways I've never observed before.<br/><span>Joel H., Teacher</span>",

"The people, places, and cultures I experienced on my trip were amazing - it was an incredible eye-opening journey.<br/><span>Daniel P., Student</span>",

"Discovery trips take students beyond the classroom and into the field where they can work side-by-side with experts. It's a real eye-opener.<br/><span>Joel H., Teacher</span>",

"The Discovery Student Adventures' teacher's trip was amazing - Discovery take cares of everything.<br/><span>Elizabeth B., Teacher</span>",

"It's one thing to read about the world in a history book; but to actually experience it in person is more powerful than you can imagine.<br/><span>Abigail G., Student</span>",

"One thing I thoroughly enjoy about Discovery trips is the continuous learning through our experienced travel guides.<br/><span>James C., Teacher</span>",

"Meeting with local families in Costa Rica and experiencing their unique culture was a beautiful thing.<br/><span>Teyra A., Teacher</span>",

"We had a blast with other teachers and Discovery staff in Costa Rica; I can't wait to share everything I've learned about this wonderful culture with my students.<br/><span>Edmund S., Teacher</span>",

"The trip to South Africa has forever changed the way that I look at myself and the other people around the world.<br/><span>Daniel P., Student</span>",

"Every teacher needs to have this amazing educational experience with their students. It was magical.<br/><span>Jennita D., Teacher</span>",

"To actually be out there in a cage inches from a great white shark - that's the best thing.<br/><span>Daniel P., Student</span>",

"The Discovery journey gave my daughter confidence for life, there's no question about that.<br/><span>Mike M., Parent</span>",

"Our journey provided students with the opportunity to meet new people and see things that they otherwise would only have seen on TV.<br/><span>Kathy G., Teacher</span>",

"This trip gave me an opportunity to step out of the classroom and give students real life experiences beyond their imagination.<br/><span>Amy P., Teacher</span>",

"A whole new door to my world has been opened, and there is no way it can ever be closed. My journey to South Africa was truly life-changing.<br/><span>Mary O., Student</span>",

"My students experienced things that will stay with them for a lifetime. I have already planned another trip for next year.<br/><span>Lisa T., Teacher</span>",

"We visited an orphanage and the kids were so happy to see us; it really tugged on my heart.<br/><span>Kelby J., Student</span>",

"It was important that my daughter have an adventure of a lifetime and that she was safe. Discovery made sure of both!<br/><span>Leslie O., Parent</span>",

"I was blown away by all the planning that goes into making these trips so memorable and valuable for students and teachers.<br/><span>Dianne M., Teacher</span>",

"I explored several educational travel programs; Discovery Student Adventures was by far the most organized.<br/><span>Deborah G., Teacher</span>",

"China was mesmerizing, astounding, breathtaking - surreal. Discovery truly changed the way I look at the world.<br/><span>Katelyn M., Student</span>",

"Looking at the website, I learned Discovery Student Adventures was chock-full of experiences that would not be possible without the resources of Discovery.<br/><span>Richard R., Teacher</span>",

"I didn't doubt that it would be awesome because the name Discovery was backing this trip.<br/><span>Lydia G., Teacher</span>",

"You do all these things that you didn't think you could do before. After the trip I felt empowered to do anything.<br/><span>Riley N., Student</span>",

"A Discovery trip is absolutely life-changing. My son has such a bigger picture of the world and a much greater appreciation for different cultures.<br/><span>Ellen N., Parent</span>",

"The name Discovery stands by itself; the confidence I have in the company allows me to assure parents the greatest care is being taken for their child.<br/><span>Lisa W., Teacher</span>",

"We hiked hills I thought were impossible and saw things I never dreamed of. I returned home feeling like I could do anything.<br/><span>Becca T., Student</span>",

"Discovery Student Adventures provides learning opportunities that I wouldn't have access to otherwise - like expert guides and behind-the-scenes access.<br/><span>Richard R., Teacher</span>",

"Its' an amazing experience; something that I will never forget. I can't wait to share my stories with everyone.<br/><span>Iman K., Student</span>",

"Africa opened my daughters' eyes to the world around her. She plans to study International Affairs and this trip has encouraged her even more.<br/><span>Leslie O., Parent</span>",

"After traveling once and having a great experience, I feel very secure planning future trips with Discovery Student Adventures.<br/><span>Holly O., Teacher</span>",

"The people, places, and culture of China will stay in my heart forever. I have learned so much and made so many friends.<br/><span>Daniel O., Student</span>",

"Once I viewed the materials, itinerary, insurance provisions, training, and certification, I felt that every aspect of student travel had been well researched and planned.<br/><span>Dianne M., Teacher</span>",

"This was not just a once-in-a-lifetime experience - it was a beginning-of-a-lifetime of experience.<br/><span>Sherry B., Student</span>",

"By seeing the way other people live, students learn something new about themselves. It's an amazing opportunity that they'd never get in a classroom.<br/><span>Brett H., Teacher</span>",

"Exploring the beauty, history, traditions, and people of China through the eyes of Discovery was even more incredible than I could have imagined.<br/><span>Tiffany L., Student</span>",

"I love the outdoors and being with nature. My journey was truly a great experience.<br/><span>Linda R., Teacher</span>",

"Getting up close and personal with lions, cheetahs, leopards, and elephants was incredible.<br/><span>Danae S., Student</span>",

"My daughter definitely is more aware of historical events and our environment as a result of her Discovery trip to Washington, D.C.<br/><span>Julie G., Parent</span>",

"It's really important for students to experience things by actually being there, not just reading about it in a book. That's what Discovery is all about.<br/><span>Carol M., Teacher</span>",

"My journey was not about finding the differences between American and Asian culture, it was about embracing both ways of life.<br/><span>Cory B., Student</span>",

"The social studies realm of what we did on our trip was remarkable; the science aspect was unlike anything else in the world.<br/><span>Jason C., Teacher</span>",

"Diving with sharks. Hanging out with cheetahs. Extreme, unforgettable experiences!<br/><span>Mary O., Student</span>",

"Every teacher should experience a Discovery journey with their students. The sense of growth, empowerment, and the feeling of connection is unbelievable.<br/><span>Brett H., Teacher</span>",

"My friends couldn't believe I camped at the Great Wall and learned kung fu from masters.<br/><span>Maha E., Student</span>"

  ]
};

function setOpacity(el, value) {
    el.style.opacity = value / 100;
    el.style.filter = "alpha(opacity=" + value + ")";
}

function unfadeText(el, tg) {
    var v = el.style.opacity * 100 + 1;
    if (v > 100) {
        setOpacity(el, 100);
        setTimeout(bundleFunction(null, fadeText, [el, tg]), 7000);
        return;
    }
    setOpacity(el, v);
    setTimeout(bundleFunction(null, unfadeText, [el, tg]), 10);
}

function fadeText(el, tg) {
    var v = el.style.opacity * 100 - 1;
    if (v < 0) {
        setOpacity(el, 0);
        rotateText(el, tg);
        //or... setTimeout(bundleFunction(null, rotateText, [el, tg]), NUMBER);
        return;
    }
    setOpacity(el, v);
    setTimeout(bundleFunction(null, fadeText, [el, tg]), 10);
}

function bundleFunction(context, func, args) {
    context = context || null;
    if (typeof func == "string" && context)
        func = context[func];
    if (!args)
        args = [];
    else if (!(args instanceof Array))
        args = [args];
    return function () {
        return func.apply(context, args);
    };
}

 
