function gotoLink (htmlElement) {

	var destinationURL = "";
	var target = "";

	if ( htmlElement.href ) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}
	else {
		if ( htmlElement.childNodes ) {
			if( htmlElement.getElementsByTagName("a") ) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}

	if ( destinationURL.length > 0 ) {
		if( target == "_blank" ) {
			window.open(destinationURL);
		}
		else {
			location.href = destinationURL;
		}
	}
	return false;
}

	


$(document).ready(function() {

    // IE6?

    if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6) {
        try {
            var ie6 = true;
        }
        catch (err) {
        }
    }
    else {
        var ie6 = false;
    }

    // IE7?

    if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 7) {
        try {
            var ie7 = true;
        }
        catch (err) {
        }
    }
    else {
        var ie7 = false;
    }

    // BACKSTRETCH PORTAL

    if ( portal == true && backgroundimageurl ) {
        if ( ie6 == true ) {
            $("body").css("background","#000 url(" + backgroundimageurl + ") no-repeat top center");
            $(".sloganbox.portal").css("display","block");
            $(".requestbox").css("display","block");
            $(".portalteasers").css("display","block");
        }
        else {
            $.backstretch(backgroundimageurl);
        }
    }

    // METANAV
	
	$("#metanav ul li.first").each(function(i) {
		$(this).bind({
			mouseenter: function() {
				if(!$(this).hasClass("sfhover")) {
					$(this).addClass("sfhover");
					if(!$(this).hasClass("initialized")) {
						$(this).addClass("initialized");
						
						var listwidth = 167*$(".submenu .list ul", this).length;
						var teaserwidth = 0;
						if($(".teaser", this).length > 0) {
							teaserwidth = 441;
						}
						
						var submenuwidth = listwidth + teaserwidth;
						$(".submenu", this).width(submenuwidth);
						
						var menupointoffset = $(this).position();
						var menupointoffset = menupointoffset.left + 204;
						
						var metanavwidth =  $("#metanav").width();
						var gesamtlaenge = submenuwidth + menupointoffset;
						if (gesamtlaenge > metanavwidth) {
							var possibleroom = 979 - menupointoffset;
							var left_room = submenuwidth - possibleroom;
							if (left_room > -1) {
								$(".submenu",this).css("left", -left_room);
							}
						}
					}
				}
			},
			mouseleave: function() {
				if($(this).hasClass("sfhover")) {
					$(this).removeClass("sfhover");
				}
			}		 
		});
	});

  

    // JQUERY TOOLS DATEINPUT

    // Localization

    $.tools.dateinput.localize("de",  {
       months:        'J&auml;nner,Februar,M&auml;rz,April,Mai,Juni,Juli,August,' +
                        'September,Oktober,November,Dezember',
       shortMonths:   'Jan,Feb,Mar,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez',
       days:          'Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag',
       shortDays:     'So,Mo,Di,Mi,Do,Fr,Sa'
     });

    $.tools.dateinput.localize("it",  {
       months:        'gennaio,febbraio,marzo,aprile,maggio,giugno,luglio,agosto,' +
                        'settembre,ottobre,novembre,dicembre',
       shortMonths:   'gen,feb,mar,apr,mag,giu,lug,ago,set,ott,nov,dic',
       days:          'lunedi,martedi,mercoledi,giovedi,venerdi,sabato,domenica',
       shortDays:     'lun,mar,mer,gio,ven,sab,dom'
    });

     $.tools.dateinput.localize("en",  {
       months:        'January,February,March,April,May,June,July,August,' +
                        'September,October,November,December',
       shortMonths:   'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',
       days:          'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday',
       shortDays:     'Su,Mo,Tu,We,Th,Fr,Sa'
     });

    if ( $("input:date").length > 0 ) {
        $("input:date").dateinput({
            format: 'dd.mm.yyyy',
            lang: lang,
			min: -1,
			firstDay: 1
        });
    }

    // SLIDER

    if ( $(".slider.slide").length > 0 ) {

        $( ".slider.slide").each(function(i) {

            var rcitemwidth = 365;
            var rcmincontroller = 0;
            var rccontroller = 0;
            var rcvisibleitems = 1;

            var rcitemcount = $(".slider.slide:eq(" + i +") .item").length;
            var rccontainerwidth = rcitemcount * rcitemwidth;
            var rcmaxcontroller = rccontainerwidth;

            $(".slider.slide:eq(" + i +") .container").width(rccontainerwidth);

            $(".slider.slide:eq(" + i +") .leftarrow").click(function() {
                if ( rccontroller > rcmincontroller ) {
                    $(".slider.slide:eq(" + i +") .container").animate({
                        left: "+="+rcitemwidth
                    }, 500, 'linear', function() {
                    });
                    rccontroller = rccontroller - rcitemwidth;
                }
                return false;
            });

            $(".slider.slide:eq(" + i +") .rightarrow").click(function() {
                if ( rccontroller < ( rcmaxcontroller - rcitemwidth * rcvisibleitems ) )   {
                    $(".slider.slide:eq(" + i +") .container").animate({
                        left: "-="+rcitemwidth
                    }, 500, 'linear', function() {
                    });
                    rccontroller = rccontroller + rcitemwidth;
                }
                return false;
            });

             if ( rcitemcount < 2 ) {
                $(".slider.slide:eq(" + i + ") .arrows").toggleClass("ishidden");
            }

        });

    }

    // SEARCH SWAP VALUE INPUT.JQUERY

    /*if ( $("input#email_nl").length > 0 ) {
        var swap_val = [];
        $("input#email_nl").each(function(i){
            swap_val[i] = $(this).val();
            $(this).focusin(function(){
                if ($(this).val() == swap_val[i]) {
                    $(this).val("");
                }
            }).focusout(function(){
                if ($.trim($(this).val()) == "") {
                    $(this).val(swap_val[i]);
                }
            });
        });
    }*/

    // PRICETABLE

    if ( $(".pricetable").length > 0 ) {

        // Variables
        var linewidth = $(".pricetable .container .line").children().length;
        var linewidth = linewidth * 90;
        $(".pricetable .container .line").width(linewidth);
        var itemsperrow = $(".pricetable .container .line:first").children().length;
        var position = 0;
        var maxposition = itemsperrow * 90;


		var overflowheight = 76;
		$(".pricetable .lefttable .line:not(.blank)").each(function(i) {														
			$(".pricetable .righttable .line:not(.blank)").eq(i).height($(this).height() + 22);
			overflowheight += $(this).height() + 22;								
		});
		
		$(".pricetable .overflow").height(overflowheight);
		$(".pricetable .border").height(overflowheight - 6);
														

        // Margin to Sibling
        /*$(".pricetable").next(".contentblock").css("padding","25px 0 0 0");
        if ( ie6 == true || ie7 == true ) {
            $(".pricetable").next(".contentblock").css("padding","0 0 0 0");
        }*/

        // Left Arrow
        $(".pricetable .leftarrow").click(function() {
            if ( position > 0 ) {
                $(".pricetable .container").animate({
                    left: "+="+90
                    }, 500, 'linear', function() {
                });
                position = position - 90;
            }
        });

        // Right Arrow
        $(".pricetable .rightarrow").click(function() {
            if ( position < ( maxposition - ( 90*1 ) ) ) {
                $(".pricetable .container").animate({
                    left: "-="+90
                    }, 500, 'linear', function() {
                });
                position = position + 90;
            }
        });

		currentDate = new Date();
		parsed = currentDate.getTime()/1000;
		
        // Dateinput Change
       $("input:date").change(function(event, date) {
            var chosendate = date;
            parsed = (Date.parse(chosendate))/1000;
        });
	   
        // Click on Button
        $("a.changesaison").click(function() {						   
            for (i=0; i < itemsperrow; i++) {
                if ( price_seasons[i][0] < parsed && price_seasons[i][1] > parsed) {
                    var scrollamount = i * 90;
                    var difference = scrollamount - position;
                    $(".pricetable .container").animate({
                        left:"-="+difference+"px"
                        } , 500, 'linear', function() {
                    });
                    position = position + difference;
                }
            }
            return false;
        });
		
		$("a.changesaison").click();
		

        // Show Image
        $(".pricetable .lefttable .line").hover(function() {
            if ( $(".image", this).length > 0 ) {
                $(this).toggleClass("higherindex");
                $(".image", this).toggleClass("highindex");
                $(".image", this).toggleClass("isnone");
                $(".image", this).hover(function() {
                    $(this).toggleClass("isnone");
                })
            }
        });
    }

    // FAKE SELECT

    if ( $("form .select").length > 0 ) {
        $("form .select").click(function() {
            var thisselect = $(this);
            $("ul li ul", this).show().toggleClass("isnone");
            $("ul li ul li", this).click(function() {
				var thishiddeninput = $(this).closest(".line");
                var content = $(this).html();
				if(thisselect.hasClass('hasvalue')) {
					$("input[type=hidden]",thishiddeninput).val($(this).attr('value'));
				} else {
					$("input[type=hidden]",thishiddeninput).val(content);
				}
                $("span", thisselect).empty().text(content);
                $("ul li ul", thisselect).hide();
            });
        });
    }
	
	// GOOGLE MAPS
	
	if ( $("#map_canvas").length > 0 ) {
		initialize();
	}

    

    // INTERACTIVE PLAN

    if ( $(".plan").length > 0 ) {
        $(".plan .plus").hover(function() {
           $(this).addClass("hover");
		   
		   // add classes depending on position and length
		   var x = $(this).css("left");
		   var xlength = x.length;
		   x = x.substr(0, xlength-2);
		   var y = $(this).css("top");
		   var ylength = y.length;
			y = y.substr(0, ylength-2);
		   var descwidth = $(".desc",this).width();
		   $(".desc",this).width(descwidth);
		   if ( y > 280 ) {
				$(".desc",this).addClass("bottom");
		   }

			if ( ( 333 - descwidth) < x ) {
				$(".desc",this).addClass("right");
			}
		   if ( x < descwidth ) {
				$(".desc",this).addClass("left");
		   }
		   $(this).css("z-index",200);
		   
        },
		function() {
			$(this).css("z-index",5);
			$(this).removeClass("hover");
		});
		
        $(".plan .plus").click(function() {
           var pos = $(this).attr("class");
           pos = pos.substring(5, pos.length - 6);
           $(".plancontent").addClass("isnone");
           $(".plancontent." + pos).toggleClass("isnone");
        });
		
		
		
		
		
    }

    // PLUSMINUS PORTAL

    if ( $(".plusminus").length > 0 ) {
        $(".plusminus img").click(function() {
           $("img", ".plusminus").toggleClass("isnone");
        });
    }

    // SLOGAN ANIMATION PORTAL

     if ( $(".sloganbox a").length > 0 ) {
          $(".sloganbox a").fadeIn(3000, function() {
          });
     }

    // FANCYBOX

    if ( $("a.fancybox").length > 0 ) {
        $("a.fancybox").fancybox({
            'transitionIn'	:	'elastic',
            'transitionOut'	:	'elastic',
            'speedIn'		:	600,
            'speedOut'		:	200,
            'overlayShow'	:	true,
            'overlayColor'  :   '#000',
			'titlePosition'	:	'over',
			'cyclic'		:	true
        });
	}
	if( $("a.panorama").length > 0 ) {
		$("a.panorama").addClass("iframe");
		$("a.panorama").fancybox({
			'transitionIn'	:	'elastic',
            'transitionOut'	:	'elastic',
            'speedIn'		:	600,
            'speedOut'		:	200,
            'overlayShow'	:	true,
            'overlayColor'  :   '#000',
			'titlePosition'	:	'over',
			'width'			:	1002,
			'height'		:	724,
			'scrolling'		:	'no',
			'autoScale'		:	false
		});
    }

	// 3D-SLIDER TEXTS
	
	if ( $("#3dgal").length > 0 ) {
		var dcount = $(".slidertext","#3dgal").length;
		
		for (i=0; i < dcount; i++) {
			var content = $(".slidertext:eq(" + i + ")").html();
		}
	}


    
	// GALLERY

    /*if ( $(".gal_buttons").length > 0 ) {
        $(".gal_buttons a").click(function () {
            $(this).toggleClass("checked");
            if ( $(this).hasClass("checked") ) {
                var thisclass = $(this).attr("class");
                thisclass = thisclass.substring(0, thisclass.length - 7);
            }
            if ( !$(this).hasClass("checked") ) {
                var thisclass = $(this).attr("class");
            }
            $(".galitem." + thisclass).toggleClass("isnone");
            return false;
        });
    }*/

    

});
