/*jslint white: true, browser: true */
/*jQuery */
/*global $: false, jQuery: false */
/* IE */
/*global ActiveXObject: false,  __flash_unloadHandler: true,  __flash_savedUnloadHandler: true */
/* WebTrends */
/*global dcsMultiTrack: false */

/* ################  External Links  ################ */
function externalLinks() {
    var intLink = /\/londonrestaurantfestival/;
    $("a").filter(function () {
        return !intLink.test($(this).attr("href"));
    }).add("a.ext, a[href$='mp3'], a[href$='pdf'], a[href$='doc']").not(".gallery").attr({
        title: 'Link will open in a new window',
        target: '_blank'
    });
}
/* ################  End External Links  ################ */

/* ################ Flash ################ */
function drawTV() {
    if (whichVid && whichVid !== "" && $("#videolarge").size !== 0) {
        var w, h, xml = whichVid + ".xml";
        $("#videolarge").flashembed({
            src: "http://static.visitlondon.com/assets/video/LRF-vl-video-player-large.swf?playerSize=SL&xmltouse=" + xml,
            width: '540',
            height: '327',
            play: "true",
            wmode: "transparent",
            scale: "noscale",
            salign: "rt",
            version: [8, 0]
        });
    }
}
/* ################ End Flash ################ */
/*
function setupMultiPanel() {
    $("#selector-panel").addClass('withJS');
    $("#selector-panel").append('<ul id="selector-controls"></ul>');
    $("#selector-window > div").hide().css('position', 'absolute').css('top', '0px').css('left', '0px').each(

    function (n) {
        $("#selector-controls").append('<li id="link' + n + '">' + this.title + '</li>');
        $("#link" + n).click(function (event) {
            multiPanel(n);
        });
    });
    multiPanel(0);
}
*/

$("#p38135 .panel-middle").hide();
$("#p38135 .panel-head").addClass('showMore').attr('tabindex', '0').bind('click keypress', function (event) {
        if (event.type == 'keypress' && event.which != KEY_ENTER) {
            return false;
        }
        $(this).toggleClass('showMore').toggleClass('showLess');
        $(".panel-middle", $(this).parents('div.secondary')).slideToggle(1000, function () {
            $(this).find("a:first").focus();
        });
    });




function fetchVenue(venueID) {
 var url = 'https://' + window.location.host + '/api/json/venue/' + venueID,
        params = {};
    $.getJSON(url, params, function (data) {
    // THIS IS VERY FRAGILE
        if (data.venue.name && data.venue.name != "") {
            $("#q1").val(data.venue.name);
        }
        if (data.venue.addressLine1 && data.venue.addressLine1 != "") {
            $("#q2").val(data.venue.addressLine1);
        }
        if (data.venue.addressLine2 && data.venue.addressLine2 != "" && data.venue.addressLine2) {
            $("#q3").val(data.venue.addressLine2);
        }
        if (data.venue.locality && data.venue.locality != "") {
            $("#q4").val(data.venue.locality);
        }
        if (data.venue.postcode && data.venue.postcode != "") {
            $("#q5").val(data.venue.postcode);
        }
        if (data.venue.telephone && data.venue.telephone != "") {
            $("#q7").val(data.venue.telephone);
        }
        if (data.venue.website && data.venue.website != "") {
            $("#q8").val(data.venue.website);
        }
        if (data.venue.emailAddress && data.venue.emailAddress != "") {
            $("#q9").val(data.venue.emailAddress);
        }
        if (data.venue.descriptions.times && data.venue.descriptions.times != "") {
            $("#q10").val(data.venue.descriptions.times);
        }
    });
    $(".restDetails input, .restDetails textarea").removeClass('loading');
}


(function ($) {
    $.fn.createTabs = function () {
        return this.each(function () {
            var tID = this.id,
                headerCopy = '<div class="tabs-header"><ul>';
            $("#" + tID + " ul.tabs li>div").each(function () {
                headerCopy += '<li id="' + this.id + '-tab"><a class="tablnk">' + $(this).children('h3').text() + '</a></li>';
            });
            headerCopy += '</ul></div>';
            $("#" + tID + " .panel-head").after(headerCopy);
            $("#" + tID + " .tabs-header ul li:first").addClass('first').addClass('current');
            $("#" + tID + " .tabs-header ul li:last a").addClass('last');
            $("#" + tID + " ul.tabs li>div>h3").remove();
            $("#" + tID + " ul.tabs li>div").hide();
            $("#" + tID + " ul.tabs li:first>div").show();
            $("#" + tID + " .tablnk").css('cursor', 'pointer').click(function (event) {
                $("#" + tID + " .tabs-header .current").removeClass('current');
                $(this).parent().addClass('current');
                $(this).blur();
                $("#" + tID + " ul.tabs li>div").hide();
                var theTab = $("#" + tID + " .tabs-header .current").attr('id').replace('-tab', ''),
                    whichTab = "#" + theTab;
                $(whichTab).show();
                return false;
            });
        });

    };
})(jQuery);


function mycarousel_initCallback(carousel) {
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto(0);
    });
    carousel.clip.hover(function () {
        carousel.stopAuto();
    },

    function () {
        carousel.startAuto();
    });
}

/* ################ Loader ################ */
$(document).ready(function () {
    setupMultiPanel();
    $("#selector-window .vlSnTeaserSuperhero span+br").remove();

    $('#lrf-partners .vlSnTitleThumbMedium').insertBefore("#lrf-partners .panel-middle .clear-both");
    $('#lrf-partners .AutoIndexSlot').remove();
    $('#lrf-partners .vlSnTitleThumbMedium').wrapAll('<ul></ul>').wrap('<li></li>');
    $('#lrf-partners ul').jcarousel({
        auto: 2,
        scroll: 1,
        easing: 'linear',
        wrap: 'both',
        initCallback: mycarousel_initCallback
    });

    $(".vlSnTabsPanel").createTabs();

});