//Script.js

$(document).ready(function(){	
//----------------------------------------------- Document Ready : begin
var interval = 10000;
// ---------------------------------------------- begin pop-up note
$("a.notes").click(function(e){
	var position = $(this).position();
	var currentRel = $(this).attr('rel');
	var popup = $("#content").find("div#" + currentRel);
	var popupHeight = $(popup).height();
	position.top = position.top - popupHeight - 20;
	$('.note-container').hide();
	if(position.left > 300){ 
	position.left = 605 - position.left;
		$(popup).css("right", position.left).addClass('note-container-right');
	}
	else {
		position.left = position.left - 40;
		$(popup).css("left", position.left);
	}
	$(popup).css("top", position.top).css("height", popupHeight).show();
	e.stopPropagation();
});
$(".note-container").click(function(e){
	e.stopPropagation();
});
$(document).click(function() {
    $(".note-container").hide();
});

$("a.close").click(function(){
	$(".note-container").hide();
});

// ---------------------------------------------- end pop-up note
// ---------------------------------------------- begin front page slideshow
$('.slideshow').html('');
  var loopIndex;
  for (loopIndex=0;loopIndex<$('.images > div').length;loopIndex++){
    $('.slideshow').html($('.slideshow').html()+'<a class="circle" href="#"></a>');
  };
  
$(".slideshow").tabs(".images > div", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: "slow",
    interval: interval,
	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
}).slideshow({  interval: interval,
                rotate: true,
                clickable: false
    });

var flagSlideshow = $('.images > div').length;
if(flagSlideshow > 0) {
    clearInterval(sliderInterval);
    var sliderInterval=setInterval(function(){$(".forward").click();}, interval);
//    $(".slideshow").data("slideshow").play(); 
    $(".slideshow a").click(function(){
       clearInterval(sliderInterval);
       sliderInterval=setInterval(function(){$(".forward").click();}, interval);  
    }); 

    $(".slideshow, .cta-orange-big").mouseenter(function(){
       clearInterval(sliderInterval);
    }).mouseleave(function(){
       clearInterval(sliderInterval);
       sliderInterval=setInterval(function(){$(".forward").click();}, interval);
    });     
}

// ---------------------------------------------- end front page slideshow
$("#navigation ul li:first").addClass("first");
$("#footer ul li:first").addClass("first");


// -------------------------------------drop down navigation
	
	$("#navigation ul li").mouseenter(function(){
			
			var list = $(this).find("ul");
			var no_list = list.length;
			if(no_list > 0)
			{
				$(this).find("ul").show();
				$(this).addClass("sub");
			}
			
		});
		 $("#navigation ul li").mouseleave(function(){
			$(this).find("ul").hide();
			$(this).removeClass("sub");
		});
		$("#navigation ul li").mouseenter(function(){
		 $(this).addClass("hoverMenu");
		});
		$("#navigation ul li").mouseleave(function(){
		 $(this).removeClass("hoverMenu");
		});
// ----------------------------------- end drop-down navigation

// ----------------------------------- clear input
    (function($){
    $.fn.clearDefault = function(){
    return this.each(function(){
    var default_value = $(this).val();
    $(this).focus(function(){
    if ($(this).val() == default_value) $(this).val("");
    });
    $(this).blur(function(){
    if ($(this).val() == "") $(this).val(default_value);
    });
    });
    };
    })(jQuery);
     
    $('.searchField').clearDefault();
    // $('input[type=text]').clearDefault();
	$('textarea').clearDefault();
	
// --------------------------------- end clear input

$("#sideForm input").click(function(){
    $("#thankyou").hide();
});

$("#sideForm textarea").click(function(){
    $("#thankyou").hide();
});

//----------------------------------------------- Document Ready : end	
});

var ajax =
{
    shortContactSubmit: function()
    {
        if ($("#contact_message").val() == "Please tell us your business issue...")
            $("#contact_message").val("");

        var params = $("#sideForm").serialize();
        var url = "en/ajax-contact-en";
        $.post(url, params, function(data)
        {
            $("#sideForm").submit();
            var isSuccess = true;
            $.each(data, function(index, value){
                $("#error_" + index).html(value);
                if (value)
                    $("#error_" + index).prev().find(".required").addClass("red");
                else
                    $("#error_" + index).prev().find(".required").removeClass("red");
               
                if (value)
                    isSuccess = false;
            });
            if (isSuccess)
            {
                $('#sideForm').get(0).reset();
                $('#sideForm .required').removeClass("red");
                
                $("#thankyou").show();
                $(".contact-form").hide();
            }
            else
                if ($("#contact_message").val() == "")
                    $("#contact_message").val("Please tell us your business issue...");
        }, "json");
    },

    fullContactSubmit: function(button)
    {
        var form = $(button).closest("form")
        if ($("#contact_message").val() == "Please tell us your business issue...")
            $("#contact_message").val("");        
        var params = form.serialize();
        var url = "en/ajax-contact-en";
        form.submit();
        $.post(url, params, function(data)
        {
            var isSuccess = true;

            $.each(data, function(index, value){
                $("#error_" + index, form).html(value);
                if (value)
                    $("#error_" + index).prev().find(".required").addClass("red");
                else
                    $("#error_" + index).prev().find(".required").removeClass("red");
               
                if (value)
                    isSuccess = false;
            });
            if (isSuccess)
            {
                form.get(0).reset();
                $('.required', form).removeClass("red");

                $("#thankyou").show();
                $(".contact-form").hide();
                $(button).closest("div.ctPane").hide();

            }
            else
                if ($("#contact_message").val() == "")
                    $("#contact_message").val("Please tell us your business issue...");
            
        }, "json");
    }
}



