$(document).ready(function() {
    // Open Popup window
    $('a.popup').click(function() {
        var obj = $(this);
        var win = $('#popup');
        if (obj.attr('href').indexOf('#') == 0) {
            win.show();
            var o = obj.offset();
            win.css("top", (o.top + 10) + 'px');
            win.css("left", (o.left - 400) + 'px');
        } else {
            win.html('');
            win.load(obj.attr('href'), function() {
                win.show();
                win.css("top", parseInt((screen.availHeight/2)-(win.height()/2)));
                win.css("left", parseInt((screen.availWidth/2)-(win.width()/2)));
            });
        }
        
        //Fade in Background
        if (!document.getElementById('fade')) {
            $('body').append('<div id="fade"></div>');
        }
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
        
        return false;
    });

    // Close Popups and Fade Layer
    $('a.popup-close, #fade').live('click', function() {
        $('#popup, #fade').fadeOut(function() {
            $('a.popup-close, #fade').remove();
        });
        return false;
    });
    
    // Portfolio tabs
    $('#portfolio-menu a').click(function() {
    	var li = $(this).parent();
    	li.parent().find('li').removeClass('c');
    	li.addClass('c');
    	return false;
    });
    
    // Pager hover
    $('#pager a.prev, #pager a.next').mouseover(function() {
        $(this).find('img').attr('src', $(this).find('img').attr('src').replace('.png', '-hover.png'));
        $(this).find('img').attr('src', $(this).find('img').attr('src').replace('-bg.jpg', '-hover.jpg'));
    });
    $('#pager a.prev, #pager a.next').mouseout(function() {
        $(this).find('img').attr('src', $(this).find('img').attr('src').replace('-hover.png', '.png'));
        $(this).find('img').attr('src', $(this).find('img').attr('src').replace('-hover.jpg', '-bg.jpg'));
    });
    
    // Remove last work line
    $('div.work:last').css('border-bottom', '0');
    
    $('#other-works img:last, a.work-small:odd').css('margin-right', '0');
    
    
    $("a.zoom-it").fancybox({
		'titleShow'		: true
	});
    hoverButtons();
    
    $('form.feedback-form').submit(function() {
        $(this).append('<input type="hidden" name="f" value="cnfqkgbrc" />');
    });
});

function hoverButtons() {
	$('.btn-hover').mouseover(function() {
    	$(this).attr('src', $(this).attr('src').replace('.png', '-h.png'));
    });
    $('.btn-hover').mouseout(function() {
    	$(this).attr('src', $(this).attr('src').replace('-h.png', '.png'));
    });
}
