

//Cufon.replace('h1'); 
//Cufon.replace('h2'); 
//Cufon.replace('.t5blink'); 
//Cufon.replace('.landing_banners a strong'); 
//Cufon.replace('.banner-text');

$(function(){

    $("ul#sitemap > li:has(ul)").prepend('<a class="minus" href="#">-</a>');
       
    $("ul#sitemap > li > ul li:has(ul)").prepend('<a class="plus" href="#">+</a>');
    
    $("ul#sitemap > li:not(:has(ul)),ul#sitemap > li > ul li:not(:has(ul))").prepend('<span>&nbsp;&nbsp;</span>');
    
    $("ul#sitemap > li > ul li ul").hide();
    
    
    
    $("#sitemap .plus").live("click",function(){
        $(this).html("-").addClass("minus").removeClass("plus");
        
        if ($(this).parent().parent().attr("id") == "sitemap")
        {
            $(this).parent().children("ul").slideDown("fast");
        }
        else
        {
            $(this).parent().find("ul").slideDown("fast");
        }
        
        return false;
    });
    
    $("#sitemap .minus").live("click",function(){
        $(this).html("+").addClass("plus").removeClass("minus");
        $(this).parent().find("ul").slideUp("fast");
        
        return false;
    });

    var originalFontSize = $('body').css('font-size');

    $("li.size a").live('click', function(){        
        if ($("body").hasClass("font-up")) {
            $("body").removeClass("font-up");
        }
        else {
            $("body").addClass("font-up");
        }
    });



    $("ul.navigation > li.active > a").click(function(){
    
        $("ul.navigation > li.active ul").toggle();
        return false;
    
    
    });





    //$('[id^="img_"]').addClass("hidden");
    $(".menu-body").hide();
    $(".block-paving").show();


    //Side menu put the arrow-white
    $(".side-menu ul li").hover(function() {
        $(this).children().css("color", "white");

        var pos = $(this).position();

        $(".arrow-side").css("top", pos.top + 8);
        $(".arrow-side").css("left", pos.left - 12);
        $(".arrow-side").show();


    },
                function() {
                    $(this).children().css("color", "#ccff99");
                    $(".arrow-side").hide();
                }
            );

    //Bottom menu   
//    $(".bottom-menu ul li a").live('click', function() {
//        //Change color bottom menu arrows
//        $(".selected .arrow-white").addClass("hidden");
//        $(".selected .arrow-green").removeClass("hidden");

//        //hide all side menu pictures
//        //$('[id^="img_"]').addClass("hidden");

//        //Select current menu item
//        $(".selected").removeClass("selected");
//        $(this).parent().addClass("selected");

//        //Change color bottom menu arrows
//        $(".selected .arrow-white").removeClass("hidden");
//        $(".selected .arrow-green").addClass("hidden");


//        //Hide previous selected menu
//        $(this).parents(".menu-body").hide();

//        //Show current selected menu        
//        var ftClass = $(this).attr("class");
//        $(".menu-body." + ftClass).show();
//        $(".menu-body." + ftClass + " .main-image").removeClass("hidden");
//        //Copy previous menu to new menu
//        $(".menu-body." + ftClass).children(".bottom-menu").html($(this).parents(".bottom-menu").html());

//        return false;

//    });


    //hover side-menu images
    $(".side-menu a").hover(function() {

        $(".main-image").addClass("hidden");

        $('[id^="img_"]').addClass("hidden");

        var id = $(this).attr("id");

        id = id.replace("link_", "img_");

        $("#" + id).removeClass("hidden");


    });


	$('.drop-down-wrap a.sprite').hover(function(){
		var theParent = $(this).parent();
		$('ul',theParent).show();
	}, function(){
		var theParent = $(this).parent();
		$('ul',theParent).hide();
	});
	$('.drop-down-wrap ul').hover(function(){
		$(this).show();
	}, function(){
		$(this).hide();
	});
	$('.menu-box .menu li').hover(function(){
		$(this).addClass('hovered');
	},function(){
		$(this).removeClass('hovered');
    });


    $('.mask').slides({
        container: 'slide-wrap',
        paginationClass: 'slide-nav',
        play: 5000,
        pause: 2500,
        slideSpeed: 1000,
        hoverPause: true,
        preload: true
    });

    //setTimeout(function() { $(".mask").show() },1000);

    // for landing page
    startTimer();
    
//    $("#toggle_footer").click(function(){
//        
//        $("div.landscaping-footer-container").slideToggle();
//        $('html, body').animate({
//        scrollTop: $("div.landscaping-footer-container").offset().top
//        }, 2000);
//        
//    });

});


// Begin landing page script

$(function() {
    $('.middle ul li').hover(function() {
        $('.middle ul li').removeClass('hovered');
        $(this).addClass('hovered');

        //check the number of the element you are at
        var x = $('.middle ul li').index(this);

        //stop the loop and pass the element number so
        //it knows where to start from
        stopLoop(x);
        stopCount();
    }, function() {
        $(this).removeClass('hovered');

        //start the timer again
        startTimer();
    });
});


