//Homepage Animation
var inter;
var count = 0;
$(window).load(function() {

    var imgLength = $(".segment").length;
    var Div = $(".segment")[0];
    $(Div).addClass("active");
    var src = $(Div).find(".ImgLarge img").attr("src");
    $(".firstImage").attr("src", src);
    $(".secondImage").attr("src", src);
    var html = $(Div).find("#imgTitle").html();
    var staticText = $(Div).find(".staticText").html()
    //$(".nivo-caption").find(".staticText").html(staticText);
    //$(".nivo-caption").html(html);
    var staticText = $(Div).find("#staticText").html();
    $(".nivo-caption").find("#static").html(staticText);
    var floatingsmall = $(Div).find("#floating-small").html();
    $(".nivo-caption").find("#floating").html(floatingsmall);
    var floatingLarge = $(Div).find("#floatingLarge").html();
    $(".nivo-caption").find("#fLarge").html(floatingLarge);
    
    if (floatingsmall.length < 66) {
        $("#static").css("margin-top", "0px");
    }
    else {
        $("#static").css("margin-top", "-100px");
       // $("#static").css("margin-top", "-112px");
    }

    inter = setInterval(function() { Rotate(); }, 10000);

});
$('.segment').click(function() {
clearInterval(inter);
    if (!($(this).hasClass("active"))) {


        var src = $(this).find(".ImgLarge img").attr("src");
        //var html = $(this).find("#imgTitle").html();
        $(".secondImage").attr("src", src);
        $(".nivo-caption").find("#static").html('');
        $(".nivo-caption").find("#floating").html('');
        $(".nivo-caption").find("#fLarge").html('');
        var staticText = $(this).find("#staticText").html();
        var floatingsmall = $(this).find("#floating-small").html();
        var floatingLarge = $(this).find("#floatingLarge").html();
        $(".firstImage").fadeOut(1000, function() { $(".nivo-caption").find("#static").html(staticText); });
        $(".secondImage").fadeIn(1000, function() { $(".nivo-caption").find("#floating").html(floatingsmall); });
        $(".nivo-caption").find("#staticText").html(staticText);
        $(".nivo-caption").find("#fLarge").html(floatingLarge);
        $(".secondImage").addClass("warpperImage");
        $(".firstImage").addClass("secondImage");
        $(".warpperImage").removeClass("secondImage");
        $(".secondImage").removeClass("firstImage");
        $(".warpperImage").addClass("firstImage");
        $(".firstImage").removeClass("warpperImage");
        $('.active').removeClass("active");
        $(this).addClass("active");
    }

});

function Rotate() {

    var next;
    next = $(".active").next();
    if ($(next).html() == null) {
        next = $(".segment")[0];
    }
   
    var src = $(next).find(".ImgLarge img").attr("src");
    //var src = $(next).find("img").attr("src").replace("_thumb.gif.aspx", ".gif.aspx");
    var html = $(next).find("div").html();
    $(".secondImage").attr("src", src);
    $(".nivo-caption").find("#static").html('');
    $(".nivo-caption").find("#floating").html('');
    $(".nivo-caption").find("#fLarge").html('');
    var staticText = $(next).find("#staticText").html();
    var floatingsmall = $(next).find("#floating-small").html();
    var floatingLarge = $(next).find("#floatingLarge").html();
    $(".firstImage").fadeOut(1000, function() { $(".nivo-caption").find("#static").html(staticText); });
    $(".secondImage").fadeIn(1000, function() { $(".nivo-caption").find("#floating").html(floatingsmall); });
    $(".nivo-caption").find("#staticText").html(staticText);
    $(".nivo-caption").find("#fLarge").html(floatingLarge);
    $(".secondImage").addClass("warpperImage");
    $(".firstImage").addClass("secondImage");
    $(".warpperImage").removeClass("secondImage");
    $(".secondImage").removeClass("firstImage");
    $(".warpperImage").addClass("firstImage");
    $(".firstImage").removeClass("warpperImage");
    $('.active').removeClass("active");
    $('.active').removeClass("active");
    $(next).addClass("active");
    
    if (floatingsmall.length < 66) {
        $("#static").css("margin-top", "0px");
    }
    else {
        $("#static").css("margin-top", "-100px");
    }
}

//Homepage END

