function pageInit(){
    $('.print a').click(function(){
        window.print();
        return false;
    });
}
function rightOffers(){
    //$('.rightOffers li:last,.rightOffers li:first').addClass('noBG');
    $('.rightOffers li:first').addClass('gold');
}

function flashTitles(){
    $.sifr({ build: 436, version: 3, path: '/flash/' , save: true});
    $('h1').sifr({font: 'gotham_lb', width: 450});
    $('h2').sifr({font: 'gotham_lb', width: 400});
    $('.subContent h2').sifr({font: 'gotham_lb', width: 800});
    $('.cruisePanel h2').sifr({font: 'gotham_db', width: 300});
    //$('h4').sifr({font: 'gotham_db', width: 300});
    $('ul.panels a').sifr({font: 'gotham_db', width: 280});
}
function topNavDisplay(){
    //nav adjust
    $('#topNav li:first').addClass('firstNav');
    //show it
    $('#topNav ul:first').oneTime(1000, function() {
        $(this).show('slide', { direction: 'down' }, 700, function(){
            $(this).parent().css('z-index','100');
            subNav();
        });
    });
}
function topNavHide(){
    $('#topNav ul:first').fadeOut().parent().css('z-index','1');
    $('.printMe').removeClass('printMe');
    $('.noPrint').removeClass('noPrint');
}
function topNavSort(){
    $('#topNav ul:first').show().parent().css('z-index','100').end().children('li:first').addClass('firstNav');
    subNav();
}
function subNav(){
    $('#topNav li').each(function(){
        var w = $(this).width();
        //padding=4 so...
        w = w -8;
        $(this).children('ul').children().children().width(w);
    });
	$('.nav').superfish({
		animation : { opacity:'show', height:'show'},
		speed:'fast'
	});
}

function picToBG(src, target){
    var pic = src.find('img:first').attr('src');
    target.css('background-image','url('+pic+')');
}
function overlay(olContent, olOffers)
{
    $('#overlay #left').removeClass('onBoard').addClass('cruiseHL');
    $('#overlay #right').show();
    if (olOffers == "null"){
        $('#overlay #right').hide();
        $('#overlay #left').removeClass('cruiseHL').addClass('onBoard').css('background-image','none');
    }
    //$('#overlay').children('#left').children('#col1').html(olContent).append('<p class="closeBtn clicker">Return to homepage</p>').end().end().children('#right').html(olOffers).end();
    $('#overlay').children('#left').children('#col1').html(olContent).end().end().children('#right').html(olOffers).end();
    //style offers
    rightOffers();
    
    //bg img
    picToBG($('.cruiseHL'), $('.cruiseHL'));
    
    //sifr rendering for slow browsers and to change h2 colours
    if($.browser.msie){
        $('#overlay h2').sifr({font: 'gotham_lb', width: 380, fontSize: '22'}).show();
        $('ul.panels a').sifr({font: 'gotham_db', width: 280, fontSize: '18'});
        
        if($.browser.version=="6.0"){
            $('#col1').css('opacity', .9);
        }
    } else {
    //just change h2 colours
        $('#overlay h2').sifr({font: 'gotham_lb', width: 380});
        $('ul.panels a').sifr({font: 'gotham_db', width: 280});
    }
    
    //show it!
    $('#overlay').show('slide', { direction: 'down' }, 700);
    $('ul.panels li').each(function(){
        //linking from whole of <li> to help IE with SIFR
        var href = $(this).children('a').attr('href');
        $(this).append('<div class="clicker"></div>');
        $(this).children('div.clicker').click(function(){
            window.location=href;
        });
    });

    topNavDisplay();

    //close link in content
    $('p.closeBtn').click(function(){
        $('#overlay').hide('slide', { direction: 'down' }, 600);
        topNavHide();
    });
    //print styling
    $('#overlay').addClass('printMe');
    $('#mainBox').addClass('noPrint');
}

function itinOverlay(ic)
{
    $('#overlay').children('#top').html(ic);
    
    if($.browser.msie){
        $('#overlay h2').sifr({font: 'gotham_db', width: 350, fontSize: '19'});
    } else {
    //just change h2 colours
        $('#overlay h2').sifr({font: 'gotham_db', width: 350});
    }
    //re-arrange content for overlay panel
    var tc = $('#top');
    var bg = tc.find('img:first').attr('src');
    tc.css('background-image','url('+bg+')');
    var textBlok = tc.find('p');
    $('#btm').html(textBlok);
       
    //show it!
    if (!openOv){
    $('#overlay').show('slide', { direction: 'down' }, 700);
    openOv = true;
    }
}

function mapSpots(){
    $('.hotspot').each(function(h){
        $(this).click(function(){
            var hsContent = $('#itinMain li.clicker:eq('+h+')').children().clone();
            itinOverlay(hsContent);
            $('#itinMain li.clicker').removeClass('sel');
            $('#itinMain li.clicker:eq('+h+')').addClass('sel');
        });
        $(this).hover(function(){
            $(this).addClass('active');
        }, function(){
            $(this).removeClass('active');
        });
    });
}
function feedData(pageOm){
            //tag every fourth row to divide data by package ID
            $(function(){
                newRowAt = 5;
                inc = newRowAt - 1;
                $('#rawData tr').each(function(i){
                    if(newRowAt == i + 1){
                        $(this).addClass('fourthRow');
                        newRowAt += inc;
                    }
                });
            });
            $('#rawData tr.fourthRow').each(function(r){
                $('#showFeed').append('<tr id="row'+r+'"></tr>');
                var pID = $(this).children('td:first').text();
                var strLink = 'http://www.royalcaribbean.co.uk/booking/getDepartureInfo/checkAvailability.do?'+pID+'&cid=UKRCIweb_GR_pricesDates_'+pageOm;
                
                var date = $(this).children('td:eq(1)').text();
                var oPrice = $(this).children('td:last').text();
                var iPrice = $(this).prev().children('td:last').text();
                var dPrice = $(this).prev().prev().children('td:last').text();
                var bPrice = $(this).prev().prev().prev().children('td:last').text();
                
                
                $('#showFeed #row'+r).append('<td>'+date+'</td>').append('<td>'+iPrice+'</td>').append('<td>'+oPrice+'</td>').append('<td>'+bPrice+'</td>').append('<td>'+dPrice+'</td>')
                .append('<td><a class="bookBtn" target="_blank" href="'+strLink+'"></a></td>');
                
            });
            $('.feedData tr:odd td').addClass('odd');
            $('.feedData tr').each(function(){
                $(this).children('td:last').addClass('lastTd');
            });
            $('#rawData').remove();
            //scroller
                $('.scrollMe').jScrollPane({
                    showArrows: true,
                    arrowSize: 10,
                    scrollbarWidth: 16,
                    scrollbarMargin: 0,
                    wheelSpeed: 20
                });
}

function videos(){
		    var allVids = ['rockwall_V.swf', 'golf_V.swf', 'fitness_V.swf'];
		    $('#videos div:first').flash({ 
                    swf: '/flash/vids/'+allVids[0],
                    width: 420,
                    height: 180,
                    hasVersion: 8,
                    params: {wmode: 'opaque'}
                });
		    $('#videos h3').each(function(i){
		        $(this).click(function(){
		            $(this).next('div').flash({ 
                        swf: '/flash/vids/'+allVids[i],
                        width: 420,
                        height: 180,
                        hasVersion: 8,
                        params: {wmode: 'opaque'}
                    });
                    $(this).siblings().next('div').html('<p></p>');
                });
		    });
}
