﻿/**
 * @class Location logic
 * depends on jQuery, jQuery-cookie, and sunweb static "logic" object
 */
var locDetails = function($) {

    /**
     * @namespace Private methods and properties
     */
    var priv = {

        /**
         * @private
         */
        countryId: null,

        /**
         * @private
         */
        regionId: null,

        /**
         * @private
         */
        randomBoxId: null,

        /**
         * @private
         */
        locationType: null,

        openLightbox: function(id, options) {
            var lightbox = Lightbox.CreateCached(id, options);
            lightbox.Show();
        },

        locationPageReady: function() {
            priv.regionId = $("#regionId").val();
            priv.randomBoxId = $("#randomBoxId").attr("name");
            if ($("#locationType").val() != null) {
            priv.locationType = $("#locationType").val().toLowerCase();
            }

            $('div.bestreviews ul, div.lastminute ul').children("li").hover(function() {
                $(this).addClass("hover");
            }, function() {
                $(this).removeClass("hover");
            }).bind("click", function() {
                //redirect to the correct page
                var url = $(this).find('a').attr("href");

                document.location.href = url;
                //prevent event bubbling
                return false;
            });

            $("#result-list>li").hover(function() {
                $(this).addClass('hover');
            }, function() {
                $(this).removeClass('hover');
            });
        },

        destinationsPageReady: function() {
            $("div.destination-block h2").bind("click", function(e) {
                location.href = $('a.image-block', $(this).parent()).attr('href');
            });


            $('div.destination-block h2').hover(function() {
                $(this).addClass('destination-hover');
            }, function() {
                $(this).removeClass('destination-hover');
            });
        }
    };

    /**
     * @scope locDetails
     */
    return {

        showPracticalInformation: function(url) {
            var id = 'pPracticalInfo';
            var config = null;
            if ($('#' + id).html() == '') {
                config = {
                    container: document.getElementById(id),
                    width: '623px',
					contentUrl: url + " #practical-information-popup"
                };
            }
            priv.openLightbox(id, config);
        },

        showDestinationsPopup: function(url) {
            var id = 'pDestinations';
            var config = {
                contentUrl: url + " #result-destination-popup",
                container: document.getElementById(id),
                width: '250px'
            };
			priv.openLightbox(url, config);
        },

        /**
         * should be triggered on page ready
         */
        OnReady: function() {
            priv.countryId = $("#countryId").val();

            switch ($('body').attr('class')) {
                case 'destination-location':
                    priv.locationPageReady();
                    break;
                case 'destination-overview':
                    priv.destinationsPageReady();
                    break;
            }

            $('#location-ribbon div.pricetag span.price').bind("click", function() {
                location.href = $('span.lmonth', $(this).parent()).text();
            });

            //copy the ups-texts to the lightbox list
            $("#usp-texts-lightbox").html($("#usp-texts").html());

            $("#divVideo").bind("click",
				function(evt) {
					alert('destination movie');
					Analytics.TrackPlayer($(this).find("object"));
				}
            )
        }
    };
} (jQuery);

