// Content Fixes and Interactions
// Beware of Fake Code: Fake Google Map Insertion
//ChooseLanguage
                function ChooseLanguage(){
                    $(".sgmPopUp").appendTo(".sgmBoxForModal");
                    var ModalHeight = $(".sgmPopUp").height();
                    var modalTopPosition = - ModalHeight/2;
                    $(".sgmPopUp").css({"margin-top" : modalTopPosition});
                    var modal =$("#wnModal1");
                    if (modal.length) $(modal).jqm({modal: true});
                     $(modal).jqmShow();
                };
function initialize() {

        var latlng = new google.maps.LatLng(53.92, 27.65);
		var myOptions = {      zoom: 12,      center: latlng,      mapTypeId: google.maps.MapTypeId.ROADMAP    };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        var contentString = '<div id="content"><img src="bullit_red.gif"/><b>Uluru</b>, sandstone rock formation in the southern part of the Northern Territory, central Australia. It lies 335 km (208 mi)</div>';
var infowindow = new google.maps.InfoWindow({    content: contentString});
var image = new google.maps.MarkerImage('bullit_red.gif',
                                                                 new google.maps.Size(20, 32),
				new google.maps.Point(0,0),
				 new google.maps.Point(0, 32));
 var shadow = new google.maps.MarkerImage('ico_plus.gif',
				      new google.maps.Size(37, 32),
					new google.maps.Point(0,0),
					 new google.maps.Point(0, 32));
var marker = new google.maps.Marker({      position: latlng,       map: map,   shadow: shadow,        icon: image,     title:"Hello World!"});
var latlng2 = new google.maps.LatLng(55, 29);
var marker2= new google.maps.Marker({      position: latlng2,       map: map,      title:"2"});
var latlng3 = new google.maps.LatLng(52, 6);

google.maps.event.addListener(marker, 'click', function() {  infowindow.open(map,marker);});


//alert("0");
var bounds=new google.maps.LatLngBounds(latlng, latlng);
//alert(bounds);

bounds.extend(latlng3);
bounds.extend(latlng2);
var marker= new google.maps.Marker({      position: latlng3,       map: map,      title:"3"});
google.maps.event.addListener(marker, 'click', function() { alert('3');});
map.fitBounds(bounds);

 }


