$(document).ready(function() {
	$('<div id="cache"><img src="/img/start/arbeitsraum.jpg" /><img src="/img/start/information.jpg" /><img src="/img/start/marke.jpg" /><img src="/img/start/mitarbeiter.jpg" /><img src="/img/start/start.jpg" /><img src="/img/information/fuss1.jpg" /><img src="/img/information/fuss2.jpg" /><img src="/img/information/fuss3.jpg" /></div>').appendTo('body');
	$('#leftstart ul li a').live('mouseover', function() {
		var className = $(this).attr('name');
		$('#start').hide().removeClass().addClass(className).show();
	});
	$('h1.fritz').live('mouseover', function(){
		$('#start').removeClass();
	});

	$('div.employee').live('click', function(){
		window.location.href = "/mitarbeiter";
	});

	$('div.redken').live('click', function(){
		window.location.href = "/marke";
	});
	
	$('#fanbox').hide();
	$('#tooltip').hide();
	/**
	 * callback function
	 */
	var phone_vacation = false;
	$('#callback').tooltip({
		bodyHandler: function() {
			return $('#tooltip').html();
		},
		showURL: false
	});
	
	$('.scroll-pane').jScrollPane();

	$('#callback').bind('click', function(){
		if ($.browser.msie && $.browser.version < 7) {
			return;
		}
		$.ajax({
			type: "GET",
			dataType: "html",
			url: $.url("/kontakt"),
			success: function(content){
				$("<div id='overlay'></div>").hide().css({opacity: 0.5}).appendTo('body').fadeIn('slow', function(){
					$("<div id='phoneservice' class='clearfix'></div>").hide().html(content).prependTo('#wrapper');
					$('#phoneservice').slideDown('slow', function(){
						$('#phoneservice .submit').css('display','block');
						// submit layer
						$(this).find('form').bind('submit', function() {
							$.post($.url('/kontakt'), $(this).serialize(), function(response) {
								$('#phoneservice').html(response);
							});
							return false;
						});
					});
				});
			}
		});
		return false;
	});
	// close Layer
	$('#overlay, a.close').live('click', function(){
		$('#phoneservice .submit').hide();
		$('#phoneservice').slideUp('slow', function(){
			$(this).remove();
			$('#overlay').fadeOut('slow', function(){
				$(this).remove();
			});
		});
		return false;
	});
	$('.selection a').live('mouseover', function(){
		$('.selection a').each(function(){
			var type = $(this).attr('class');
			$(this).data('class', type).removeClass();
		});
		$(this).addClass($(this).data('class'));
	}).live('mouseout', function(){
		$('.selection a').each(function(){
			$(this).addClass($(this).data('class'));
		});
	});
});



// Debugging-Function. Only active in Browser who support it
function pr() {
	if (!window.console) {
		return;
	}
	if (typeof window.console !== 'undefined' && typeof window.console.log === 'function') {
		console.log(pr.arguments);
	}
}

(function($) {
	// Produces correct URLs relative to Router::url('/)
	$.url = function(url) {
	  return $('meta[name=identifier-url]').attr('content')+url.substr(1);
	}

	$(function() {
		// Generate a Page-Object to bind events on
		window.Page = $('body');
		
		//Take care about the non-js fallback-version of the site 
		$('body').addClass('js').removeClass('no-js');
		 
		// Make external links open in a new window
		$('a[rel=external]').live('click', function() {
			window.open(this.href);
			return false;
		});

		// Fix Alpha-PNG's for IE6
		if ($.browser.msie && $.browser.version < 7) {
			$.ifixpng($.url('/js/jquery/ifixpng/pixel.gif'));
			$('img[src$=.png]').ifixpng();
		}

		// And now all the project-specific stuff to be executed ON READY
		$.local.func();
	});

	// Generate namespace for project-specific functions encapsulated in the jQuery $-namespace
	$.local = function() {};
	// Definition of project-specific function
	$.local.func = function() {
		
	};
})(jQuery);
