$(window).load(function () {
    
    //    $("div#makeMeScrollable").smoothDivScroll({
    //        autoScroll: "onstart",
    //        autoScrollDirection: "endlessloopright",
    //        autoScrollStep: 1,
    //        autoScrollInterval: 15,
    //        visibleHotSpots: "always",
    //        scrollInterval:5,
    //        scrollStep: 5
    //    });
})




$(document).ready(function () {
    $("#showy").carousel();
//    $("div.scrollWrapper").mouseover(function () {
//        $("#makeMeScrollable").smoothDivScroll("stopAutoScroll");
//    }).mouseout(function () {
//        $("#makeMeScrollable").smoothDivScroll("startAutoScroll");

//    });

//    $("div.scrollingHotSpotLeft").mouseout(function () {
//        $("#makeMeScrollable").smoothDivScroll("startAutoScroll");

//    });
//    $("div.scrollingHotSpotRight").mouseout(function () {
//        $("#makeMeScrollable").smoothDivScroll("startAutoScroll");

//    });

    $("#histLink").click(function () {
        var $this = $(this);
        var histHolder = $("<div id='.uimodal-output'></div>").hide();
        $("body").append(histHolder);
        histHolder.load($this.attr("href"), null, function () {
            histHolder.dialog({
                title: 'Roch Castle - Further History',
                modal: true,
                autoOpen: true,
                height: 230,
                minWidth: 600,
                minHeight: 400,
                maxHeight: 600,
                close: function (ev, ui) {
                    $(this).remove();
                }
            })
            return false;
        });
        return false;
    });


    //    $("input:submit, a, button", ".bookdiv").button();
    $("#showcase").imageShowcase();
    $("#showcaseProjects").articleShowcase({ autoScroll: false });
    //$("#diag").dialog({ autoOpen: true });
    //alert($("a.single_image").length);


    //    $('#mask-gallery').simplyScroll({
    //        frameRate: 20,
    //        speed: 3,
    //        autoMode: 'loop'
    //    }); 

    var pathname = window.location.pathname;

    var $newdiv1 = $('<div id="largeMap"/>'),
    newdiv2 = document.createElement('div'),
    existingdiv1 = document.getElementById('#map');









    //    <![CDATA[
    var markerDefinitions;
    if (pathname == "/Venue/Penrhiw-Priory/Map") {

        $('#map').append($newdiv1);
        //        $('.body').append($newdiv1, [newdiv2, existingdiv1]);
        markerDefinitions = [{ "address": "SA62 6PG", "html": "<p>Penrhiw St Davids<br />Haverfordwest<br />Pembrokeshire<br />SA62 6PG<br />United Kingdom</p><p><a href='http://www.retreatsgroup.com/Venue/Penrhiw-Priory/'>Details</a> <a href='http://www.retreatsgroup.com/Venue/Penrhiw-Priory/'>Availability/Book</a>"}];
    }
    if (pathname == "/Venue/Roch-Castle/Map") {

        $('#map').append($newdiv1);
        //        $('.body').append($newdiv1, [newdiv2, existingdiv1]);
        markerDefinitions = [{ "address": "SA62 6AQ", "html": "<p>Roch Castle<br />Church Road<br />Nolton<br />Pembrokeshire<br />SA62 6AQ<br />United Kingdom</p><p><a href='Venue/Roch-Castle'>Details</a> <a href='http://www.retreatsgroup.com/Venue/Roch-Castle/'>Availability/Book</a>"}];
    }

    $('#largeMap').gMap({ markers: markerDefinitions, zoom: 17, maptype: G_SATELLITE_MAP });


    $(function () {
        var path = location.pathname.substring(1);
        if (path)
            $('#topnav a[href$="' + path + '"]').attr('class', 'selected');
    });


    $(function () {
        var path = location.pathname.substring(1);
        if (path)
            $('.contentSideNav a[href$="' + path + '"]').attr('class', 'selectedText');
    });
    $(".btnBookVenue").bind('click', function () {
        var $this = $(this);
        var venueName = $this.attr("title");
        var outputHolder = $("<div id='.uimodal-output' class='bookingDialg'></div>").hide();
        $("body").append(outputHolder);
        var diagHeight = 585;
        var diagWidth = 850;
        if (ie < 8) {
            diagHeight = 620;
            diagWidth = 850;
        }
        //alert(diagWidth + "  " + diagHeight)
        outputHolder.load($this.attr("href"), null, function () {
            outputHolder.dialog({
                title: 'Retreats Group Ltd.',
                modal: true,
                autoOpen: true,
                height: diagHeight,
                minWidth: diagWidth,
                minHeight: diagHeight,
                maxHeight: diagHeight,
                close: function (ev, ui) {
                    $(".calenderSelectDiv").remove();
                    $(this).remove();
                },
                buttons: {
                    'Prev': function () {
                        return false;
                    },
                    'Next': function () {
                        return false;
                    }

                }
            })
            initialiseBooking();
        });
        return false;
    });

    $("ul#topnav li").hover(function () { //Hover over event on list item
        $(this).css({ 'background': '#1376c9 repeat-x' }); //Add background color and image on hovered list item
        $(this).find("span").show(); //Show the subnav
    }, function () { //on hover out...
        $(this).css({ 'background': 'none' }); //Ditch the background
        $(this).find("span").hide(); //Hide the subnav
    });


    //    $(".dropdown").each(function () {
    //        $(this).parent().eq(0).hoverIntent({
    //            timeout: 100,
    //            over: function () {
    //                var current = $(".dropdown:eq(0)", this);
    //                current.slideDown(100);
    ////                alert("hover over");
    //            },
    //            out: function () {
    //                var current = $(".dropdown:eq(0)", this);
    //                current.fadeOut(200);
    ////                alert("hover out");
    //            }
    //        });
    //    });
    //    $(".dropdown a").hover(
    //             function () {
    //                        $(this).stop(true).animate({
    //                            paddingLeft: "10px"
    //                        },
    //                            500,
    //                            "easeOutBack"

    //                     );
    ////                        alert("hover1");
    //                    },
    //             function () {
    //                  $(this).stop(true).animate({
    //                      paddingLeft: "0"
    //                  },
    //                    500,
    //                   "easeOutBounce"
    //                   
    //                  );
    ////                  alert("hover2");
    //              }
    //        );
    $("a.single_image").fancybox({
        showNavArrows: true
    });
});

var ie = (function () { var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while (div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0]); return v > 4 ? v : undef; } ()); 


