function myPreload(img_src){var d=document;if(d.images){if(!d.p){d.p=new Array()}var key=d.p.length;d.p[key]=new Image;d.p[key].src=img_src}}function preloadImages(){var a=preloadImages.arguments;for(i=0;i<a.length;i++){if(a[i].indexOf("#")!=0){myPreload(a[i])}}}function setRoleAttr(){if($('#header')){$('#header').attr('role','banner')}if($('#navi')){$('#navi').attr('role','navigation')}if($('#col1')){$('#col1').attr('role','complementary')}if($('#col2')){$('#col2').attr('role','complementary')}if($('#col3')){$('#col3').attr('role','main')}if($('#footer')){$('#footer').attr('role','contentinfo')}}
function initChanger(pic,thumbs,img,suffix,prev,next){var src_arr=new Array();var current_index=1;$(thumbs).each(function(i){var src=$(this).find(img).attr('src').replace(suffix,'');src_arr[i]=src;myPreload(src)});$(thumbs).click(function(){$(thumbs).removeClass('current');var src=$(this).find(img).attr('src').replace(suffix,'');$(pic).attr('src',src);$(this).addClass('current');$.each(src_arr,function(i,v){if(v==src){current_index=i+1}});return false});if(prev!=''){$(prev).click(function(){current_index--;if(current_index==0)current_index=src_arr.length;$(thumbs).removeClass('current');$(pic).attr('src',src_arr[current_index-1]);$(thumbs+':nth-child('+current_index+')').addClass('current');return false})}if(next!=''){$(next).click(function(){current_index++;if(current_index==src_arr.length+1)current_index=1;$(thumbs).removeClass('current');$(pic).attr('src',src_arr[current_index-1]);$(thumbs+':nth-child('+current_index+')').addClass('current');return false})}}
function initDatePicker(first,second){$('head').append($('<link type="text/css" rel="stylesheet" href="http://tools.werbewind.com/js/jquery-1.4.2/ui/custom_all/css/smoothness/jquery-ui-1.8rc3.custom.css" />'));$.getScript('http://tools.werbewind.com/js/jquery-1.4.2/ui/custom_all/js/jquery-ui-1.8.datepicker.min.js',function(){$.getScript('http://tools.werbewind.com/js/jquery-1.4.2/ui/i18n/jquery.ui.datepicker-de.js',function(){var sf=$(first).datepicker({minDate:"0",onSelect:function(){if($(second).length==1){var anrDate=new Date(Date.parse($(first).datepicker('getDate')));var abrDate=new Date(Date.parse($(second).datepicker('getDate')));if(anrDate>=abrDate||$(second).val()==''){$(second).datepicker('setDate',new Date(anrDate.getTime()+86400000))}$(second).datepicker("option","minDate",new Date(anrDate.getTime()+86400000))}}});var st=$(second).datepicker({minDate:"+1",onSelect:function(){var abrDate=new Date(Date.parse($(second).datepicker('getDate')));if($(first).val()==''){$(first).datepicker('setDate',new Date(abrDate.getTime()-86400000))}}})})})}
function initFancyBox(){var lb_els=$("a[rel^='lightbox']");if(lb_els.size()>0){$.getScript('http://tools.werbewind.com/js/jquery-1.4.2/fancybox/jquery.fancybox-1.3.1.pack.js',function(){$("a[rel^='lightbox']").fancybox({"speedIn":600,"speedOut":200,"overlayShow":true,"titlePosition":"over","overlayOpacity":0.85,"titleShow":false,"overlayColor":'#222'})});$.getScript('http://tools.werbewind.com/js/jquery-1.4.2/fancybox/jquery.easing-1.3.pack.js');$.getScript('http://tools.werbewind.com/js/jquery-1.4.2/fancybox/jquery.mousewheel-3.0.2.pack.js');$('head').append($('<link rel="stylesheet" href="http://tools.werbewind.com/js/jquery-1.4.2/fancybox/jquery.fancybox-1.3.1.css" type="text/css" media="screen" />'))}}
function gmRoute(){
  var street=$('#street').val();var zip=$('#zip').val();var city=$('#city').val();var country=$('#country').val();
  var url="http://maps.google.de/?hl=de&q="+street+","+city+" "+zip+","+country+"+nach+Bergwer Weg 18, 87538 Fischen im Allgäu, Deutschland";
  if(street!=''&&zip!=''&&city!=''&&country!=''){window.open(url,"_blank");}
  else{alert("Füllen sie bitte alle Felder aus!");}
}
$(document).ready(function(){
  setRoleAttr();
  initFancyBox();
  initDatePicker('#f_date_sa','');
  if($("#kontaktform").length>0){
    $.getScript('http://tools.werbewind.com/js/jquery-1.4.2/validate/jquery.validate.js',function(){
      $.getScript('http://tools.werbewind.com/js/jquery-1.4.2/validate/localization/messages_de.js',function(){
        $("#kontaktform").validate();
        initDatePicker('#anreise','#abreise');		
      });	
    });
  }
  $('.newsbox a').mousedown(
    function(){$.ajax({url:'http://tools.werbewind.com/Newsbox/add_click.php?id='+$(this).attr('rel')})}
  );
  initChanger('#header_pic','#header_thumbs a','img','_kl','','');
  if($('#pic').length>0){initChanger('#pic','#thumbs a','img','_kl','','');}
  if($('#show_plan').length>0){
    $('#plan').hide();
	$('#show_plan').click(function(){
      $('#plan').toggle('slow',function(){
        if($('#plan:visible').length>0){$('#show_plan').html('Belegungsplan ausblenden');}
        else{$('#show_plan').html('Belegungsplan anzeigen');}
      });
    }).css('cursor','pointer');
  }
});
