/*
* Code initialisation based here
*/

(function($) { 
$.ti = $.prototype = {
    
    requiredPlugins: {
        tiTicker: true,
        jCarouselLite: true 
    },
    
    /* Initialise common page functions */
    initCommon: function() {
        // Clear inputs
        $("form").tiClearInputs();
        
        // Hot offers - vertical ticker
        if($.ti.requiredPlugins.tiTicker) {
            var newsTicker = $('#verticalTicker');
            if(newsTicker.length) {
                newsTicker.tiTicker();      
            }
        }
            
        // Carousel
        if($.ti.requiredPlugins.jCarouselLite) {
            var carousel = jQuery('.scroller');
            if(carousel.length) {
                carousel.jCarouselLite({
                btnNext: ".offersNext",
                btnPrev: ".offersPrevious"
                });   
            }
        }
        
        // Plan visit
        var tiAccordion = $('#planVisit');
        if(tiAccordion.length) {
            $(tiAccordion).accordion({                
                header: 'h3',
                animated: 'bounceslide'
            }).bind('accordionchangestart', function(event, ui) {                
                $('.ui-icon', ui.newHeader).fadeOut(500);
                $('.ui-icon', ui.oldHeader).fadeIn(500);                
            });
           $("li:first > h3 > .ui-icon", tiAccordion).fadeOut();
        }
    },
    
    initItinerary: function() {
        $.ti.panel.renderPanel();
        
        // Check for in page offers
        //if($('#offersPage').length) {
            $.ti.addActivities.init();
        //}
        
        // Check for Public trip search
        if($('#likeTrip').length) {
            $.ti.likeTrip.init();
        }

    },

    // Only place I can put this that guarantees other initialisers
    // can find it...
    makeSafeOnclickStr: function(rawStr) {
        if (rawStr)
            return rawStr.replace('\'', '').replace('\"', '').replace(')', '');
        else
            return "";
    }
};

// Trip planner data stored here.
$.ti.tripData = false;

$(document).ready(function(){
   // $.ti.initCommon();
    // Todo - we can exclude IE6 from this - IE6 check sits in ti-brandify.js already when we merge.
    $.ti.initItinerary();
});

})(jQuery);
