var $ = jQuery.noConflict();

$(function() {

    /******************************************
                    CUFON FONTS
     *****************************************/

    Cufon.replace('h1, h2, h3, h4, h5, h6', {
        fontFamily: 'Junction'
    });

    /******************************************
            Main Menu - Slide Animation
     *****************************************/

    var nav = $('ul#nav li').children('ul').hide().end();

    nav.hover(function() {
        // mouseover
        $(this).find('> ul').stop(true, true).slideDown("fast");

        //If the user clicks the link while hovering hide the submenu
        $(this).click(function(){
            //Hides the submenu
            $(this).find('> ul').stop(true, true).hide();
        });
    },
    function() {
        // mouseout
        $(this).find('> ul').stop(true, true).hide();
    });

    /******************************************
       PRETTY PHOTO / IMAGES / LINKS
     *****************************************/

    //Image Links Fade Animation
    if ($.support.opacity) {
        $("a img, .button, h1 a, h2 a, h3 a, h4 a, h5 a, h6 a, #teaser a, #disclaimer a").hover(function(){
            $(this).stop().fadeTo(500, 0.7);
       
        },function(){
            $(this).stop(false, false).fadeTo(500, 1);
        });
    } else {
        $("a img, .button").hover(function(){
            $(this).stop().fadeTo(500, 0.7);

        },function(){
            $(this).stop(false, false).fadeTo(500, 1);
        });
    }

    //Main Menu Links Fade Animation
    $("ul#nav li ul a").hover(function(){
        $(this).stop().fadeTo(0, 0.1);
        $(this).stop().fadeTo(500, 1);

    },function(){
        $(this).stop(false, false).fadeTo(500, 1);
    });

    //Append necessary elements
    $('.prettyPhoto.image').append("<div class='frame'><img class='zoom_image' src='img/layout/zoom_image.gif' alt='' /></div>");
    $('.prettyPhoto.video').append("<div class='frame'><img class='zoom_video' src='img/layout/zoom_video.gif' alt='' /></div>");

    //Animation on MouseOver, MouseOut
    $(".prettyPhoto").hover(function(){

        //Bug fix
        $(this).find('.frame').show();
        $(this).find('.frame img').show();
        $(this).find('.frame').hide();
        $(this).find('.frame img').hide();

        //Icon Animation and Centering
        var h = $(this).find('img').height() + 2;
        var w = $(this).find('img').width() + 2;

        var x = (w/2) - 32;
        var y = (h/2 )- 32;
        x = x + 'px';
        y = y + 'px';

        $(this).find('.zoom_image').css({
            left: x,
            top: y
        });

        $(this).find('.zoom_video').css({
            left: x,
            top: y
        });

        $(this).find('.frame').css({
            height: h,
            width: w
        });
        
        $(this).find('.frame').stop().fadeTo(600, 0.7);
        $(this).find('.frame img').stop().fadeTo(800, 1);

    },
    function(){
        $(this).find('.frame').stop(false, false).fadeTo(700, 0);
        $(this).find('.frame img').stop(false, false).fadeTo(300, 0);
      
    });
   
    /******************************************
          List Items - Margin Animation
     *****************************************/
    $("ul.style_1 li a, ul.style_2 li a, ul.style_3 li a, ul.style_4 li a, ul.style_5 li a, ul.style_6 li a, \n\
       ul.style_7 li a, ul.style_8 li a,").hover(function() {
        var li = $(this).parent();

        li.stop().animate({
            marginLeft: "8px"
        }, 250, function() {
            li.animate({
                marginLeft: "5px"
            }, 250);
        });

    },function(){
        var li = $(this).parent();
        li.stop().animate({
            marginLeft: "-5px"
        }, 250, function() {
            li.animate({
                marginLeft: "0px"
            }, 250);
        });
    });


    /******************************************
               ScrollTop Animation
     *****************************************/
    $('a[href=#top]').click(function(){

        if ($.browser.webkit) {
            $('body').animate({
                scrollTop:0
            }, 'slow');
            return false;

        } else {

            $('html').animate({
                scrollTop:0
            }, 'slow');
            return false;
        }
    });

    /******************************************
         Items loading animation
     *****************************************/
    if ($.support.opacity) {
        // Menu
        $('body').hide().fadeIn(1200);
    }


    /******************************************
      Portfolio  - Caption Sliding Animation
     *****************************************/
    $('.boxgrid').hover(function(){
        $(".cover", this).stop().animate({
            top:'125px'
        },{
            duration:200
        });

    }, function() {
        $(".cover", this).stop().animate({
            top:'160px'
        },{
            duration:200
        });
    });
    
});
