var dates =[
	[	new Date(2011,5,8),		new Date(2011,5,13),	"Slot 1 - 8. Juni bis 13. Juni", 			"closed"	],
	[	new Date(2011,5,15),	new Date(2011,5,20),	"Slot 2 - 15. Juni bis 20. Juni",			"closed"		],
	[	new Date(2011,5,22),	new Date(2011,5,27),	"Slot 3 - 22. Juni bis 27. Juni",			"closed"	],
	[	new Date(2011,5,29),	new Date(2011,6,4),		"Slot 4 - 29. Juni bis 4. Juli",			"closed"		],
	[	new Date(2011,6,6),		new Date(2011,6,11),	"Slot 5 - 6. Juli bis 11. Juli",			"closed"	],
	[	new Date(2011,6,13),	new Date(2011,6,18),	"Slot 6 - 13. Juli bis 18. Juli",			"closed"	],
	[	new Date(2011,6,20),	new Date(2011,6,25),	"Slot 7 - 20. Juli bis 25. Juli", 			"closed"		],
	[	new Date(2011,6,27),	new Date(2011,7,1),		"Slot 8 - 27. Juli bis 1. August", 			"closed"		],
	[	new Date(2011,7,3),		new Date(2011,7,8),		"Slot 9 - 3. August bis 8. August",			"closed"		],
	[	new Date(2011,7,10),	new Date(2011,7,15),	"Slot 10 - 10. August bis 15. August",		"closed"	],
	[	new Date(2011,7,17),	new Date(2011,7,22),	"Slot 11 - 17. August bis 22. August",		"closed"		],
	[	new Date(2011,7,24),	new Date(2011,7,29),	"Slot 12 - 24. August bis 29. August", 		"closed"		],
	[	new Date(2011,7,31),	new Date(2011,8,5),		"Slot 13 - 31. August bis 5. September",	"closed"		],
	[	new Date(2011,8,7),		new Date(2011,8,12),	"Slot 14 - 7. September bis 12. September", "free"		],
	[	new Date(2011,8,14),	new Date(2011,8,19),	"Slot 15 - 14. September bis 19. September","free"		],
	[	new Date(2011,8,21),	new Date(2011,8,26),	"Slot 16 - 21. September bis 26. September","closed"		],
];

function daysToMark(date) {
	for (var i = 0; i < dates.length; i++) {
	        if (dates[i][0] <= date && dates[i][1] >= date) {
					if (dates[i][3] == "free") {
						return [true, 'ui-state-marked slot' + i + '" slot="' + i + '" id="a', dates[i][2]];
					}else{
						return [true, 'ui-state-closed slot' + i + '" slot="' + i + '" id="a', dates[i][2]];
						}
		}
	}
    return [true, '', ""];
}

