$(document).ready(function() {
    // Expand Panel
    $("#open").click(function(){
        $("div#panel").slideDown(300);
    });
    // Collapse Panel
    $("#close").click(function(){
        $("div#panel").slideUp(300);
    });
    // Switch buttons from "Log In | Register" to "Close Panel" on click
    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });
        
    $('#password-clear').show();
    $('#password-password').hide();

    $('#password-clear').focus(function() {
        $('#password-clear').hide();
        $('#password-password').show();
        $('#password-password').focus();
    });
    $('#password-password').blur(function() {
        if($('#password-password').val() == '') {
            $('#password-clear').show();
            $('#password-password').hide();
        }
    });

    $('.default-value').each(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if(this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if(this.value == '') {
                this.value = default_value;
            }
        });
    });
	
    $('#fbBackButton').click(function(event) {
        event.preventDefault();
    });
    $('#fbForwardButton').click(function(event) {
        event.preventDefault();
    });

    //Fancybox overlay pages.
    $(".fb_sewn_signatures, .fb_cover_options, .fb_archival_papers, .fb_book_size, .fb_sewn_glued_choice, .fb_end_papers, .fb_ship_photos_and_slides, .fb_layout_options, .fb_cover_type, .fb_accessories, .fb_foil_stamping").fancybox({
        'padding'                   : 10,
        'overlayShow'               : true,
        'overlayOpacity'            : '0.8',
        'overlayColor'              : '#666',
        'scrolling'                 : 'yes',
        'transitionIn'              : 'elastic',
        'autoScale'                 : 'false',
        'transitionOut'             : 'none',
        'hideOnContentClick'        : true,
		'onStart'                   : function() {
			// Hide arrow hack
			$('#fancybox-left').hide();
			$('#fancybox-right').hide();
		}
    });

//    $(".tooltip").tooltip({
//        delay: 0.5,
//        showURL: false,
//        extraClass: "pretty",
//        opacity: 1,
//        left: -120,
//        bodyHandler: function() {
//            return $(".tooltip_content").html();
//        }
//    });

    $(".tooltip").fancybox({
        'padding'                   : 10,
        'overlayShow'               : true,
        'overlayOpacity'            : '0.8',
        'overlayColor'              : '#666',
        'scrolling'                 : 'no',
        'transitionIn'              : 'elastic',
        'autoScale'                 : 'false',
        'transitionOut'             : 'none',
        'hideOnContentClick'        : true,
		'showNavArrows'             : false,
		onStart			            : function() {
			// Hide arrow hack
			$('#fancybox-left').hide();
			$('#fancybox-right').hide();
		}
    });


});

$(window).load(function() {
    $('ul.errors > li').each(function(index, domEle) {
        var errorIdName = $(domEle);
        var idName = $(domEle).attr('id').replace('_error', '');
        var error = $("#" + idName);
        var position = error.offset();
		console.log(error);
		//console.log(idName + " - " + position.top)
        $(errorIdName).css('position', 'absolute').css('top', position.top + 5);
    });
    $('ul.errors').show();
});


