jQuery(document).ready(function(){
    /* Fix target blank problems */
    jQuery('a[rel=external]').click(function(){
        this.target = "_blank";
    });
    
    /* Defuscate email links */
    jQuery(".fuscated").defuscate({link: false});
    
    /* Initialize Uniform */
    if(!jQuery.browser.opera) {
        jQuery("select, :checkbox, :radio, :file").uniform();
    }
    
    /* Si hi to the people on the contact page */
    jQuery('#name').bind('blur', function() {
        if(jQuery('#name').val().length > 0) {
            jQuery('.hi-there').css('visibility', 'visible');
        }
    });

    /* Initialize the konami code */
    konami = new Konami();
    konami.code = function() {
        $('body').addClass('konamicode');
    }
    konami.load();
    
    /* Initialize the gallery on the project page */
    try {
		if($('#player').length) {
			Gallery.playing = false;
		}
        Gallery.init();
    } catch(e) {}
    
    if ($.browser.safari) {
        $('#footer').addClass('webkit');
     }
    
});

var Gallery = {
        playing: true,
        init: function() {
            $('#slideshow').cycle({ 
                fx:     'fade',
                timeout: 4000,
                speed:  1000,
                pager:  '#slideshow_nav',
                activePagerClass: 'active',
                pagerAnchorBuilder: function(idx, slide) {
                    return '<li><a href="#">' + (idx + 1)+ '</a></li>';
                }
            });

			if(Gallery.playing == false) {
				$('#slideshow').cycle('pause');
				$('#slideshow_playpause').addClass('playslideshow').removeClass('pauseslideshow');
                $('#slideshow_playpause a').html('Play slideshow');
			}
            
            $('#slideshow_playpause').addClass('pauseslideshow').removeClass('playslideshow');
            $('#slideshow_playpause a').html('Stop slideshow');
            
            $('#slideshow_playpause').click(function() {
                if(Gallery.playing == true) {
                    $('#slideshow').cycle('pause');
                    Gallery.playing = false;
                    $('#slideshow_playpause').addClass('playslideshow').removeClass('pauseslideshow');
                    $('#slideshow_playpause a').html('Play slideshow');
                }
                else {
                    $('#slideshow').cycle('resume');
                    $('#slideshow_playpause').addClass('pauseslideshow').removeClass('playslideshow');
                    $('#slideshow_playpause a').html('Stop slideshow');
                    Gallery.playing = true;
                }
                
                return false;
            });
        }
    };
