$(function(){ $(window).bind('load', function() {
    showContent();
    lightbox();
    captcha()
    showHide();
    $('#nav li.ml').find('a:first').each(function(){
        var w=$(this).width();
        if($.browser.msie && $.browser.version.slice(0,1) == '7'){w=w+9;}
        $(this).parent().css({'width':w});
    });
    bookingForm();
    newsRotator();
    datePicker();
    if($('.public').length > 0) { VideoJS.setupAllWhenReady(); }
}); });
function showContent() {
    $('#content').fadeIn();
    $('#nav').fadeIn();
}
function newsRotator() {
    var $rotator=$('#newsFl');
    var $top=$rotator.children('li:first'); $top.css({'display':'block'});
    $top.css({'z-index':'2'});
    if($rotator.children('li').length > 1){
        var $timer = window.setInterval(function(){
            var $next= $top.next('li');
            $next.css({'z-index':'1'});
            $top.fadeTo(1000,0,function(){
                $top.css({'z-index':'0'}).remove().appendTo($rotator).css({'display':'none'});
                $next.css({'z-index':'2'}).fadeTo(1000,1,function(){
		    $top = $next;
		});
            });
        }, 5000);
    }
}
function bookingForm() {
    $('#submitBtn').click(function(){ return validateForm(); });
    cleanForm();
    function cleanForm(){
        //dates
	var lastO = $('#bookingForm .dates:first');
        $('#bookingForm .dates:not(:first)').each(function(){
	    hOb=false; $field=$(this);
	    $field.find('select').each(function(){ if($(this).val() !=0){ hOb=true; lastO=$(this).parent(); } });
	    if(!hOb) { $(this).hide(); } 
	});
        lastO.find('a').show();
        $('#bookingForm .dates a.moreDates').click(function(){ $(this).hide(); $(this).parent().next('.dates').toggle().find('a').show(); return false; });
        //athletes
	var lastO = $('#bookingForm .athletes:first');
        $('#bookingForm .athletes:not(:first)').each(function(){
	    hOb=false; $field=$(this);
	    $field.find('input.req').each(function(){ if($(this).val() !=''){ hOb=true; lastO=$(this).parent().parent(); } });
	    if(!hOb) { $(this).hide();$field.find('input.req').each(function(){$(this).removeClass('req')}); }
	});
        lastO.find('a').show();
        $('#bookingForm .athletes .moreAthletes').click(function(){ $(this).hide(); $(this).parent().next('fieldset.athletes').toggle().find('a').show(); return false; });
    }

}
function datePicker() {
    $.datepicker.regional['de-CH'] = {
		closeText: 'schliessen',
		prevText: '&#x3c;zurŸck',
		nextText: 'nächster&#x3e;',
		currentText: 'heute',
		monthNames: ['Januar','Februar','März','April','Mai','Juni',
		'Juli','August','September','Oktober','November','Dezember'],
		monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
		'Jul','Aug','Sep','Okt','Nov','Dez'],
		dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
		dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		weekHeader: 'Wo',
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
        changeMonth: true,
        changeYear: true,
        yearRange: (new Date).getFullYear()-70+':'+(new Date).getFullYear(),
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['de-CH']);

    $( ".date" ).datepicker();
    
}
function showHide() {
    $('.btnHContent:first').removeClass('hideBtn');
    if($('.readmore').length) $('.btnContent .pdf').addClass('hideBtn');
    $('#hContent').hide();
    $('.btnHContent').click(function(){ $('.btnHContent').each(function(){ $(this).toggleClass('hideBtn'); }); $('#hContent').stop().slideToggle(500); $('.btnContent .pdf').toggleClass('hideBtn'); return false;});
}
function lightbox() { $('#bigGallery a.lightbox').lightBox(); }
function hideSl() { $('#box.public ul.sl').hide(); }
function validateForm() {
    //checkAthlete();
    valid = true; selArr = ['0'];
    $('select.reqSel').each(function(){ 
        if($.inArray($(this).val(), selArr) > -1) {
            mark($(this), false); valid = false;
        } else { mark($(this), true); }
    });
    $('.req').each(function(){
        if($(this).val() == ''){ mark($(this), false); valid = false;
        } else { mark($(this), true); }
    });
    function mark(obj, pos) {
        if(pos) { obj.removeClass('mark');
        } else { obj.addClass('mark'); }
    }
    return valid;
    //return false;
}
function captcha() {
    $('#newCaptcha').click(function () {
        $("#captcha").attr("src",'http://'+window.location.hostname+'/addons/captcha/securimage_show.php?' + Math.random());
        return false;
    });
}