$().ready(function() {
	
	// cave_away aktionskram
	
	var activatedslot = "NULL";

	$("#datepicker").datepicker({ 
			dayNames: ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'],
			firstDay: 1,
			beforeShowDay: daysToMark,
			selectOtherMonths: true,
			showOtherMonths: true,
			dateFormat: 'dd-mm-yy',
			minDate: new Date(2011,5,1),
			maxDate: new Date(2011,8,30)
		});
		
	$("#datepicker").datepicker( "option", "dayNamesMin", ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] );

	$("td:not(.ui-state-selected)").live('mouseenter', function() { 
		$('td').removeClass('activated');
	}).live('mouseleave', function () {
	});
	
	$('.ui-state-marked').live('click', function() {
	  	var number = $(this).attr('slot');
	  	$(".slot" + number).addClass('ui-state-selected');
	  	activatedslot = number;
	});
	
	$('#senden').live('click', function() {
	  	$(this).attr('disabled', false);
	  	$('#zeitraum').attr('disabled', false);
	});
	
	$('#popupanmeldung1').live('click', function() {
		if(activatedslot != "NULL"){
			$('#zeitraum').val(dates[activatedslot][2]);
			$('#zeitraum').attr('disabled', true);
			$('#senden').attr('disabled', false);
			}else{
				$('#zeitraum').val('Bitte suche dir im Kalender einen Slot aus.');
				$('#zeitraum').attr('disabled', true);
				$('#senden').attr('disabled', true);
				}
	});

	$(".ui-state-marked").live('mouseenter', function() { 
		if($(this).hasClass('ui-state-selected')){
			}else{
				$('td').removeClass('activated');
				var number = $(this).attr('slot');
				$(".slot" + number).addClass('activated');
			}
		}).live('mouseleave', function () {
	});



    // find ipad, ipod and iphone users.
    var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    
    
    // Fancybox and cycle Configurations used by the galleries...
    
    fancy_linklist = {
						'padding'			: 0,
						'overlayOpacity'	: .9,
						'type'              : 'image',
						'titleShow'			: false,
						'overlayColor'		: '#000'
					};
					
	fancy_video = {
						'padding'			: 0,
						'overlayOpacity'	: .9,
						'type'              : 'inline',
						'titleShow'			: false,
						'overlayColor'		: '#000'
					};
	
	fancy_shopswitch = {
						'padding'			: 20,
						'overlayOpacity'	: .9,
						'type'              : 'inline',
						'titleShow'			: false,
						'overlayColor'		: '#000'
					};
	
					
	cycle_bigimg = {
						'delay'				: 10000,
						'speed'				: 200,
						'next'				:'#gal_nxt',
						'prev'				:'#gal_prev',
						'pause'				: 1
					};	


	image_p = {
						'padding'			: 30,
						'overlayOpacity'	: .9,
						'titleShow'			: false,
						'overlayColor'		: '#000'
					};					
	
	
	$('#videopopup').fancybox(fancy_video);
	$('#videopopup2').fancybox(fancy_video);
	$('#videopopup3').fancybox(fancy_video);
	$('#popupanmeldung1').fancybox(fancy_video);
	
	$('.popup').fancybox(image_p);
	
	//$('#menu-item-1595 a, #menu-item-1596 a, .shopcall, .bestellknopf').fancybox(fancy_shopswitch);
	
	// dynamic positioning of the lower cross
	if ($('.cross.dynamic').length) $('.cross.dynamic').css('top', (($('.crossanchor').position().top+$('.crossanchor').height()+5)+'px'));

	/* AUGMENTFUNCTIONS */
	
	function activateAugment(augcount){
		//find the Augment and -Col weĞre talking about
		var col = $('.augmentic .col:eq('+augcount+')').stop();
		var aug = $('#augments div:eq('+augcount+')').stop();
				
		//calulate the new positions for the fancy crosses
    	var ucl = col.offset().left - col.offsetParent().offset().left - 10 + col.width();
		var lcl = col.offset().left - col.offsetParent().offset().left - 30;
		
		// scroll down to the Augment area befor the magic begins
		//$('html:not(:animated),body:not(:animated)').animate({ scrollTop: $('#augmentarea').offset().top }, 300);		
			
		if(col.data('activated') != true){
		// magic
			$('h3', col).stop().animate({'backgroundColor': '#000', 'color': '#fff'}, 100, function(){col.data('activated', true)});
			aug.css('background-position', 'bottom');
			$('#shemeframe img').stop().css('left', +(augcount*(-140))+'px').animate({'opacity':1},100);

		// pull our fancy crosses to their new positions
			$('#upper_crossbar .cross').stop().animate({'left': ucl+'px', 'opacity':'1'}, 100);
			$('#lower_crossbar .cross').stop().delay(100).animate({'left': lcl+'px', 'opacity': 1}, 100);	
		}
		else{
			aug.stop();
			col.stop();
		}	
    }
    
    function deactivateAugment(augcount){
		//find the Augment-Col weĞre talking about
		var col = $('.augmentic .col:eq('+augcount+')').stop();
		var aug = $('#augments div:eq('+augcount+')').stop();
		// magic		
		$('h3', col).stop().delay(501).animate({'backgroundColor': '#fff', 'color': '#000'}, 100, function(){aug.stop().css('background-position', 'top');col.data('activated', false)});
		$('#shemeframe img').stop().delay(800).animate({'opacity':'0'},100);
		
		// pull our fancy crosses back to standard position
		$('#upper_crossbar .cross').stop().delay(501).animate({'left': '-19px', 'opacity': 0}, 100);    
    	$('#lower_crossbar .cross').stop().delay(501).animate({'left': '-19px', 'opacity': 0}, 100);
    }

    //Remove 'nojs'-Class from Body Tag to deactivate our CSS-Definitions for non-js-use
    $('body').removeClass('nojs');
    
    
    // fancy fancyboxing to happen...
    $("a#vlink").fancybox({
    	'overlayOpacity': .8,
    	'titleShow': false,
    	'margin': 0,
    	'padding': 0,
		'modal' : true,
		'type' : 'inline'		 
	});

    //Submenu Links
    $('#menu-inpagenavigation li a, #menu-inpagenavigation_en li a').not('li.current_page_item a').hover(

    function() {
        				$(this).addClass("liactive");
        				$(this).stop().animate({ height: '30px' }, 70);
        }, function() {
       					$(this).removeClass("liactive");
        				$(this).stop().animate({ height: '25px' }, 70);
    			});

    //Mainmenu Links
//    $('#menubar>ul>li').not('#menubar ul li ul *').hover(
/*
    $('#menubar>ul>li').hover(

    function() {
        $(this).find('a:eq(0)').stop().animate({
            'border-bottom': '5px solid black',
            backgroundColor: '#fff',
            color: '#000'
        }, 100);
    }, function() {
        $(this).find('a:eq(0)').stop().delay(300).animate({
            'border-bottom': '0px solid black',
            backgroundColor: '#000',
            color: '#fff'
        }, 100);
    });

    $('#menubar ul li ul li').unbind('mouseout mouseover');
*/
    //Superfish for Mainmenu
    if (!agentID){
    	$("#menu-hauptnavigation, #menu-hauptnavigation_en").superfish();
    }

    //Languageswtich
    $('ul#lang').hover(

    function() {
        $('a:first-child', this).stop().animate({
            backgroundColor: '#000',
            color: '#fff'
        }, 200, function() {
            $(this).parent().parent().stop().animate({
                height: '80px'
            }, 200);
        });
    }, function() {
        $(this).stop().delay(800).animate({
            height: '15px'
        }, 200, function() {
            $('a:first-child', this).stop().animate({
                backgroundColor: '#fff',
                color: '#787878'
            }, 200);
        });

    });


    $(' ul#lang a:gt(0)').hover(

    function() {
        $(this).stop().animate({
            backgroundColor: '#fff',
            color: '#787878'
        }, 100);
    }, function() {
        $(this).stop().delay(50).animate({
            backgroundColor: '#000',
            color: '#fff'
        }, 100);
    });

    //Searchform
    $('#search').hover(

    function() {
        $('form', this).stop().animate({
            width: '170px',
            opacity: 1
        }, 200, function() {
            $('#searchfield', this).focus().select();
        });
    }, function() {
        if (!($('#searchfield').val() != 'Suche')) $('form', this).stop().animate({
            width: '0',
            opacity: 0
        }, 200);
    })

    $('#searchfield').change(

    function() {
        if ($(this).val() == '') $(this).parent().stop().delay(501).animate({
            width: '0',
            opacity: 0
        }, 200).find('#searchfield').val('Suchen');
    });
    
    
    // Augments
    
    $('#augments div').hover(function(){
		var augcount = $('#augments div').index($(this));
		activateAugment(augcount);
    },
    function(){
		var augcount = $('#augments div').index($(this));
		deactivateAugment(augcount);
	});
	
	$('.augmentic .col').hover(function(){
		var augcount = $('.augmentic .col').index($(this));
		activateAugment(augcount);
    },
    function(){
		var augcount = $('.augmentic .col').index($(this));
		deactivateAugment(augcount);
	});

/*
	$('a[href*=#]').click(function() {
	   var duration=1000;
	   var easing='swing';
	   var newHash=this.hash;
	   var target=$(this.hash).offset().top;
	   var oldLocation=window.location.href.replace(window.location.hash, '');
	   var newLocation=this;
	   if(oldLocation+newHash==newLocation)
	   {
	      $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
	         window.location.href=newLocation;
	      });
	      return false;
	   }
	});

*/
	// Martin menubar sub-menu Width
	
	//$('#menu-hauptnavigation UL.sub-menu')

});

