$(document).ready(function() {

    var switcher = null;
    switchWorks();

    /*$("#subscriber_country").dropdownReplacement({
        selectCssWidth: 182
    });*/

    $("#subscriber_country").msDropDown({
        onInit: function() {
            $('#subscriber_country_msdd').css('width', '200px');
            $('#subscriber_country_child').css('width', '200px');
        }
    });


    $('.recent-works-tab').click(function() {
        clearTimeout(switcher);
        viewWork(this);
    });

    $('.view-details').click(function() {
        clearTimeout(switcher);
        var id = $('.recent-works-tabs-selected').attr('href');
        $(id).children('.zoombox:first').click();
        return false;
    });

    $('.signup').click(function(){
        $('#subscriber_form').submit();
    });

    if ($('#hidden').length > 0 ) {
        $.openPopupLayer({
            name: "popup",
            width: 550,
            target: "hidden"
        });
    }
    
});

function switchWorks() {
    switcher = setTimeout('switchWorks()', 7000);
    if ($('.recent-works-tabs-selected').next('a.recent-works-tab').length == 0) {
        viewWork($('.recent-works-tab:first'));
    } else {
        viewWork($('.recent-works-tabs-selected').next('a.recent-works-tab'));
    }
    
}

function viewWork(recentWork) {
    $('.recent-works-tabs-selected').removeClass('recent-works-tabs-selected');
    $(recentWork).addClass('recent-works-tabs-selected');
    var id = $(recentWork).attr('href');
    $('.recent-work-selected').fadeOut(400, function() {
        $(this).css('background-image', $(id).css('background-image'));
        $(this).fadeIn(400);
    });
}



