$(document).ready(function () {

$(function(){ $("input:checkbox").uniform(); });

/*as the whole nav button isnt a href force a redirect on the same href 
for the whole button (not just the text link) */
$('#menu_items li a').each( function() {
    $(this).parent().click(function() { 
       link =  $(this).children().attr('href');
       window.location = link;
    });
});

//make the whole div redirect instead of just a links within
 $('#artists_tab div a').each( function () {
     $(this).parent().click(function() { 
       link =  $(this).children().attr('href');
       window.location = link;
 });
});

//make the whole div redirect instead of just a links within
 $('#latest_entries div.canvas_latest').each( function () {
     $(this).click(function() { 
       link = $(this).children().children().children().attr('href');
       window.location = link;
 });
});


//make the whole div redirect instead of just a links within
 $('.results_cont .row').each( function () {
     $(this).click(function() { 
       link = $(this).children('.gallery_left').children().children().children().children().attr('href');
       window.location = link;
 });
});

//make the whole div redirect instead of just a links within
 $('#results_cont .row').each( function () {
     $(this).click(function() { 
       link = $(this).children('.gallery_left').children().children().children().children().attr('href');
       window.location = link;
 });
});

//make the whole div redirect instead of just a links within
 $('#gallery_portfolio_options div#color_wrap div#option2').each( function () {
     $(this).click(function() { 
       link = $(this).find('a').attr('href');
       if (link !== undefined){
           window.location = link;
       }
 });
});

//make the whole div redirect instead of just a links within
 $('#gallery_portfolio_options.profile_toolbar div#color_wrap div').each( function () {
     $(this).click(function() { 
       link = $(this).find('a').attr('href');
       if (link !== undefined){
           window.location = link;
       }
 });
});


//make the whole div redirect instead of just a links within
 $('#secondary_account_nav div').each( function () {
     $(this).click(function() { 
       link = $(this).find('a').attr('href');
       window.location = link;
 });
});


 $("#artists_tab_indiv1").hover(function(){

    $("#artists_tab_indiv2").removeClass("current");
    $("#artists_tab_indiv3").removeClass("current");
    $("img#indiv2_bottombg").removeClass("bottombg_current indiv2_bottombg");
    $("img#indiv3_bottombg").removeClass("bottombg_current indiv3_bottombg");

    $(this).addClass("current");
    $("img#indiv1_bottombg").addClass("bottombg_current indiv1_bottombg");
    
}, function() {
    $(this).removeClass('current');
    $("img#indiv1_bottombg").removeClass("bottombg_current indiv1_bottombg");
});

 $("#artists_tab_indiv2").hover(function(){

    $("#artists_tab_indiv1").removeClass("current");
    $("#artists_tab_indiv3").removeClass("current");
    $("#artists_tab_indiv1 img").removeClass("bottombg_current indiv1_bottombg");
    $("#artists_tab_indiv3 img").removeClass("bottombg_current indiv3_bottombg");
    
    $(this).addClass("current");
    $("#artists_tab_indiv2 img").addClass("bottombg_current indiv2_bottombg");

}, function() {
    $(this).removeClass('current');
    $("#artists_tab_indiv2 img").removeClass("bottombg_current indiv2_bottombg");
});

 $("#artists_tab_indiv3").hover(function(){

    $("#artists_tab_indiv1").removeClass("current");
    $("#artists_tab_indiv2").removeClass("current");
    $("img#indiv1_bottombg").removeClass("bottombg_current indiv1_bottombg");
    $("img#indiv2_bottombg").removeClass("bottombg_current indiv2_bottombg");

    $(this).addClass("current");
    $("img#indiv3_bottombg").addClass("bottombg_current indi3_bottombg");
}, function() {
    $(this).removeClass('current');
    $("#artists_tab_indiv3 img").removeClass("bottombg_current indiv3_bottombg");
});

//Artist bar
 $("#artists_tab_indiv1").click(function(){

    $("#artists_tab_indiv2").removeClass("current");
    $("#artists_tab_indiv3").removeClass("current");
    $("img#indiv2_bottombg").removeClass("bottombg_current indiv2_bottombg");
    $("img#indiv3_bottombg").removeClass("bottombg_current indiv3_bottombg");

    $(this).addClass("current");
    $("img#indiv1_bottombg").addClass("bottombg_current indiv1_bottombg");
    
}),

 $("#artists_tab_indiv2").click(function(){

    $("#artists_tab_indiv1").removeClass("current");
    $("#artists_tab_indiv3").removeClass("current");
    $("#artists_tab_indiv1 img").removeClass("bottombg_current indiv1_bottombg");
    $("#artists_tab_indiv3 img").removeClass("bottombg_current indiv3_bottombg");
    
    $(this).addClass("current");
    $("#artists_tab_indiv2 img").addClass("bottombg_current indiv2_bottombg");

}),

 $("#artists_tab_indiv3").click(function(){

    $("#artists_tab_indiv1").removeClass("current");
    $("#artists_tab_indiv2").removeClass("current");
    $("img#indiv1_bottombg").removeClass("bottombg_current indiv1_bottombg");
    $("img#indiv2_bottombg").removeClass("bottombg_current indiv2_bottombg");

    $(this).addClass("current");
    $("img#indiv3_bottombg").addClass("bottombg_current indi3_bottombg");
});


$('.toolbar-skip-to-top').click(function(event) {
    event.preventDefault();
    $('html').animate({scrollTop:0}, 'ease') 
    $('body').animate({scrollTop:0}, 'ease') 
});

$('.follow').live('click', toggle_follow); 

});

function toggle_follow(event) {

    event.preventDefault();

    id = $(this).attr('id');
    element = $(this);

    if ($(this).hasClass("follow_this_artist")) {
        ajax_url = "/" + id + "/follow/true/";
    } else if ($(this).hasClass("unfollow_this_artist")) {
        ajax_url = "/" + id + "/follow/false/";        
    }

    $.getJSON(ajax_url, function(data) {
        following = data["following"]
        if (following == true) {
                    element.removeClass('follow_this_artist');
                    element.addClass('unfollow_this_artist');
                    element.attr('href', "/"+id +"/follow/false/")
                    element.html("Unfollow");
        } else if (following == false) {
                    element.removeClass('unfollow_this_artist');
                    element.addClass('follow_this_artist');
                    element.attr('href', "/"+id +"/follow/true/")
                    element.html("Follow Artist");
        }
    });
}







