$(function(){
   
    $('header h1 a span').css({opacity: 0, display: 'block'});

    $('header h1 a').hover(function() {
        $('span', this).stop().animate({opacity: '1'}, 200);
    },function() {
        $('span', this).stop().animate({opacity: '0'}, 200);
    });
    
    
    $('#hireNow a').live('mouseenter', function() {
        $('em', this).stop().animate({opacity: '0'}, 300);
        $('span', this).stop().animate({opacity: '1'}, 300);
    }).live('mouseleave', function() {
        $('em', this).stop().animate({opacity: '1'}, 300);
        $('span', this).stop().animate({opacity: '0'}, 300);
    });
    
});

$(function() {
    $('.tip').each(function() {
        var width = $(this).outerWidth();
        var w = -(width/2);
        $(this).css({marginLeft: w});
    });
    $('#stayConnected li a').each(function() {
        var $this = $(this).parent().find('.tip');
        $(this).hover(function() {
            $this.css({display: 'block',opacity: 0.7});
        },function() {
            $this.css({opacity: 0}, function() {
                $(this).css({display: 'none'});
            });
        });
    });
});

//ajax shtuff

$(document).ready(function() {

    // Ajax Cache!
    $.ajaxSetup ({  
        cache: false  
    });
        
    var $loadW = '<div id="whiteLoader" />';
    var $loadurl = $('.current').attr('href');
     
    // Initial Page Load
    $('#con').prepend($loadW);
    $('#main').fadeOut('slow', function() {
        $('#main').load($loadurl + ' .page', function() {
            $('#whiteLoader').fadeOut('slow', function() {
                $('#main').fadeIn('slow');
                $(this).remove();
            });
        });
    });
    
    $('#hireNow a').live('click',function(e) {
        
        e.preventDefault();
        
        $('*').removeClass('current');
        $('.contactLink').addClass('current');
        
        var $loadW = '<div id="whiteLoader" />';
        var $loadurl = $(this).attr('href');
        
        // Load the Page
        $('#main').fadeOut('slow', function() {
            $('#con').prepend($loadW);
            $('#main').load($loadurl + ' .page', function() {
                $('#whiteLoader').fadeOut('slow', function() {
                    $('#main').fadeIn('slow');
                    $(this).remove();
                });
            });
        });
        
    });
    
    $('header h1 a').live('click',function(e) {
        
        e.preventDefault();
        
        $('*').removeClass('current');
        $('.aboutLink').addClass('current');
        
        var $loadW = '<div id="whiteLoader" />';
        var $loadurl = $(this).attr('href');
        
        // Load the Page
        $('#main').fadeOut('slow', function() {
            $('#con').prepend($loadW);
            $('#main').load($loadurl + ' .page', function() {
                $('#whiteLoader').fadeOut('slow', function() {
                    $('#main').fadeIn('slow');
                    $(this).remove();
                });
            });
        });
        
    });
    
    $('nav ul li a').each(function() {
        $(this).click(function(e) {
        
            var $loadW = '<div id="whiteLoader" />';
            var $loadurl = $(this).attr('href');
        
            // Prevent default hotlink
            e.preventDefault();
        
            // Add the current state
            $('*').removeClass('current');
            $(this).addClass('current');
            
            
            // Load the Page
            $('#main').fadeOut('slow', function() {
                $('#con').prepend($loadW);
                $('#main').load($loadurl + ' .page', function() {
                    $('#whiteLoader').fadeOut('slow', function() {
                        $('#main').fadeIn('slow');
                        $(this).remove();
                    });
                });
            });
            
        });
    });
    
    $('.item').live('mouseenter', function() {
        $('.itemDetails', this).stop().animate({opacity: 1}, 'fast');
    }).live('mouseleave', function() {
        $('.itemDetails', this).stop().animate({opacity: 0}, 'fast');
    });
    
    
    ////////////////
    //--LIGHTBOX--//
    ////////////////
    
    $('.enlarge').live('click', function(i) {
    
        i.preventDefault();
        
        $title = $(this).parent().find('h2');
        $desc = $(this).attr('alt');
        $role = $(this).parent().find('.enlarge').attr('rel');
        
        if($(this).parent().find('h2').attr('rel')) {
            var $online = $(this).parent().find('h2').attr('rel');
            var $status = '<a href="' + $online + '" target="_blank">Online</a>';
        } else {
            var $status = 'offline';
        }
        
        var $nofindrel = (!($(this).parent().find('h2').attr('rel')));
        
        if($(this).parent().find('h2').attr('alt') && !($(this).parent().find('h2').attr('rel'))) {
            var $status = $(this).parent().find('h2').attr('alt');
        }

                        
        var $href = $(this).attr('href');
        var $loadW = '<div id="whiteLoader" />';
        
        if($('#overlay').length < 1) {
            $('body').append('<div id="overlay" />');
        }
        
        $('#overlay').stop().animate({opacity: 1}, 400, function() {
            $('#overlay').html($loadW);
            $('body').append('<div id="lightBoxOuter" />');
            $('#lightBoxOuter').load($href, function() {
                $(this).queue(function() {
                    $('#pTitle').html($title.text());
                    $('#pDesc').html($desc);
                    $('#pRole').html($role);
                    
                    var $outerH = $(this).outerHeight();
                    var $h = -($outerH/2);
                    
                    if($status == 'offline' || $nofindrel) {
                        $('#pStatus').text($status);
                    } else {
                        $('#pStatus').html($status);
                    }
                                        
                    $(this).css({marginTop: $h});
                    
                    $(this).fadeIn('slow', function() {
                        $('#whiteLoader').remove();
                    });
                    $(this).dequeue();
                });   
            });
        });
        

        $('#close').live('click', function() {
            $('#lightBoxOuter').remove();
            $('#overlay').stop().animate({opacity: 0}, 400, function() {
                $(this).remove();
            });
        });
    });
    
    
});



















