$(document).ready(function(){

/* ------------------------------------
    HOME PAGE SLIDES
--------------------------------------*/
    var activeSlide = 1;

    $("#home-slides-thumbs .item").mouseover(function(){
        id = $(this).attr("id");
        id = id.substring(id.length-1,id.length);
        offset = (190 * (id-1)) + 85;
        goTo = offset + "px";
        $('#home-slides-indicator span').stop();
        $('#home-slides-indicator span').animate({
            left: goTo
          },
          { duration: 200 }
        );
    });

    $("#home-slides-thumbs").mouseout(function(){
        offset = (190 * (activeSlide - 1)) + 85;
        goTo = offset + "px";
        $('#home-slides-indicator span').stop();
        $('#home-slides-indicator span').animate({
            left: goTo
          },
          { duration: 200 }
        );
    });
    
    $("#home-slides-thumbs .item").click(function(){
        id = $(this).attr("id");
        id = id.substring(id.length-1,id.length);
        if(id != activeSlide){
            $("#home-slides #slide-" + activeSlide).fadeOut('slow');
            $("#home-slides #slide-" + id).fadeIn('slow');
            activeSlide = id;
        }
    });
    
    $("#slide-left").mouseover(function(){
        $(this).css("background-position","left -52px")
    });
    $("#slide-left").mouseout(function(){
        $(this).css("background-position","left top")
    });
    $("#slide-left").click(function(){
        previousSlide = activeSlide - 1;
        if(previousSlide == 0) previousSlide = 5;
        $("#home-slides #slide-" + activeSlide).fadeOut('slow');
        $("#home-slides #slide-" + previousSlide).fadeIn('slow');
        activeSlide = previousSlide;
        offset = (190 * (previousSlide - 1)) + 85;
        goTo = offset + "px";
        $('#home-slides-indicator span').stop();
        $('#home-slides-indicator span').animate({
            left: goTo
          },
          { duration: 200 }
        );
    });

    $("#slide-right").mouseover(function(){
        $(this).css("background-position","left -52px")
    });
    $("#slide-right").mouseout(function(){
        $(this).css("background-position","left top")
    });
    $("#slide-right").click(function(){
        nextSlide = parseInt(activeSlide) + 1;
        if(nextSlide == 6) nextSlide = 1;
        $("#home-slides #slide-" + activeSlide).fadeOut('slow');
        $("#home-slides #slide-" + nextSlide).fadeIn('slow');
        activeSlide = nextSlide;
        offset = (190 * (nextSlide - 1)) + 85;
        goTo = offset + "px";
        $('#home-slides-indicator span').stop();
        $('#home-slides-indicator span').animate({
            left: goTo
          },
          { duration: 200 }
        );
    });
    
/* ------------------------------------
    OTHER
--------------------------------------*/
    $("#newsletter-form .input").focus(function(){
        if($(this).attr("value") == $(this).attr("title")){
            $(this).attr("value","");
        }
    });
    $("#newsletter-form .input").blur(function(){
        if($(this).attr("value") == ""){
            $(this).attr("value",$(this).attr("title"));
        }
    });

/* ------------------------------------
    MAILING
--------------------------------------*/

	$("#newsletter-form").submit(function(){
		var data = {};
		data['email'] = $("input[name=Email]", this).val();
		$.post("/tool/mailing-subscribe", data,
			function(result){
				$("#newsletter-message").html(result);
				$("input[name=Email]").val("")
			}, 
			"html"
		);
		return false;
	});

});