(function($) {
    $.extend({
        equalHeight: function() {
            $('.sgmEqual-height').children().height('auto');
            $('.sgmEqual-height').each(function() {
                var maxHeight = 0;
                $(this).children().each(function() {

                    if ($(this).height() > maxHeight) {

                        maxHeight = $(this).height();
                    }

                });

                $(this).children().height(maxHeight);

            });
        }
        ,
        equalHeight2: function() {

            var lefts = $("ul.sgmCatalog-b li.sgmLeftBlock .sgmBlock");
            var rights = $("ul.sgmCatalog-b li.sgmRightBlock .sgmBlock");
            var leftTitles = $("ul.sgmCatalog-b li.sgmLeftBlock h2");
            var rightTitles = $("ul.sgmCatalog-b li.sgmRightBlock h2");
            for (var i = 0; i < lefts.length; i++) {
                var leftElement = lefts.get(i);
                var rightElement = rights.get(i);
                var leftTitle = leftTitles.get(i);
                var rightTitle = rightTitles.get(i);
                if (leftElement && rightElement) {
                    var height = Math.max($(leftElement).height(), $(rightElement).height());
                    $(leftElement).height(height);
                    $(rightElement).height(height);
                }
                if (leftTitle && rightTitle) {
                    var heightTitle = Math.max($(leftTitle).height(), $(rightTitle).height());
                    $(leftTitle).height(heightTitle);
                    $(rightTitle).height(heightTitle);
                }
            }

        }
        ,

        toggleBlock: function() {
            var openBtn = $('.sgmProd-sel-b .sgmTopBlock .sgmOpen-btn');
            var closeBtn = $('.sgmProd-sel-b .sgmBotBlock .sgmClose-btn');
            var slideBlock = $(".sgmProd-sel-b .sgmMidBlock");
            var botBlock = $(".sgmProd-sel-b .sgmBotBlock");
            openBtn.click(function() {
                slideBlock.slideDown(800, function() {
                    closeBtn.show();
                });
                botBlock.animate({
                    "height": "19px"
                });
                /*if ($("select.productSelect").length) $("select.productSelect").selectbox();*/
                return false;
            });

            closeBtn.click(function() {
                slideBlock.slideUp(800, function() { });
                closeBtn.hide();
                botBlock.animate({
                    "height": "9px"
                }, 800);
                return false;
            });
        },
        dropDown: function() {
            var ddContainer = $(".sgmTopL-b .sgmTop-n li.sgmParent");
            ddContainer.hover(
                        function() {
                            $(this).children(".sgmQuick-n").width($(this).width() + 10);
                            $(this).children(".sgmQuick-n").show();
                        },
                        function() {
                            $(this).children(".sgmQuick-n").hide();
                        }
                    );
        }
        ,
        /*chooseLanguage: function(){

            $(".sgmHomePage .sgmOverlay").height($(document).height());
        var popUpTop = $(".sgmHomePage .sgmPopUp").height() / 2;
        $(".sgmHomePage .sgmPopUp").css({'margin-top': - popUpTop});
        $(".sgmHomePage .sgmOverlay").show();
        $(".sgmHomePage .sgmPopUp").show();

            $(".sgmPopUp .sgmContent ul.sgmBlock li h5 a").click(function(){
        $(".sgmHomePage .sgmOverlay").hide();
        $(".sgmHomePage .sgmPopUp").hide();    
        });
          
        }, */

        init: function() {
			if($.browser.msie && $.browser.version > 8) {
				Cufon.set('engine', 'canvas');
			}
            Cufon.replace('.sgmTop-b p.sgmSlogan');
            Cufon.replace('.sgmTop-b p.sgmTitle');
            Cufon.replace('.sgmBot-title');
            //Cufon.replace('h1');
            Cufon.replace('.sgmCycle-b li p');



            jQuery('#mycarousel').jcarousel({
                start: 3
            });

            $(".SgmProduct-tabs").tabs();
            $(".sgmPromoTabs").tabs();
            $('.SgmProduct-tabs > .ui-tabs-nav > li > a').click(function() {
                $.equalHeight();

            });
            $("#overnachten-ja").change(function() {
                $("#aantal-personen").parent("dd").prev().removeClass("sgmDisable");
                $("#aantal-personen").removeAttr("disabled");
            });
            $("#overnachten-nee").change(function() {
                $("#aantal-personen").parent("dd").prev().addClass("sgmDisable");
                $("#aantal-personen").attr("disabled", "disabled");
            });

            $(".sgmAccordion").accordion({
                autoHeight: false
            });

            $(window).resize(function() {
                $(".sgmHomePage .sgmOverlay").height($(document).height());
            });

            $(window).load(function() {

                $.equalHeight();
                $.equalHeight2();
                // Selectbox
                if ($("select.productSelect").length) $("select.productSelect").selectbox();


                $.toggleBlock();
                $.dropDown();
                //$.chooseLanguage();

                // jqModal
                var modal = $("#wnModal");
                if (modal.length) $(modal).jqm();


                //sgmResponse
                $(".sgmResponse .sgmJa").change(function() {
                    $(".sgmResponse dd a").removeClass("sgmPlain-l");
                    $(".sgmResponse dd a").addClass("sgmGrey-l");

                });
                $(".sgmResponse .sgmNee").change(function() {
                    $(".sgmResponse dd a").removeClass("sgmGrey-l");
                    $(".sgmResponse dd a").addClass("sgmPlain-l");

                });

                $(".sgmResponse dd a").click(function() {
                    if ($(this).hasClass("sgmPlain-l")) {
                        $(".sgmPopUp").appendTo(".sgmBoxForModal");
                        var ModalHeight = $(".sgmPopUp").height();
                        var modalTopPosition = -ModalHeight / 2;
                        $(".sgmPopUp").css({ "margin-top": modalTopPosition });
                        $(modal).jqmShow();
                    }
                    return false;
                });



                //Expand Text
                $(".sgmTabs-panel .sgmExpandLink").click(function() {
                    $(this).hide();
                    $(".sgmTabs-panel .sgmExtraText").show();
                    $(".sgmTabs-panel .sgmCloseLink").show();
                    return false;
                });
                $(".sgmTabs-panel .sgmCloseLink").click(function() {
                    $(this).hide();
                    $(".sgmTabs-panel .sgmExtraText").hide();
                    $(".sgmTabs-panel .sgmExpandLink").show();
                    return false;
                });


                // Clickable Plugin fires
                //if ($(".sgmInfo-b li").length) $(".sgmInfo-b li").clickable();
                //if ($("ul.sgmCatalog-b li .sgmBlock").length) $("ul.sgmCatalog-b li .sgmBlock").clickable();
                //if ($(".sgmLinks-b li").length) $(".sgmLinks-b li").clickable();
                //if ($(".sgmStart-b").length) $(".sgmStart-b").clickable();
                //if ($(".sgmStart-p").length) $(".sgmStart-p").clickable();


                //Hover readMore
                $(".sgmBlock span.text b, .sgmInfo-b .sgmInfo span.text b").hover(
                    function() {
                        $(this).addClass("sgmHover");
                    },
                    function() {
                        $(this).removeClass("sgmHover");
                    }
                );


                //Open Hours Tooltip
                $(".sgmOpenHours a").click(function() {
                    var tooltipText = $(this).parent().next(".hiddenWorkingHoursBlock").html();
                    $(this).addClass("Clicked");
                    $(".OpenHoursTooltip").html(tooltipText);
                    $(".OpenHoursTooltip").appendTo("body");

                    var topPosition = $(this).offset().top + $(this).height();
                    var leftPosition = $(this).offset().left + $(this).width();
                    $(".OpenHoursTooltip").css({
                        "display": "block",
                        "left": leftPosition,
                        "top": topPosition
                    });
                    $(".OpenHoursOverlay").appendTo("body");
                    $(".OpenHoursOverlay").height($(document).height());
                    $(".OpenHoursOverlay").show();

                    return false;
                });
                $(".OpenHoursOverlay").click(function() {
                    var hiddenBlock = $(".OpenHoursTooltip").html();
                    $(".sgmOpenHours a.Clicked").parent().next(".hiddenWorkingHoursBlock").html(hiddenBlock).queue(function(next) {
                        $(".sgmOpenHours a").removeClass("Clicked");
                        next();
                    });
                    $(".OpenHoursTooltip").css({
                        "display": "none"
                    });
                    $(".OpenHoursOverlay").hide();
                });
                $(".FormBlock li .FieldContainer input.ToolTipItem").each(function() {
                    $(this).focus(function() {

                    });
                    $(".sgmOpenHours a.Clicked").blur(function() {

                    });
                });



                // Clear inputs on focus
                var inputs = $("input[type='text'],textarea[alt]");
                //alert(inputs.length);
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].onfocus = function() {
                        if ($(this).attr("alt") && this.value.indexOf($(this).attr("alt")) == 0) { this.value = ''; }
                    };
                    inputs[i].onblur = function() {
                        if (this.value == '') { this.value = $(this).attr("alt"); }
                    };
                }

                //Product option disabled style
                $("span[disabled='disabled']").css("color", "#444");

            });
        }

    });


})(jQuery);

