var switchoffset = 0;

function goLink(destinationURL, target){
    if( target == "_blank" ) {
        window.open(destinationURL);
    }
    else {
        location.href = destinationURL;
    }
}


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;
}

function eventcarousel_initCallback(carousel) {

    $('#eventwrappernext').bind('click', function() {
        carousel.next();
        return false;
    });

    $('#eventwrapperprev').bind('click', function() {
        carousel.prev();
        return false;
    });
}

function livecamcarousel_initCallback(carousel) {

    $('#webcamwrappernext').bind('click', function() {
        carousel.next();
        return false;
    });

    $('#webcamwrapperprev').bind('click', function() {
        carousel.prev();
        return false;
    });
}

function eventarousel(){
    $("#eventcarousel").jcarousel({
        scroll: 1,
        wrap: "circular",
        initCallback: eventcarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
}

function rotatestoerer(){
    $("#stoererimg").rotate(4);
}

function rotationbyid(id){
    rotateimage = "#stoererimg"+id;
    $(rotateimage).rotate(4);
}

function portalvid(){
    $("#portalvidimg").rotate(2);
}

function livecambt(){
    /*$('#livecambtn').click(function() {
        $("#livecamactive").html(randomcam);
        $("#livecamactive").css({'display' : 'block'});
        livecamcarousel();
        fancybox();
    });*/


    $('#closewebcambox').live('click', function() {
        $("#livecamactive").css({'display' : 'none'});
    });
}

function menu(){
	$("#nav ul li").mouseenter(function() {
		if(!$(this).hasClass("active") && !$(this).hasClass("sfhover")){
			$(this).addClass("sfhover");
		}
	}).mouseleave(function(){
		$(this).removeClass("sfhover");
	});
}


function datepicker(){
    if ( lang == "de" ) {


        if(belegungvon && belegungbis){
            $("input#arrival, input#departure").datepicker({
                numberOfMonths: 1, regional: lang, dateFormat: 'dd.mm.yy', firstDay: 1,
                monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
                dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                minDate: belegungvon,
                maxDate: belegungbis,
                onSelect: function(dateText, inst) {
                    var x = $(this).attr("id");
                    if ( x == "arrival" ) {
                        $("input#departure").datepicker("option", "minDate", dateText);
                        var currdate = $(this).datepicker("getDate");
                        currdate.setDate(currdate.getDate()+7);
                        $("input#departure").datepicker("setDate",currdate);
                    }

                }
            });
        } else {
            $("input#arrival, input#departure").datepicker({
                numberOfMonths: 1, regional: lang, dateFormat: 'dd.mm.yy', firstDay: 1,
                monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
                dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                minDate: 0,
                onSelect: function(dateText, inst) {
                    var x = $(this).attr("id");
                    if ( x == "arrival" ) {
                        $("input#departure").datepicker("option", "minDate", dateText);
                        var currdate = $(this).datepicker("getDate");
                        currdate.setDate(currdate.getDate()+7);
                        $("input#departure").datepicker("setDate",currdate);
                    }

                }
            })
        }

/*        $("input#arrival, input#departure").datepicker({
            numberOfMonths: 1, regional: lang, dateFormat: 'dd.mm.yy', firstDay: 1,
            monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
            dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
            minDate: stdate,
            maxDate: endate,
            onSelect: function(dateText, inst) {
                var x = $(this).attr("id");
                if ( x == "arrival" ) {
                    $("input#departure").datepicker("option", "minDate", dateText);
                    var currdate = $(this).datepicker("getDate");
                    currdate.setDate(currdate.getDate()+7);
                    $("input#departure").datepicker("setDate",currdate);
                }

            }
        });*/



    }
}

function livecamcarousel(){
    $("#webcamcarousel").jcarousel({
        scroll: 1,
        wrap: "circular",
        initCallback: livecamcarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
}

function goFancyvideo(urls){
    $('#portalvid').css('display','none');
    $.fancybox({
        'width'				: 950,
        'height'			: 534,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'href'              : '/videoplayer/'+urls,
        'type'				: 'iframe',
        'onClosed'		: function() {
            $('#portalvid').css('display','block');
       	}
    });
}

function fancybox(){

    $("a[rel=imggal]").fancybox({
        'transitionIn'		: 'fade',
        'transitionOut'		: 'fade',
        'titlePosition' 	: 'inside'
    });

    $("a.webcamimg").fancybox({
        'transitionIn'		: 'fade',
        'transitionOut'		: 'fade',
        'titlePosition' 	: 'inside'
    });


    $('a.webcamimg').click(function() {

        $.fancybox({
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'href'			    : this.href,
            'titlePosition' 	: 'inside'
        });

        return false;

    });

    $('.marketinglist .contentetaser').click(function() {


        $.fancybox({
            'width'             : 790,
            'height'            : '75%',
            'type'              : 'iframe',
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'href'			    : $(this).find('a').attr('href')
        });

        return false;

    });


    $('a.webcamiframe').live('click', function() {
        coords = $(this).attr("coords");
        cd = coords.split(',');

        var fwidth = parseInt(cd[0]);
        var fheight = parseInt(cd[1]);

        $.fancybox({
            'width'				: fwidth,
            'padding'           : 0,
            'scrolling'         : 'no',
            'height'			: fheight,
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'href'			    : this.href,
            'type'				: 'iframe'
        });

        return false;

    });




    $(".gimage .ytvideo").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		    : 680,
            'height'		: 495,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'			: 'swf',
            'swf'			: {
                 'wmode'		    : 'transparent',
                'allowfullscreen'	: 'true'
            }
        });
        return false;
    });

    $("#portalvid span.lupe").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		    : 680,
            'height'		: 495,
            'href'			: $('#portalvidimga').attr('href').replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'			: 'swf',
            'swf'			: {
                 'wmode'		: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });

        return false;
    });

    $("#portalvidimga").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		    : 680,
            'height'		: 495,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'			: 'swf',
            'swf'			: {
                 'wmode'		: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });

        return false;
    });

}

