    function mycarousel_initCallback(carousel) 
    {
        // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function() {
            carousel.startAuto(0);
        });

        carousel.buttonPrev.bind('click', function() {
            carousel.startAuto(0);
        });

        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });
    };

    jQuery(document).ready(function () {

        var anchorsWidth = 0;
        
        $("#menu a").each(function () {
            anchorsWidth += $(this).width() + 30;
        });
               
        var width = $("#menu").width() - anchorsWidth;
        var lastWidth = $("#menu .last").width();

        $("#menu .last").css("width", lastWidth + width + "px");

        $("#menu .last").mouseenter(function () {
            $(this).siblings("#menu-right-corner").addClass("hover");
        }).mouseleave(function () {
            $(this).siblings("#menu-right-corner").removeClass("hover");
        });
        
        $(".a_submit").click(function(){  $("#reservation-form").submit(); });	
        
        $("#content a[target=_blank], #right-col a[target=_blank]").click(function () {
            $("<div id='modal-page'></div>").insertAfter("#wrapper");

            var uri = $(this).attr("href").split("/");
            var length = uri.length;
            var rewrite_string = "";

            if(uri[2] != "voucher")
            { 	
	            if (!uri[length]) {
	                rewrite_string = uri[length - 1];
	            }
	            else {
	                rewrite_string = uri[length];
	            }
	            
	            $("#modal-page").load("/default/ajax/load-simple-page-content?rewrite-string=" + rewrite_string).dialog({
	                height: 500,
	                width: 800,
	                modal: true
	            });
	            return false;
            }
            
            return true;
        });

        $("#language-button").click(function () {
            $(this).parent().children("ul").slideToggle("slow");

            return false;
        });

        $("#right-col #client-information .section-name").click(function () {
            var cl = $(this).attr("class").split(' ').slice(-1);

            if (cl != "active-section") {
                $(this).parent().children(".section-name").removeClass("active-section").next(".section").slideUp("slow");
                $(this).addClass("active-section");
                $(this).next(".section").slideToggle("slow");
            }
            else {
                $(this).parent().children(".section-name").removeClass("active-section").next(".section").slideUp("slow");
            }

            return false;
        });

        $("#right-col #city-information .section-name").click(function () {
            var cl = $(this).attr("class").split(' ').slice(-1);

            if (cl != "active-section") {
                $(this).parent().children(".section-name").removeClass("active-section").next(".section").slideUp("slow");
                $(this).addClass("active-section");
                $(this).next(".section").slideToggle("slow");
            }
            else {
                $(this).parent().children(".section-name").removeClass("active-section").next(".section").slideUp("slow");
            }

            return false;
        });

        $("#reservation #use-discount-code").click(function () {
            $(this).siblings("#discount-code-form").show();
            $(this).hide();
            $(this).next().children("#disc-input").attr("disabled", 0);
            return false;
        });

        $("#reservation-header .show-my-bookings").click(function () {
            $("#my-bookings").show();
            $("#reservation").hide();
        });

        $("#my-bookings-heading .show-make-reservation").click(function () {
            $("#reservation").show();
            $("#my-bookings").hide();
        });

        $("#search-location, #newsletter .input-text").focus(function () {
            if ($(this).siblings(".was-focus").val() == "false") {
                $(this).siblings(".was-focus").val(true);
                $(this).css("color", "#000");
                $(this).val("");
            }
        });


        $("#normal-font").click(function () {
            var increment = parseInt($("#font-inc").val());

            if (increment) {
                $("#left-col p, #left-col label, #left-col input, #left-col select, #left-col a, #left-col span, #left-col li, #footer p, .section-content").each(function () {
                    fontSize = parseFloat($(this).css("font-size").substring(0, $(this).css("font-size").length - 2));
                    fontSize -= increment;
                    $(this).css("font-size", fontSize + "px");
                });
            }

            $("#font-inc").val(0);

            return false;
        });

        $("#bigger-font").click(function () {
            var increment = parseInt($("#font-inc").val());

            if (increment) {
                $("#left-col p, #left-col label, #left-col input, #left-col select, #left-col a, #left-col span, #left-col li, #footer p, .section-content").each(function () {
                    fontSize = parseFloat($(this).css("font-size").substring(0, $(this).css("font-size").length - 2));
                    fontSize += (2 - increment);
                    $(this).css("font-size", fontSize + "px");
                });
            }
            else {
                $("#left-col p, #left-col label, #left-col input, #left-col select, #left-col a, #left-col span, #left-col li, #footer p, .section-content").each(function () {
                    fontSize = parseFloat($(this).css("font-size").substring(0, $(this).css("font-size").length - 2));
                    fontSize += 2;
                    $(this).css("font-size", fontSize + "px");
                });
            }

            $("#font-inc").val(2);

            return false;
        });


        $("#biggest-font").click(function () {
            var increment = parseInt($("#font-inc").val());

            if (increment) {
                $("#left-col p, #left-col label, #left-col input, #left-col select, #left-col a, #left-col span, #left-col li, #footer p, .section-content").each(function () {
                    fontSize = parseFloat($(this).css("font-size").substring(0, $(this).css("font-size").length - 2));
                    fontSize += (3 - increment);
                    $(this).css("font-size", fontSize + "px");
                });
            }
            else {
                $("#left-col p, #left-col label, #left-col input, #left-col select, #left-col a, #left-col span, #left-col li, #footer p, .section-content").each(function () {
                    fontSize = parseFloat($(this).css("font-size").substring(0, $(this).css("font-size").length - 2));
                    fontSize += 3;
                    $(this).css("font-size", fontSize + "px");
                });
            }

            $("#font-inc").val(3);
            return false;
        });

        jQuery('#mycarousel').jcarousel({
            visible: 1,
            scroll: 1,
            auto: 2,
            wrap: 'last',
            initCallback: mycarousel_initCallback
        });
        /*
        $("#left-col #cars > .car .a-car-view-more").click(function () {
        $(this).siblings(".car-info-view").slideDown("slow");
        return false;
        }); 

        $("#left-col #cars > .car .a-hide-car-info-view").click(function () {
        $(this).parent().slideUp("slow");
        return false;
        });*/

       
        $(".accessories-count").change(function () {
            var checkbox = $(this).parent().parent().children(".accessories-checkbox");
            var valArray = checkbox.val().split(";");

            var rate = valArray[3] * $(this).val();
            var margin = valArray[6] * $(this).val();

            if (rate > valArray[4] && valArray[4] > 0) {
                $(this).parent().next().children(".rate").text(valArray[3].toFixed(2));
                valArray[1] = valArray[4];
            }
            else {
                $(this).parent().next().children(".rate").text(rate.toFixed(2));
                valArray[1] = rate;
            }

            valArray[2] = $(this).val();
            valArray[5] = margin;

            checkbox.val(valArray.join(";"));
        });

        $("#acceptReservationPolicy").change(function () {
            $(this).next().next().slideToggle();
            $(this).siblings(".error").hide();
        });

        $("#acceptConditions").change(function () {
            $(this).parent().next().next().slideToggle();
        });

        $("#cancel-reservation").click(function () {
            if ($("#acceptReservationPolicy").is(":checked")) {
            	$(this).parent().submit();
            }
            else {
                $(this).siblings(".error").toggle();
                return false;
            }
        });

        $("#reservation-submit > input").click(function () {
            var html = "";

            html += validateForm();
            html += validateDates();

            if (html == "") {
                validateFormUsingAjax();
            }
            else {
                $.prompt(html);
            }

            return false;
        });

        $("#how-to-get-code, #ccv-prompt").click(function () {
            $.prompt($(this).children("span").text());

            return false;
        });

        $("#pickUpTime").change(function () {
            $("#dropOffTime").val($(this).val());
        });

        $("#footer #show-popular-countries").click(function () {
            $("#footer-content #popular-locations").slideUp("slow");
            $("#footer-content #popular-countries").animate({ height: "toggle", opacity: "toggle" }, 500);

            var cl = $(this).attr("class").split(' ').slice(-1);

            if (cl == "active") {
                $(this).removeClass("active");
            }
            else {
                $(this).addClass("active");
            }
            $(this).siblings("#show-popular-locations").removeClass("active");

            return false;
        });

        $("#footer #show-popular-locations").click(function () {
            $("#footer-content #popular-countries").slideUp("slow");
            $("#footer-content #popular-locations").animate({ height: "toggle", opacity: "toggle" }, 500);

            var cl = $(this).attr("class").split(' ').slice(-1);

            if (cl == "active") {
                $(this).removeClass("active");
            }
            else {
                $(this).addClass("active");
            }
            $(this).siblings("#show-popular-countries").removeClass("active");

            return false;
        });
       
    }); 
    
 function validateForm()
 {
	 var html = "";
	 
	 if(isEmpty($("#search-location").val())) html += $("#search-location-empty-translate").val();
	 if(isEmpty($("#drop-off").val())) html += $("#dropoff-empty-translate").val();
	 if(isEmpty($("#age").val())) html += $("#age-empty-translate").val();
	 
	 return html;
 }
    
 function validateDates()
 {
	 var html = "";
	 
	 var datepick1Val = $("#datepick1").val();
	 var datepick2Val = $("#datepick2").val();
	 
	 var dateFrom = datepick1Val.split("/");
	 var dateTo = datepick2Val.split("/");

	 var d1 = new Date(dateFrom[2], dateFrom[1], dateFrom[0]);
	 var d2 = new Date(dateTo[2], dateTo[1], dateTo[0]);
	 
	 var currentTime = new Date();
	 var month = currentTime.getMonth();
	 var day = currentTime.getDate();
	 var year = currentTime.getFullYear();
	 
	 var today = new Date(year, month, day); 

	 if(today >= d1)
	 {
		 html += $("#invalid-from-date-translate").val();
	 }
	 
	 if(today >= d2)
	 {
		 html += $("#invalid-to-date-translate").val();
	 }


     if (html == "") 
     {
         var timeFrom = $("#pickUpTime").val().split(":");

         d1 = new Date(dateFrom[2], (dateFrom[1] - 1), dateFrom[0], timeFrom[0], timeFrom[1], 0, 0);
         today = new Date(year, month, day, currentTime.getHours(), currentTime.getMinutes(), 0, 0);

         var difference = (d1.getTime() - today.getTime()) / (1000 * 3600);
   
         if (difference < 48) 
         {
             html = $("#invalid-reservation-time-translate").val(); 
         }
	 }

	 return html;
 }
    
 function validateFormUsingAjax()
 {	
	    var tmp = $("#drop-off").val().split(';');
	    
	    var pbDropOff = 0;
	    var nDropOff = 0;
	    
	    if(tmp[2] == "n") nDropOff = tmp[0];
	    if(tmp[2] == "p") pbDropOff = tmp[0];
	    
	 	$.ajaxSetup({
			url: "/default/ajax/validate-form"
		});

		$.ajax({
		    data:
	               {
	                   idProviderBranchPickUp: $("#hidden-id-provider-branch").val(),
	                   idNodePickUp: $("#hidden-id-node").val(),
	                   idProviderBranchDropOff: pbDropOff,
	                   idNodeDropOff: nDropOff,
	                   pickUpTime: $("#pickUpTime").val(),
	                   pickUpDate: $("#datepick1").val(),
	                   dropOffTime: $("#dropOffTime").val(),
	                   dropOffDate: $("#datepick2").val(),
	                   age: $("#age").val(),
	                   rand: randomNumber()
	               },
		    type: "GET",
		    dataType: "html",
		    timeout: 10000,

		    error: function (e) {
		        $.prompt("Server is not responding. Please try to repeat your request");
		    },

		    success: function (data) {
		        if (data == "")
                {
                    blockUI(); 
                    $("#reservation-form").submit();
		        }
		        else 
                {
		            $.prompt(data, { buttons: { Ok: true} });
		        }
		    }
		});
			
 }
 
 function isEmpty(value) 
 {
     var val = trim(value, 'both')
     return val.length == 0;
 }

 function trim(arg, func) 
 {
     var trimvalue = '';
     var arglen = arg.length;

     if (arglen < 1)
         return trimvalue;

     if (func == 'left' || func == 'both') 
     {
         i = 0;
         var pos = -1;

         while (i < arglen) 
         {
             if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) 
             {
                 pos = i;
                 break;
             }

             i++;
         }
     }

     if (func == 'right' || func == 'both') 
     {
         var lastpos = -1;
         i = arglen;

         while (i >= 0) {
             if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) 
             {
                 lastpos = i;
                 break;
             }

             i--;
         }
     }

     if (func == 'left') 
     {
         trimvalue = arg.substring(pos, arglen - 1);
     }

     if (func == 'right') 
     {
         trimvalue = arg.substring(0, lastpos + 1);
     }

     if (func == 'both') 
     {
         trimvalue = arg.substring(pos, lastpos + 1);
     }

     return trimvalue;
 }
