var welcomeVisible = true;
var welcomeTextVisible = 0;
var welcomeTextCount = 0;

function switchImage(obj) {
    if (welcomeVisible) {
        welcomeVisible = false;
        $("#welcome").fadeOut(500);
    }
    $('#bg_all2').css({'background-image' : "url('" + $(obj).attr('href')+"')"});
    $('#bg_all').fadeOut(800, function () {
        $('#bg_all').css({'background-image' : "url('" + $(obj).attr('href')+"')"});
            $('#bg_all').show(0, function () {
                $('#bg_all2').hide(0);
                $('#bg_all2').css({'background-image' : 'none'});
            });
        }
    );
    $('#bg_all2').fadeIn(800);
}

function switchWelcomeText() {
    $('#welcome_text_' + welcomeTextVisible).fadeOut(400);
    welcomeTextVisible++;
    welcomeTextVisible %= welcomeTextCount;
    $('#welcome_text_' + welcomeTextVisible).fadeIn(400);


}

function xx2(obj) {
    $('#bg_all').fadeOut(400, function() {
        $('#bg_all').css({'background-image' : "url('" + $(obj).attr('href')+"')"});
        $('#bg_all').fadeIn(800);
    });
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(document).ready(function() {
    $("#thumbStrip").hide(0);
    $("#welcome").hide(0)
    $(".welcome_text").hide(0)
    $("#welcome_text_0").show(0)
    elms = $("#thumbStrip li a");
    jQuery.each(elms, function() {$(this).click(function() {switchImage(this); return(false);});});
    $("#thumbStrip li a img").hover(
        function () {
            //$(this).css({'border-left-color' : 'red', 'border-right-color' : 'red'});
            $(this).fadeTo(0, .7);
        }
    ,
        function () {
            //$(this).css({'border-left-color' : 'transparent', 'border-right-color' : 'transparent'});
            $(this).fadeTo(0, 1);
        }
    );

    $("#thumbStrip").hover(
        function () {
            //$(this).css({'border-left-color' : 'red', 'border-right-color' : 'red'});
            $(this).fadeTo(0, 1);
        }
    ,
        function () {
            //$(this).css({'border-left-color' : 'transparent', 'border-right-color' : 'transparent'});
            $(this).fadeTo(0, .8);
        }
    );
    $("#welcome .close_box a").click(
        function() {
            $("#welcome").fadeOut(500);
            return false;
        }
    );
});

$(window).load(function() {
    elm = $('#thumbStrip')
    //elm.fadeTo(400, .4, function () {elm.fadeTo(400, 1, function() {elm.fadeTo(1500, .4)});});
    elm.slideDown(400, function () {
        elm.fadeTo(1000, .8);
        $("#welcome").fadeIn(1000);
    });
    elms = $("#thumbStrip li a");
    welcomeTextCount = $('div.welcome_text').length;
    jQuery.each(elms, function() {jQuery("<img>").attr("src", $(this).attr('href'));});
    $(document).everyTime(5000, function() {switchWelcomeText();});
});