jQuery( function( $ ) {
	$.init(); // Inits content fixes
	$('.accordion.lofter .title').click(function() {
		$(this).next().toggle();
		$(this).toggleClass('active');
		return false;
	}).next().hide();

});

function GoToActionPage() {
    $(".sgmPopUpLand").appendTo(".sgmBoxForModal");
    var ModalHeight = $(".sgmPopUpLand").height();
    var modalTopPosition = -ModalHeight / 2;
    $(".sgmPopUpLand").css({ "margin-top": modalTopPosition, "z-index": "4000", "visibility": "visible" });
    $(".sgmOverlayLand").height($(document).height());
    $(".sgmOverlayLand").show();
    $(".sgmPopUpLand .sgmTitle .sgmClose").click(function() {
        $(".sgmPopUpLand").css({ "z-index": "-4000", "visibility": "hidden" });
        $(".sgmOverlayLand").hide();
    });
};

function PopUpStudio() {
    $(".sgmBoxForModal").addClass("sgmBoxForModalImage");
    $(".sgmPopUpStudio").appendTo(".sgmBoxForModal");
    /*var ModalHeight = $(".sgmPopUpStudio").height();
    var modalTopPosition = -ModalHeight / 2;*/
    $(".sgmPopUpStudio").css({ "margin-top": 0, "z-index": "4000", "visibility": "visible" });
    $(".sgmOverlayLand").height($(document).height());
    $(".sgmOverlayLand").show();
    $(".sgmPopUpStudio .sgmClose").click(function() {
        $(".sgmPopUpStudio").css({ "z-index": "-4000", "visibility": "hidden" });
        $(".sgmOverlayLand").hide();
    });
};
