// JQUERY ONDOMREADY

var _className = 'empty';
var timeOut = '';

$(document).ready(function() { 
	
	
	//MENU
	$("ul.main-menu").supersubs({
	
		minWidth: 12,
		maxWidth: 27,
		extraWidth: 1
	
	}).superfish({
	
		autoArrows: false
	
	});
	
	
	//TABS SHIP DETAILS
    $("ul.tabs").tabs("div.panes > div");
    
    
    //CAROUSEL
    $('#mycarousel_horizontal').jcarousel({
		scroll: 1
	});
	
	//OVER STATE DIV CONTAINER
	$('.used-boats-listitem').hover(function() {
		
		$(this).addClass('used-boats-over');	
		
	}, function () {
	
		$(this).removeClass('used-boats-over');
	
	});
	
	
	$('.boatselling-listitem').hover(function() {
		
		$(this).addClass('boatselling-over');	
		
	}, function () {
	
		$(this).removeClass('boatselling-over');
	
	});
	
	
	//JQUERY UI DATEPICKER
	$("#datepicker").datepicker();
	$('#date_start, #date_end').datepicker({ 
		monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
		dayNamesMin: ['SO','MO','DI','MI','DO','FR','SA'],
		firstDay: 1,
		beforeShow: customRange,
		dateFormat: 'dd.mm.yy'
	});
	
	function customRange(input) {
	
		var min = new Date(2009, 1, 1);
		var dateMin = min;
		var dateMax = null;
		var tempDate = null;
	
		if (input.id == 'date_start') {
		
			if ($('#date_end').datepicker('getDate') != null && $('#date_end').datepicker('getDate') != 'TT.MM.JJJJ') {
			
				tempDate = $('#date_end').datepicker('getDate');
				dateMax = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
			
			} 
		
		} else if (input.id == 'date_end') {
		
			if ($('#date_start').datepicker('getDate') != null && $('#date_start').datepicker('getDate') != 'TT.MM.JJJJ') {
			
				tempDate = $('#date_start').datepicker('getDate');
				dateMin = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
			
			}
		
		}
	
		return {
		
			minDate: dateMin,
			maxDate: dateMax
		
		};
	
	}
	
	//BOOKINGTABLE MOUSEOVER
	$(".booking-content-booking-table a").hover(function() {
	
		var className = $(this).attr('class');
		
		if ($("#em_" + className).css('display') == 'none' && className != _className) {
			
			//CLOSE OLD ONE
			if (_className != 'empty') {
				
				if (!$('body').hasClass('ie') && !$('body').hasClass('ie6')) {
				
					$("#em_" + _className).animate({opacity: "hide", top: "-85"}, "fast");
					
				} else {
						
					$("#em_" + _className).css('display', 'none');
						
				}
				
			}
			
			_className = className;
			
			//CLOSE AFTER A MAXIMUM TIME OF 10 SECS
			clearTimeout(timeOut);
			timeOut = setTimeout(closeAllEms, 10000);
			
			if (!$('body').hasClass('ie') && !$('body').hasClass('ie6')) {
				
				$("#em_" + className).animate({opacity: "show", top: "-85"}, "slow");
				return false;
				
			} else {
				
				$("#em_" + className).css('display', 'block');
				return false;
				
			}
		
		}
		
	}, function() {
	
		//
	
	});
	
	function closeAllEms() {
		
		clearTimeout(timeOut);
		
		if (!$('body').hasClass('ie') && !$('body').hasClass('ie6')) {
			
			$("#em_" + _className).animate({opacity: "hide", top: "-85"}, "fast");
			return false;
			
		} else {
				
			$("#em_" + _className).css('display', 'none');
			return false;
				
		}
	
	}
	
/*	$(".booking-content-booking-table a").hover(function() {
		
		if (!$('body').hasClass('ie') && !$('body').hasClass('ie6')) {
			
			$(this).next("em").animate({opacity: "show", top: "-85"}, "slow");
			return false;
			
		} else {
			
			$(this).next("em").css('display', 'block');
			return false;
			
		}
	
	}, function() {
		
		if (!$('body').hasClass('ie') && !$('body').hasClass('ie6')) {
			
			$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
			return false;
			
		} else {
				
			$(this).next("em").css('display', 'none');
			return false;
				
		}
	
	});*/

}); 