// post-submit callback
/*
/function ajaxShowResponse(responseText, statusText)  {
     alert('status: ' + statusText + '\n\nresponseText: \n' + responseText );
}

function ajaxShowMessage(responseText, statusText)  {
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText );
}
/*
function AjaxRequestHandler(handlerUrl, action, input_data){
	$.ajax({
		type: 'POST',
		url: handlerUrl,
		data: {'action':action, 'data':input_data},
		dataType: 'json',
		async: false,
		error: function(xhr, status, errorThrown){
			alert('Er is een fout opgetreden tijdens het doorgeven van deze actie!');
		},     		
		success: function(data, status){
			if(data==undefined || data.rc==undefined){
				alert('Onverwachte reactie ontvangen van de server!');
			}else if(data.rc=='1'){
				/* var e = $('div.balloonData');
				e.html(data.c);
				alert('test');
			}else{
				alert(data.msg);
			}	   		
		}    	
	});
}*/

function resize(Background) {
	if( Background ) {
		if( !Background.aspectRatio ) {
			if( Background.offsetWidth && Background.offsetHeight ) {
				Background.aspectRatio = Background.offsetWidth / Background.offsetHeight;
			} else {
				return;
			}
		}
		var Width = window.innerWidth || document.body.clientWidth;
		var Height = window.innerHeight || document.body.clientHeight;
		if( ( Width/Height) > Background.aspectRatio ) {
			Background.style.width = '100%';
			Background.style.height = '';
		} else {
			Background.style.width = '';
			Background.style.height = '100%';
		}
	//} else {
	//	alert("No background ID found");
	}
}

$( window ).bind( 'resize load', function() { 
	var BackgroundImg = document.getElementById( 'BackgroundImage' );
	resize(BackgroundImg);
	/* var BackgroundImg = document.getElementById( 'BackgroundImageOverlay' );
	resize(BackgroundImg);*/	
	//resize();
});

//Diashow
function slideSwitch() {
    var $active = $('#SlideHolder IMG.active');

    if ( $active.length == 0 ) $active = $('#SlideHolder IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#SlideHolder IMG:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(document).ready( function() {
	$('ul#LeftMainMenu').find('a.Active').bind('click', function(e) {
		if( $(this).next().find('li.Active').length > 0 ) {
			
		} else {
			e.preventDefault();
			if( $(this).next().css('display') == 'block' ) {
				$(this).css('background-position', '0 56px');
				$(this).next().toggle();
			} else {
				$(this).css('background-position', 'left bottom');
				$(this).next().toggle();
			}
		}
	});
	
	/*
	 * Order popup
	 * Set value op input box when checking checkbox
	 */
	$('input:checkbox').click(function() {
		var checkBoxes = $("input:checkbox");
		$.each(checkBoxes, function() {
			var InputField =  $(this).attr( 'name' ).replace('Checked','Quantity');
			if ($(this).attr('checked')){
				//console.log( 'Checked:'+ $(this).attr( 'name' ) + ' - ' + InputField );
				if( $('input[name$='+InputField+']').val() == 0 ){
					$('input[name$='+InputField+']').val('1');
				}
			} else {
				//console.log( 'Not checked:'+ $(this).attr( 'name' ) + ' - ' + InputField  );
				$('input[name$='+InputField+']').val('0');
			} 
		});
	});
	
	$('input:text').blur(function() {
		var InputField =  $(this).attr( 'name' ).replace('Quantity','Checked');
		if( $(this).val() > 0 ){
			$('input[name$='+InputField+']').attr('checked','checked');
		} else {
			$('input[name$='+InputField+']').removeAttr('checked');
		}
	});
	
});

$(function() {
    setInterval( "slideSwitch()", 4000 );
});

