$(document).ready(function() {

    // All pages
    
    // fit to screen functionality
    $('#fit-to-screen').click(function () {
        window.moveTo(0,0);
        window.resizeTo(screen.availWidth,screen.availHeight); 
    });

    // remove no-js class after pageload
    $('body').removeClass('no-js');
 
/*  
    $('.top-category').hover(
        function () {
            $('.subnav').hide();
            $('.subnav', this).show();
        },
        function () {
            // maybe set timer to hide all subnavs?
            $('.subnav', this).hide();
        }
    );
*/

	$(".top-category").hover(function() {
		$(".subnav", this).addClass("pretty-hover");
	}, function() {
		$(".subnav", this).removeClass("pretty-hover");
	});
	
	
	
	
	
	
    // Entry Listings
    
    // styling image container width in listings
    if ($('.entry-listing').length) {
        $('.entry img').load(function() { $(this).parent().css('width', $(this).attr('width')); }); 
        $('.entry').each(function() {
            $(this).css({'width' : $('img', this).attr('width')});
        });
  
/* Animating the container div make sIFR texts flicker
     
        // animate hide & show of footer
        $("#footer").animate({ 
            height: "140px"
        }, 3000 );
        $("#footer").animate({ 
            height: "25px"
        }, 400 );

        var hide = false; 
        $("#footer").hover(
            function(){ 
                if (hide) clearTimeout(hide); 
                $("#footer").animate({ 
                    height: "140px"
                }, 400 );
            }, function() { 
                hide = setTimeout(function() { 
                    $("#footer").animate({ 
                        height: "25px"
                    }, 400 );
                }, 250); 
            }
        );
*/
        
    };


    // Entry Detail

    // Arrow key navigation
     $(document).keydown(function (e) {
        var link;
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if(key == 39)
            link = $("#arr-nav-right-link").attr("href");
        if(key == 37)
            link = $("#arr-nav-left-link").attr("href");
        if(link)
            window.location = link;
     });
    

    // tag & details modals
    var tc = $('#tags-container');
    var dc = $('#details-container');
	var tipc = $('#tips-container');

    
    $('#tags-container, #details-container, #tips-container').click(function() {
        $(this).fadeOut();
    });
    
    $('#tags').click(function () {
        if ( $(tc).is(':visible') ) {
            $(tc).fadeOut();
        } else {
            $(dc).hide();
            $(tc).fadeIn("fast");
        }
        return false;
    });
    
    $('#details').click(function () {
        if ( $(dc).is(':visible') ) {
            $(dc).fadeOut();
        } else{ 
            $(tc).hide();
            $(dc).fadeIn("fast");
        }
        return false;
    });


    $('#tips').click(function () {
        if ( $(tipc).is(':visible') ) {
            $(tipc).fadeOut();
        } else{ 
            $(tipc).hide();
            $(tipc).fadeIn("fast");
        }
        return false;
    });


    $('.close').click(function () {
        $(this).parent().hide();
    });


    // Main Index
    if ($('.main-index').length) {
        // behavior for main index only
    }

});



 