function hidecoolFlash(){

}


function openwindow(url,width,height) {
   fenster = window.open(url, "fenster1", "width="+width+",height="+width+",status=yes,scrollbars=yes,resizable=yes");
   fenster.focus();
}

function PortalslideSwitchprev() {
    var $active = $('#st .stcarus.active');

    if ( $active.length == 0 ) $active = $('#st .stcarus:last');

    var $prev =  $active.prev().length ? $active.prev()
        : $('#st .stcarus:last');

    $active.addClass('last-active');



    $prev.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function PortalslideSwitchnext() {
    var $active = $('#st .stcarus.active');

    if ( $active.length == 0 ) $active = $('#st .stcarus:last');

    var $next =  $active.next().length ? $active.next()
        : $('#st .stcarus:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}




function switchprev() {
    if(switchoffset == 0){
        $('#mainimage').append(portalimages);
        switchoffset = 1;
        setTimeout("switchprevimg()", 500);
    } else {
        switchprevimg();
    }

    var $active = $('#switcherinlay div.active');

    if ( $active.length == 0 ) $active = $('#switcherinlay div:last');

    var $prev =  $active.prev().length ? $active.prev()
        : $('#switcherinlay div:last');

    $active.addClass('last-active');

    $prev.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function switchnext() {
    if(switchoffset == 0){
        $('#mainimage').append(portalimages);
        setTimeout("switchnextimg()", 500);
        switchoffset = 1;

    } else {
        switchnextimg();
    }

    var $active = $('#switcherinlay div.active');

    if ( $active.length == 0 ) $active = $('#switcherinlay div:last');

    var $next =  $active.next().length ? $active.next()
        : $('#switcherinlay div:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}







function switchprevimg() {
    var $active = $('#mainimage div.active');

    if ( $active.length == 0 ) $active = $('#mainimage div:last');

    var $prev =  $active.prev().length ? $active.prev()
        : $('#mainimage div:last');

    $active.addClass('last-active');

    $prev.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function switchnextimg() {
    var $active = $('#mainimage div.active');

    if ( $active.length == 0 ) $active = $('#mainimage div:last');

    var $next =  $active.next().length ? $active.next()
        : $('#mainimage div:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function portalangebote() {
    var $active = $('#portalstoerer .portalstoerercontainer.active');

    if ( $active.length == 0 ) $active = $('#portalstoerer .portalstoerercontainer:last');

    var $next =  $active.next().length ? $active.next()
        : $('#portalstoerer .portalstoerercontainer:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}



function teaserhover(){
    $(".contentetaser").mouseover(function() {
		if (!$(this).hasClass("az_entry")) {
			$(this).css("background-position","0px -183px");
			$(this).find('h2').css("color","#20a1dc");
			$(this).find('span').css("color","#20a1dc");
			$(this).find('p').css("color","#20a1dc");
			$(this).find('a').css("color","#20a1dc");
		}
    }).mouseout(function(){
		if (!$(this).hasClass("az_entry")) {
			$(this).css("background-position","0px 0px");
			$(this).find('h2').css("color","#ffffff");
			$(this).find('span').css("color","#84c8e4");
			$(this).find('p').css("color","#ffffff");
			$(this).find('a').css("color","#ffffff");
		}
    });


    $(".angebotsteaser").mouseover(function() {
        $(this).css("background-position","0px -574px");
        $(this).find('h2').css("color","#20a1dc");
        $(this).find('p').css("color","#20a1dc");
        $(this).find('a').css("color","#20a1dc");
        $(this).find('span.date').css("color","#20a1dc");
    }).mouseout(function(){
        $(this).css("background-position","0px -367px");
        $(this).find('h2').css("color","#ffffff");
        $(this).find('p').css("color","#ffffff");
        $(this).find('a').css("color","#ffffff");
        $(this).find('span.date').css("color","#ffffff");
    });


    $(".shortteaser").mouseenter(function() {
        $(this).find('.move').animate({
          top: "77px"
        }, 300, function() {
        });
    }).mouseleave(function(){
        $(this).find('.move').animate({
          top: "165px"
        }, 300, function() {
        });
    });

    $(".shortteaserlast").mouseenter(function() {
        $(this).find('.move').animate({
          top: "77px"
        }, 300, function() {
        });
    }).mouseleave(function(){
        $(this).find('.move').animate({
          top: "165px"
        }, 300, function() {
        });
    });

}
















$(document).ready(function() {




if( $.browser.msie && ( $.browser.version == '7.0' || $.browser.version == '8.0') ){
        $('body').addClass('msie');
}

    rotatestoerer();
    livecambt();
    menu();
    //fancybox();
    portalvid();

    if($(".gallery").length > 0 || $(".marketinglist").length > 0){
        fancybox();
    }

    if($("#eventcarousel").length > 0){
        eventarousel();
    }

    if($(".contentetaser").length > 0 || $(".angebotsteaser").length > 0){
        teaserhover();
    }

    if($("#arrival").length > 0){
        datepicker();
    }


    if($(".wbcimage").length > 0){
        PmaxGThumb.scan();
    }





});




