function isEven(value){
	if (value%2 == 0)
		return true;
	else
		return false;
}
function isDividable(value, index){
	if (value%index == 0)
		return true;
	else
		return false;
}

$(document).ready(
	$(function() {
	    // Webkit browsers Loads CSS + scripts simultaniously, so we need to pause loading scripts a bit before loading css.
	    if (jQuery.browser.safari && document.readyState != "complete") {
	        //console.info('ready...');
	        setTimeout(arguments.callee, 100);
	        return;
	    }

	    // BEGIN : Add the fun from here...


	    $('input.primary').bind('click', function() {
	        //$("#valueholder").html("id:" + $(this).attr("id") + " - Value:" + $(this).attr("value"));
	        var str = $(this).attr("id");
	        var disable_elm = new Array();
	        disable_elm = str.split("_");
		//alert(disable_elm[0]);
	        $("#" + disable_elm[0] + "_alternativ").attr("disabled", this.checked);
	        $("#" + disable_elm[0] + "_voksneantal").attr("disabled", !this.checked);
	        $("#" + disable_elm[0] + "_ungeantal").attr("disabled", !this.checked);
	        $("#" + disable_elm[0] + "_prisgruppea").attr("disabled", !this.checked);
	        $("#" + disable_elm[0] + "_prisgruppeb").attr("disabled", !this.checked);
	        //$("#" + disable_elm[0] + "_isalt").attr("disabled", this.checked);

		if(this.checked) 
			{$("#" + disable_elm[0] + "_isalt").val("0");}

		if($("#" + disable_elm[0] + "_alternativ").checked)
			{$("#" + disable_elm[0] + "_tmp").val("1");}
			
		if(!this.checked && $("#" + disable_elm[0] + "_alternativ").attr("disabled")) 
			{$("#" + disable_elm[0] + "_isalt").val("1");}

//		alert($("#" + disable_elm[0] + "_alternativ").attr("disabled"));

		if(this.checked && $("#" + disable_elm[0] + "_alternativ").attr("disabled")) 
			{$("#" + disable_elm[0] + "_isalt").val("0");}
	        
 		if(!this.checked && $("#" + disable_elm[0] + "_tmp").val() == '1')
			{
			$("#" + disable_elm[0] + "_isalt").val("1");
//		        $("#" + disable_elm[0] + "_alternativ").attr("disabled", !$("#" + disable_elm[0] + "_isalt").val("1"));
		        $("#" + disable_elm[0] + "_voksneantal").attr("disabled", !$("#" + disable_elm[0] + "_isalt").val("1"));
		        $("#" + disable_elm[0] + "_ungeantal").attr("disabled", !$("#" + disable_elm[0] + "_isalt").val("1"));
		        $("#" + disable_elm[0] + "_prisgruppea").attr("disabled", !$("#" + disable_elm[0] + "_isalt").val("1"));
		        $("#" + disable_elm[0] + "_prisgruppeb").attr("disabled", !$("#" + disable_elm[0] + "_isalt").val("1"));
			}

	    });
	    $('input.alternativ').bind('click', function() {
	        //$("#valueholder").html("id:" + $(this).attr("id") + " - Value:" + $(this).attr("value"));
	        var str = $(this).attr("id");
	        var disable_elm = new Array();
	        disable_elm = str.split("_");
		//alert(disable_elm[0]);
	        //$("#" + disable_elm[0] + "_alternativ").attr("disabled", this.checked);
	        $("#" + disable_elm[0] + "_voksneantal").attr("disabled", !this.checked);
	        $("#" + disable_elm[0] + "_ungeantal").attr("disabled", !this.checked);
	        $("#" + disable_elm[0] + "_prisgruppea").attr("disabled", !this.checked);
	        $("#" + disable_elm[0] + "_prisgruppeb").attr("disabled", !this.checked);
		if(this.checked){$("#" + disable_elm[0] + "_isalt").val("1");}else {$("#" + disable_elm[0] + "_isalt").val("0");}
		if(this.checked){$("#" + disable_elm[0] + "_tmp").val("1");}else{$("#" + disable_elm[0] + "_tmp").val("0");}

	    });


	    

	    //	    $('input.alternativ').bind('click', function() {
	    //	        $("#valueholder").html("id:" + $(this).attr("id") + " - Value:" + $(this).attr("value"));
	    //	    });


	    // validate signup form on keyup and submit
	    $("#form1").validate({
	        rules: {
	            formNavn: "required",
	            formAdresse: "required",
	            formPostnr: {
	                required: true,
	                minlength: 4,
	                number: true
	                
	            },
	            formBy: {
	                required: true
	            },
//	            formTelefon: {
//	                required: true,
//	                minlength: 8
//	            },
	           formEmail: {
	                required: true,
	                email: true
	            },
	            SKU: {
	                required: true,
	                minlength: 3
	            }

	        },
	        messages: {
	            formNavn: "Udfyld venligst dit navn",
	            formAdresse: "Udfyld venligst din adresse",
	            formPostnr: {
	                required: "Venligst udfyld dit postnummer",
	                minlength: "Udfyld venligst et gyldigt postnummer med minimum 4 cifre",
	                number: "Et postnummer indeholder ikke bogstaver"
	            },
	            formBy: "Venligst udfyld din by",
	            formTelefon: {
	                required: "Venligst udfyld dit telefonummer",
	                minlength: "Udfyld venligst et gyldigt telefonnummer med minimum 8 cifre"
	            },
//	            formEmail: {
//	                required: "Venligst udfyld din email",
//	                email: "Udfyld venligst en gyldig email"
//	            },
	            SKU: {
	                required: "Dine 3 favoritter skal udfyldes",
	                minlength: "Udfyld venligst minimum 3 favoritter"
	            }
	        },
	        // the errorPlacement has to take the table layout into account 
	        errorPlacement: function(error, element) {
	            if (element.is(":radio"))
	                error.appendTo(element.parent().next().next());
	            else if (element.is(".primary:checkbox")) {
	                $("#customErrorField").addClass('error');
	                error.appendTo("#customErrorField");
	            }
	            else
	                error.appendTo(element.parent());
	        }
	    });


	    // Lighbox functionality
	    $("a.lightbox").fancybox({
	        'autoDimensions': true,
	        'titleShow': true,
	        'transitionIn': 'elastic',
	        'transitionOut': 'elastic',
	        'easingIn': 'easeOutBack',
	        'easingOut': 'easeInBack'
	    });
              
	    if ($('.slidepanel_content').length != 0) {
	   var scrollValue =  $('.slidepanel_content ul').children().size() / 6;
	   var count = $('.slidepanel_content ul').children().size();
		if (isDividable(count, 2)) {scrollValue = 2;} 
		if (isDividable(count, 3)) {scrollValue = 3;} 
		if (isDividable(count, 4)) {scrollValue = 4;} 
		if (isDividable(count, 5)) {scrollValue = 5;} 
		if (isDividable(count, 6)) {scrollValue = 6;} 
		if (isDividable(count, 7)) {scrollValue = 7;} 
		if (isDividable(count, 8)) {scrollValue = 8;} 
		if (isDividable(count, 9)) {scrollValue = 9;} 
		if (isDividable(count, 10)) {scrollValue = 10;} 

	        // Jcarousel functionality
	        $(".slidepanel_content").jCarouselLite({
	            auto: 2000,
		    start: 0,
                    speed: 1000,
	            visible: $('.slidepanel_content ul').children().size(),
	            scroll: 1, //scrollValue,
	            easing: "linear"
//	            easing: "easeInOutExpo"
	        });
	    }
//	    //else { alert("slidepanel_content does not exist"); }

	    // END : ...to here

	})
);