﻿/**
 * @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,

        openLightbox: function(id, options) {
            var lightbox = Lightbox.CreateCached(id, options);
            lightbox.Show();
        },

        locationPageReady: function() {
            priv.regionId = $("#regionId").val();
            priv.randomBoxId = $("#randomBoxId").attr("name");

            $('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;
            });

            $('.hrefShowLocationPopup').bind("click", function() {
                locDetails.showLocationPopup(this);
                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 {

        showLocationReadMore: function() {
            $('#location-read-more').show();
            priv.openLightbox('location-read-more-lightbox', {
                width: "623px",
                container: document.getElementById('location-read-more-lightbox')
            });
        },

        /* old lightbox, replaced by showLocationPopup
        showSkipasInfo : function(){
        priv.openLightbox('skipas-read-more-lightbox', {
        container: document.getElementById('skipas-read-more-lightbox'),
        width: '623px',
        clone: false
        });
        },
        */

        showLocationPopup: function(el) {
            var id = 'pLocationPopup';

            if (typeof (el) != "undefined" && el) {
                id += $(el).attr('rel');
            }

            var config = null;

            if ($('#' + id).html() == '') {
                config = {
                    container: document.getElementById(id),
                    width: '623px',
                    contentUrlHasScript: true
                };
                if (typeof (el) != "undefined" && el) {
                    var anticacheParam = '&anticache=' + (new Date()).getTime();
                    config.contentUrl = $(el).attr('href') + anticacheParam + "#popup";
                }
            }

            priv.openLightbox(id, config);
        },

        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());
        }
    };
} (jQuery);

function readMoreLess(a) {
if(a=="show")
		{
	document.getElementById("shortText").style.height = 100 + "%";
	document.getElementById("read_less").style.display = "block";
	document.getElementById("read_more").style.display = "none";
		}	
else{
	document.getElementById("shortText").style.height = 150 + "px";
	document.getElementById("read_less").style.display = "none";
	document.getElementById("read_more").style.display = "block";
	}
				
}
