var loaderSmall = '<img src="images/loaderSmall.gif" class="loaderSmall" width="66" height="66" alt="Lade..." />';


// (function($) {
	// $(document).ready(function() {
		// //$('a.on').removeClass('on')
		// //$('.anchor-' + location.hash.substr(1)).addClass('on')
		// //$('#navigation').append(loaderSmall);
		// //$('.loaderSmall').hide();
	// })
// })(jQuery)

function changeImage(nextImg) {

	if (nextImg.src == $('#supersized img').attr('src')) {
		return;
	}
	$('#supersized img').hide();
	$('#supersized img').attr('alt', nextImg.alt);
	$('#supersized img').one('load', function() {
		//$('.loaderSmall').hide();
		//$('.loaderSmall').remove();
		$('#supersized img').fadeIn(500);
	});
	$('#supersized img').attr('src', nextImg.src);
	//$('.loaderSmall').show();

}

 
	
$(function() {	
		
	$("#contactForm").validate({
		rules: {
			sender_email: {
				required: true,
				email: true
			},
			sender_interesse: {
				required: true
			},
			sender_name: {
				required: true,
				minlength: 2
			},
			message: {
				required: true,
				minlength: 2
			}
		}
	});
	
		
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'xy';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	
	
	$("#navigation").draggable();
	
	
	var nextImg = {};
	$(".sup").click(function(){
	
		nextImg.src = $(this).attr('loadImg');
		nextImg.alt = $(this).attr('loadImgAlt');
		
		if ($("#contentInner").is(":hidden")) {
			changeImage(nextImg);
		}
		
		$("#navigation a").each(function(){
//			$(this).removeClass('on');
		});
		
		
		
		//$('li.'+$(this).attr('class').replace(/\s/g, '.')).siblings().find('a').removeClass('on');
		//$('li.'+$(this).attr('class').replace(/\s/g, '.')).find('a').addClass('on');
	});
	
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: '#content', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
			if (!$("#contentInner").is(":hidden")) {
				changeImage(nextImg);
				// track on google analytics
				_gaq.push(['_trackPageview', "/#" + anchor.id]);
				
			}
		}
	});	
	
	
	$("#hideText").click(function(){
		if ($("#contentInner").is(":hidden")) {
			$("#contentInner").fadeIn();
			$(this).css('backgroundImage', 'url(\'images/verstecken.png\')');
		} else {
			$("#contentInner").fadeOut();
			$(this).css('backgroundImage', 'url(\'images/anzeigen.png\')');
		}
	});
	
	
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var newHeigth = (windowWidth/3) * 2;	

	//first image
	var initImage = $("#navigation li.on").attr("loadImg");
	// var initImageAlt = $("#navigation li.on").attr("loadImgAlt");
	
	$.fn.supersized.options = {  
		startwidth: windowWidth,
		startheight: newHeigth,
		vertical_center: 1,
		slides : [
			{ 
				image : initImage,
				// imagealt: initImageAlt
			}
		]
	};
	
	$('#supersized').supersized();
	
	$('[rel="window_open"]')
	.each(function(link) {
		this.onclick = function(){
			var w = 610
			var h = 750
			var sw = screen.width
			var sh = screen.height
			var l = parseInt((sw-w)/2)
			var t = parseInt((sh-h)/2)
			var window_open = window.open(this.href, 'kayfly_window_open', 'width='+w+', height='+h+', top='+t+', left='+l+', scrollbars=yes, resizable=yes,menubar=no, location=yes');
			window_open.focus();
			return false;
		};
	});
var check_checkout = function() {
   if ($('#jcart #jcart-is-checkout').is(":checked") && $('#jcart #jcart-is-checkout-2').is(":checked")) {
    //enable button
    $('#jcart #jcart-paypal-checkout, #jcart #jcart-invoice-checkout').removeAttr('disabled');
  } else {
    //disable button
    $('#jcart #jcart-paypal-checkout, #jcart #jcart-invoice-checkout').attr('disabled', true);
  }

 }
 
 $(document).ready(check_checkout)
 $('#jcart #jcart-is-checkout').live('click', check_checkout)
 $('#jcart #jcart-is-checkout-2').live('click', check_checkout)
 
	// alternate invoice checkout
	
	var submit_invoice = function() {
		$('#checkout-form').attr('action','/invoiceCheckoutForm.php');
		//return false;
	}
	
	$('#jcart #jcart-invoice-checkout').live('click', submit_invoice);
 

//$('#jcart #cart-is-checkout').attr("disabled", "disabled");


 


});
