var featuredArtistSelected=0;
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
$(window).load(function(){
   init();
});
function init(){
    $(".journalContent").jCarouselLite({
        btnNext: ".journalButtonUp",
        btnPrev: ".journalButtonDown",
        mouseWheel: 'true',
        vertical: 'true',
        circular: 'false',
        visible: 2,
        speed:700
    });
    $(".featuredVideoContent").jCarouselLite({
        btnNext: ".featuredVideoButtonUp",
        btnPrev: ".featuredVideoButtonDown",
        mouseWheel: 'true',
        vertical: 'true',
        circular: 'false',
        visible: 2,
        speed:700
    });
   featuredArtistSelect(1);
   $(".button").each(function(){
        $(this).mouseover(function(){
            $(this).removeClass('normal');
            $(this).addClass('over');
        }).mouseout(function(){
            $(this).removeClass('over');
            $(this).addClass('normal');
        });
    });
    $.preloadImages(
        baseUrl + '/public/images/design/index/featuredButtonLeftOver.jpg',
        baseUrl + '/public/images/design/index/featuredButtonRightOver.jpg',
        baseUrl + '/public/images/design/index/journalButtonUpOver.jpg', 
        baseUrl + '/public/images/design/index/journalButtonDownOver.jpg'
        );

}

function moveFeaturedArtist(count){
    var moveTo = featuredArtistSelected + count;
    if(moveTo<1){
        moveTo = 4;
    }
    if(moveTo>4){
        moveTo = 1;
    }
    featuredArtistSelect(moveTo);
}

function featuredArtistSelect(id){
    if(id != featuredArtistSelected){
        if(featuredArtistSelected>0){
            $("#featured_" + featuredArtistSelected).removeClass("featuredArtistBoxSelected");
            $("#featured_" + featuredArtistSelected).addClass('featuredArtistBox');
            $("#mainContent_" +featuredArtistSelected).fadeOut(500, function(){
               $("#mainContent_" + id).fadeIn(500);
            });
        }
        $("#featured_" + id).removeClass('featuredArtistBox');
        $("#featured_" + id).addClass("featuredArtistBoxSelected");
        featuredArtistSelected = id;
    }
}

function joinMailing(){
    email = $("#mailingEmail").val();
    if(email.length<5){
        alert('Please enter your email address');
        return false;
    }
    var postUrl = baseUrl + '/misc/addtomailinglist';
    var postData = 'email=' + email;
    postData += '&country=' + $("#mailingCountry").val();
    postData += '&zip=' + $("#mailingZip").val();
    $.ajax({
       type: "POST",
       url: postUrl,
       data: postData,
       success: function(msg){
           if(msg == 'ok'){
               alert("Thank you for joining our mailing list");
           }
           else{
               alert("The data you entered is invalid, please try again");
           }
       }
    });
}