// *****************************************
// *********** DOCUMENT ONLOAD *************
// *****************************************
$(document).ready(function() {

    //If user logged in, hide transition background
    if ($("table.ControlPanel").length < 1) {
        $('#divFlashBg').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%" id="flashROABg" align="left"><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="/flashROABg.swf" /><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="salign" value="lt" /><param name="bgcolor" value="#ffffff" />	<embed src="/flashROABg.swf" quality="high" scale="exactfit" salign="lt" bgcolor="#ffffff" width="100%" height="100%" name="flashROABg" align="left" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" /></object>');
    }
    else {
    	$("#divFlashBg").toggle();
	    $('#divFlashBg').html('<style type="text/css">body { background-image: url("/Portals/_default/Skins/Airport/images/bg/imgBodyBg_6.jpg"); background-position: center center; background-attachment: fixed; background-repeat: no-repeat; }</style>');
	}
    
    //Insert URL to maintain W3C compliance
    $('#aGoogleLink').attr('href', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=5202+Aviation+Drive,+N.W.,+Roanoke,+VA+24012&sll=37.0625,-95.677068&sspn=34.671324,70.576172&ie=UTF8&ll=37.324765,-79.968688&spn=0.008498,0.017231&z=16&iwloc=A');

    //Set SubNav Mouseovers
    $("#divNavigation p").each(
    function(intIndex) {
        $(this).hover(
            function() { $(this).removeClass("pNavSubLinkOff").addClass("pNavSubLinkOn"); },
            function() { $(this).removeClass("pNavSubLinkOn").addClass("pNavSubLinkOff"); }
        );
    });
    $("#divNavigation div").each(
    function(intIndex) {
        $(this).hover(
            function() { $(this).removeClass("pNavSubLinkOff").addClass("pNavSubLinkOn"); },
            function() { $(this).removeClass("pNavSubLinkOn").addClass("pNavSubLinkOff"); }
        );
    });

    //Load special bulletins slider
    $('#divSpecialSlider').html('<iframe src="/slider/slider.aspx" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>');

    //Load tabs
    //$('#tdFlights').html('<iframe src="/flights/Flight.aspx?loc=' + location.href + '&css=yes" width="100%" height="380px" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>');
    $.ajax({ url: "/flights/Flight.aspx?loc=" + location.href, cache: false, success: function(code) { $("#divFlights").html(code); $('#divFlight > ul').tabs(); } });
    
    //The deals on the homepage often go on for too long. This introduces a mechanism to view a short version and click for a longer version
    HandleLongHomeDeals()
});

// *****************************************
// *****************************************
// *****************************************

function SiteSearch() {
    location.href = "/SearchResults.aspx?Search=" + $("#divSearchContainer table input").attr("value");
}

function HandleLongHomeDeals() {
    $("p.homeDeal").each(
        function(intIndex) {
            var content = $(this).html();
            var words = content.split(" ");
            if (words.length > 30) {
                var c2 = '<p class="homeMore" style="display: none;">' + content + '</p>';
                var c1 = '<p class="homeMain" title="Click to Read More">';                

                for (i = 0; i < 30; i++) {
                    c1 = c1 + words[i] + ' ';
                }

                c1 = c1 + ' ...</p>';
                $(this).html("<div>" + c1 + c2 + "</div>");
            }
        });
        $('p.homeMain').click(function() {
            $(this).hide();
            $(this).parent().children("p.homeMore").show("slow");
        });
}