var firstElement = 0;
var c = 0; 	// timer starts from 0 seconds
var t; 	// will hold the timer object
var b; 	// will hold the loop timer object
var timer_is_on = 0; // timer is halted if 0, on if is 1


function timer() {
    c = c + 1;
    if (c <= 4) {
        t = setTimeout("timer()", 1000);
    } else {
        stopCount();
        loopthrough();
    }
}
function startTimer() {
    if (!timer_is_on) {
        timer_is_on = 1;
        timer();
    }
}
function stopCount() {
    clearTimeout(t);
    timer_is_on = 0;
}
function stopLoop(x) {
    clearTimeout(b);
    timer_is_on = 0;
    c = 0;
    firstElement = x + 1;
}
function loopthrough() {
    $(function() {
        $('.content li').removeClass('hovered');
        if (firstElement == 0) {
            $('.content li:eq(' + firstElement + ')').delay(3000).addClass('hovered');
        } else if (firstElement > 0 && firstElement <= 4) {
            $('.content li:eq(' + firstElement + ')').addClass('hovered');
        } else {
            firstElement = 0;
            $('.content li:eq(' + firstElement + ')').addClass('hovered');
        }
        firstElement++;
        b = setTimeout('loopthrough()', 3000);
    });
}

//End landing page script


function sendEmailToInstaller(){
    var installerData = $("#installer-form .form_content").attr("id").split("_");
    var name = "";
    var email = "";
    var pointerid= "";
    $("#installer-form .error").hide();
    $("#success_box.success").hide();
    
    if (installerData.length == 3)
    {
        email = installerData[1];
        name = installerData[0];
        pointerid = installerData[2];
    }
    
    if (validate("installer-form") && isValidEmail(email)){
        $.ajax({
            url: "/ajax/sendInstallerForm.aspx?installerName=" + name + "&installerEmail=" + email + "&installerPointerid=" + pointerid + "&" + $("#installer-form *").serialize(),
            success:
                function (data){
                    if (data != "SUCCESS"){
                        $("#installer-form .error").html("Error sending the form. Please try again.").show();
                    }
                    else{
                        $("#installer-form.form_holder").hide();
                        $("#success_box.success").show();  
                    }                
                }       
        });
        
    }else{
        $("#installer-form .error").html("Please fill the highlighted fields.").show();
    
    }

}


function sendEmailfromPromo(){
    $(".successBorders").removeClass("successBorders");
    $(".invalidBorders").removeClass("invalidBorders");
    var email = $("#form-promo .form_content").attr("id");
    $("#form-promo .error").hide();
    $("#form-promo .success").hide();
    var valid = true;
    $("#form-promo input,#form-promo textarea").each(function(){
        if (($(this).attr("name") == $(this).val())||($(this).val() == '')){
            $(this).addClass("invalidBorders");
            valid = false;
        }
        
        if ($(this).hasClass("isEmail")){
            if (!isValidEmail($(this).val()))
            {
                $(this).addClass("invalidBorders");
                valid = false;
            }
        
        }    
    });
    
    if (valid && isValidEmail(email)){
        $.ajax({
            url: "/ajax/sendInstallerForm.aspx?destinationEmail=" + email + "&formTitle=" + $("#form-promo h2").attr("title") + "&" + $("#form-promo *").serialize(),
            success:
                function (data){
                    if (data != "SUCCESS"){

                        $("#form-promo .error").html("Error sending the form. Please try again.").show();
                    }
                    else{

                        $("#form-promo input,#form-promo textarea,#form-promo select").addClass("successBorders");  
                        cleanForm("form-promo");
                    }                
                }       
        });
    
    
    
    }else{

        $("#form-promo .error").html("Please fill the highlighted fields.").show();
    
    }
    

}


function cleanForm(id){
    $("#"+ id + " .invalid").removeClass("invalid");
    $("#"+ id + " .error").hide();
    $("#"+ id + " input[type=text]").val("");    
        
    $("#"+ id + " input[type=checkbox]").attr("checked", false);    
        
    $("#"+ id + " textarea").html("");
        
    $("#"+ id + " select option").each(function(){
        if ($(this).attr("value") == "United Kingdom")
        {
            $(this).attr("selected","selected");
        }
    });
   

}

function scrollIntoView(element, container) {
  var containerTop = $(container).scrollTop(); 
  var containerBottom = containerTop + $(container).height(); 
  var elemTop = element.offsetTop;
  var elemBottom = elemTop + $(element).height(); 
  if (elemTop < containerTop) {
    $(container).scrollTop(elemTop);
  } else if (elemBottom > containerBottom) {
    $(container).scrollTop(elemBottom - $(container).height());
  }
}

