﻿var numberOfItems = 2;
var stopCycle = false;
var marginLeft = 0;
var animationID = 0;
$(document).ready(function() {
    $('img[src$=.png]').ifixpng();
    $("#carousel DIV.transwhite, #transorange").css("opacity", 0.5);
    $("#carousel").fadeIn("slow");
    animationID = setInterval("animateItems();", 40);
    $("#carousel").unbind().hover(function() {
        clearInterval(animationID);
        fadeOutItems();
    },
			function() {
			    clearInterval(animationID);
			    animationID = setInterval("animateItems();", 40);
			    $("#carousel .citem A").stop().animate({ opacity: 1.0 }, { duration: 300, queue: false });
			});
});
function fadeOutItems() {
    var mouseentered = false;
    $("#carousel .citem A").unbind().stop().animate({ opacity: 0.5 }, { duration: 300, queue: false });
    $("#carousel .citem A").unbind("mousemove").bind("mousemove", function() {
        if (!mouseentered) {
            $(this).stop().animate({ opacity: 1.0 }, { duration: 300, queue: false });
            mouseentered = true;
        }
    });
    $("#carousel .citem A").unbind("mouseout").bind("mouseout", function() {
        mouseentered = false;
        $(this).stop().animate({ opacity: 0.5 }, { duration: 300, queue: false });
    });
}
function animateItems() {
    if (marginLeft > -1200) {
        $("#carousel .citem").eq(0).css("margin-left", marginLeft--);
    } else {
        marginLeft = 0;
        $("#carousel .citem").eq(0)
						.css("margin-left", marginLeft)
						.clone(true)
						.insertAfter($("#carousel .citem").eq(1));
        $("#carousel .citem").eq(0).remove();
    }
}