﻿// HANDLER TABS
$(document).ready(function() {
    var indexTab = 0;
    $('.ms_tab_single').click(function() {
        // rendo il vecchio tab bianco
        $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').removeClass('ms_tab_top_selected');
        $('.ms_tab_single').eq(indexTab).find('.ms_tab').removeClass('ms_tab_selected');
        $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().removeClass('ms_tab_label_selected');

        $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#FFFFFF');
        $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#FFFFFF');

        if (indexTab != 0) {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_img').css("background-position", "center top");
        }

        // nascondo il vecchio content
        $('.ms_content').eq(indexTab).css("height", "0");
        $('.ms_content').eq(indexTab).css("overflow", "hidden");

        indexTab = $(this).index();

        // coloro il nuovo tab
        $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').addClass('ms_tab_top_selected');
        $('.ms_tab_single').eq(indexTab).find('.ms_tab').addClass('ms_tab_selected');
        $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().addClass('ms_tab_label_selected');

        // FACEBOOK
        if ($(this).attr('id') == "facebook") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#6185b5');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#6185b5');

        // TWITTER
        } else if ($(this).attr('id') == "twitter") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#79d1ee');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#79d1ee');

        // YOUTUBE
        } else if ($(this).attr('id') == "youtube") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#e85354');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#e85354');

        // RSS
        } else if ($(this).attr('id') == "rss") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#ff9d5c');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#ff9d5c');

        // TRIPADVISOR
        } else if ($(this).attr('id') == "tripadvisor") {
        $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#89b676');
        $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#89b676');

        // FLICKR
        } else if ($(this).attr('id') == "flickr") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#5b91ca');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#5b91ca');

        // FOURSQUARE
        } else if ($(this).attr('id') == "foursquare") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#92d7e1');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#92d7e1');

        // LINKEDIN
        } else if ($(this).attr('id') == "linkedin") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#2591c7');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#2591c7');

        // GOOGLEPLUS
        } else if ($(this).attr('id') == "googleplus") {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#2fb350');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#2fb350');    
            
        // DEFAULT
        } else {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_top').css('background-color', '#F5F5F5');
            $('.ms_tab_single').eq(indexTab).find('.ms_tab').children().css('background-color', '#F5F5F5');
        }

        if (indexTab != 0) {
            $('.ms_tab_single').eq(indexTab).find('.ms_tab_img').css("background-position", "center -26px");
        }

        // mostro nuovo content
        $('.ms_content').eq(indexTab).css("height", "auto");
        if (indexTab == 0)
            $('.ms_content').eq(indexTab).css("overflow", "visible");        
    });
});
