/*
*	Movie Genie
*	JS functionality for Movie Genie site
*	
*	Requires jQuery library (http://www.jquery.com)
*	
*	Taylan Pince (taylanpince at gmail dot com) - May 13, 2009
*/

$.extend($.namespace("core.MovieGenie"), {
    
    active_thumb : null,
    
    init_toolbar : function() {
        $("#Toolbar > li").hover(function() {
            $(this).stop().animate({
                "top": "6px"
            })
        }, function() {
            $(this).stop().animate({
                "top": "0px"
            })
        });
    },
    
    init_dock : function() {
        /*$("#Header > a").hover(function() {
            $("#Dock > ul").stop().animate({
                "height": "100px"
            })
        }, function() {
            $(this).stop().animate({
                "height": "9px"
            })
        });*/
        $("#DockToggle").click(function() {
            $("#Dock > ul").slideToggle();
            $("#Dock").animate({
                "height": ($("#Dock").height() > 9) ? 9 : 100
            });
        });
    },
    
    init_apps : function() {
        $("#Applications > li").hover(function() {
            $("#Applications > li").not(this).stop().animate({
                "opacity": 0.5
            })
        }, function() {
            $("#Applications > li").not(this).stop().animate({
                "opacity": 1.0
            })
        });
    },
    
    init_thumbs : function() {
        $("#Thumbnails > li").hover(function() {
            if (this != core.MovieGenie.active_thumb) {
                $(this).stop().fadeTo("normal", 1);
            }
        }, function() {
            if (this != core.MovieGenie.active_thumb) {
                $(this).stop().fadeTo("normal", 0.7);
                $(core.MovieGenie.active_thumb).stop().fadeTo("normal", 1.0);
            }
        }).find("a").click(function() {
            if ($(this).parent().get(0) != core.MovieGenie.active_thumb) {
                $(core.MovieGenie.active_thumb).stop().fadeTo("slow", 0.7);
                core.MovieGenie.active_thumb = $(this).parent().get(0);
                $("#iPhone").find("ul").stop().animate({
                    "left": "-" + $("#Screenshots").find("[src*=" + $(this).attr("href") + "]").parent().position().left + "px"
                });
            }
            
            return false;
        }).end().not(":first-child").stop().fadeTo("slow", 0.7);
        
        this.active_thumb = $("#Thumbnails > li:first-child").get(0);
    },
    
    init : function() {
        this.init_toolbar();
        this.init_dock();
        this.init_apps();
        //this.init_thumbs();
    }
    
});

$(function() {
    core.MovieGenie.init();
});