var global_doc_id	// Holder for doc id used when creating links to full docs in colorbox

$(document).ready(function() {
    
    // Init Home page focus tabs
    if ($('#focus').length) {
        var focus = $('#focus'); 
        focus.tabs({ fx: { opacity: 'toggle', duration: 600} });
        focus.tabs('rotate', 10000, true);
    }
    
    // Inner pages tabs
    if ($('#tabs').length) {
        $('#tabs').tabs();
    }
	
    // Toggle Sign in box
    $('#sign-in-toggle').bind('click', function () {
        $('#sign-in-box').toggleClass("display");
        return false;
    });
    
    // Toggle document description
    $('#content-wrapper p.toggle-description a').bind('click', function () {
        var link = $(this);
        link.toggleClass('collapse');
        if (link.text() == 'Expand description') {
            link.text('Collapse description');
        } else {
            link.text('Expand description');
        }
        link.parents('div.inner').find('div.description').slideToggle(600);
        return false;
    });
    // Toggle document description
    $('#content-wrapper p.toggle-adescription a').bind('click', function () {
        var link = $(this);
        link.toggleClass('collapse');
        if (link.text() == 'Expand description ...') {
            link.text('Collapse description ...');
        } else {
            link.text('Expand description ...');
        }
        link.parents('li').find('div.description').slideToggle(400);
        return false;
    });

    $('#content-wrapper a.toggle-sidebar-form-comments').bind('click', function () {
        var link = $(this);
        link.toggleClass('collapse');
        if (link.text() == 'write comments') {
            link.text('cancel');
        } else {
            link.text('write comments');
        }
        link.parents('div').find('div#sidebar-form-comments').slideToggle(400);
        return false;
    });

    $('#content-wrapper a.toggle-form-comments').bind('click', function () {
        var link = $(this);
        link.toggleClass('collapse');
        if (link.text() == 'write comments') {
            link.text('cancel');
        } else {
            link.text('write comments');
        }
        link.parents('div').find('div#form-comments').slideToggle(400);
        return false;
    });
    
    // Init Colorbox Modals
    $('a.colorbox').click(function() {
	
    		var doc_id = $(this).attr('id');
    		global_doc_id = doc_id;
		
    		$.fn.colorbox({ href: '/_scripts/doc_preview.php?doc_id=' + doc_id, opacity: .3, innerWidth: '840px' }, function() {
    			
    		});
	
    });
    
    $('#member_search #search_term').focus(function() {
    	if ($(this).val() == 'Search For Members') $(this).val('');
    });
    
    // Init Directory listing links
    $('.person').click(function() {
    	window.location="/directory/member_profile.php?user_id="+$(this).attr('id').substring(7);
    });
    
    $('.person').hover(
    	function() { $(this).prev().css("border-bottom", "1px solid #ffffff"); },
    	function() { $(this).prev().css("border-bottom", "1px solid #e4e7ea"); }
    );
    
    // Init vCards
    $('a.vcard').click(function() {
    	var user_id = $('.personal_info').attr('id').substring(5);
    	$.get('/_scripts/create_vcard.php?user_id='+user_id, function(data) {
    		window.location="/download.php?file_name="+data;
    	});
    });
    
    // Init Fixed Nav
    $(window).scroll(function() {
    	if ($(window).scrollTop() >= 1) {
    		$('.border').css("borderBottom", "1px solid #ddd");
    		$('#header-wrap').css({ marginBottom: "0px", paddingBottom: "38px" });
    		$('#header-wrap').css("background", "transparent url(/_ui/images/shadow.png) no-repeat center bottom");
    	} else {
    		$('.border').css("borderBottom", "none");
    		$('#header-wrap').css({ paddingBottom: "0px", marginBottom: "38px" });
    		$('#header-wrap').css("background", "none");
    	}
    });
    
});


// Move Colorbox 'close' button to top left corner
$(document).bind('cbox_complete', function() {
	$('#colorbox').prepend($('#cboxClose'));
	$('#colorbox').append('<a class="full" href="/content?id='+global_doc_id+'&nobanner=1&nomenu=1&backbutton=1">Full Article</a>');

});