﻿// JScript File

$(document).ready(function() {
    swfobject.embedSWF(skinPath + "gfx/header.swf", "flash-header", "950", "95", "8.0.0",{},{},{menu: "false", wmode:"transparent"});

    $('a.lightbox').lightbox({displayTitle: false, fileLoadingImage: skinPath + 'gfx/loading.gif', overlayOpacity: 0.5});
    
    $('ul.thumbnails li:first, ul.portfolio-items li:first').addClass('current');
    
    $('ul.thumbnails a').click(function(e) {
        e.preventDefault();
    
        var index = $('ul.thumbnails li').index($(this).parent());

        //mark as current
        $('ul.thumbnails li')
            .removeClass('current')
            .eq(index)
                .addClass('current');
    
        //open full view
        $('ul.portfolio-items li')
            .removeClass('current')
            .eq(index)
                .addClass('current');
    });
    
    $('body').append('<div class="overlay"></div><div class="poster-popup poster-details"><a class="close"></a><div class="top-left"><div class="top-right"><div class="top"></div></div></div><div class="content"></div><div class="bottom-left"><div class="bottom-right"><div class="bottom"></div></div></div></div>');
    
    $('.overlay, .poster-popup .close').click(function() {
        $('.overlay').hide();
        $('.poster-popup').hide();
    });
    
    $('ul.thumbnails').css({ width: $('ul.thumbnails').find('li').length * 34 + 'px' });
    
    //$('.border-continued').css({ height: ($('.content-pane').height() - 100) + 'px' });
    
    $('ul.posters a.poster').click(function(e) {
        e.preventDefault();
        
        var arrayPageSize = $.fn.lightbox.getPageSize();
		var arrayPageScroll = $.fn.lightbox.getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
        $('.overlay').css({
            opacity: '0',
            height: arrayPageSize[1]+'px'
        }).show().animate({opacity: '0.6'});
        
        $('.poster-popup').css({ top: Math.max(arrayPageScroll[1], 160) + 'px' });

        $('.poster-popup .content').load('/desktopmodules/studioyeshportfolio/ViewStudioYeshPortfolioPosters.aspx?' + $(this).attr('rel'), function() {
            $('.poster-popup').fadeIn();
            $('.poster-popup').find('img').load(function() {
                //$('.poster-popup').fadeIn();
                var newPopupWidth = $('.poster-popup img').width();
                if ($('.poster-popup img').hasClass('type-6'))
                    newPopupWidth += 6;
                $('.poster-details').css({ width: newPopupWidth+'px' });
                $('.poster-popup').css({ width: (newPopupWidth + 40)+'px' });
            });
        });
        
        /*$('.poster-popup').load($(this).attr('href'), function() {
            if ($('.poster-popup .poster-details').length>0) {
                $('.poster-popup').html('');
            }
            alert($('.poster-popup .poster-details').length);
           $('.poster-popup').html('');          //$('.poster-popup').find('poster-details').html()
        });*/
        /*
        $.get($(this).attr('href'), function(data){
            alert("Data Loaded: " + $(data).find('poster-details').html());
        });*/
    });

    /* top navigation */
    $('.top-navigation li.level-0')
        .each(function() {
            var maxWidth = $(this).width();
            $(this).find('li.level-1').each(function() {
                if ($(this).width() > maxWidth) {
                    //alert('max was' + maxWidth);
                    maxWidth = $(this).width();
                    //alert('new max is' + maxWidth);
                }
            });
            $(this).find('ul.level-1, li.level-1').css({width: maxWidth+'px'});
            $(this).find('span.level-1').css({width: (maxWidth - 20)+'px'});
            $(this).find('ul.level-1').hide().css({visibility: 'visible'});
        })
        .mouseover(function() {
            //$('ul.level-1.hide-this').hide();
            $(this).find('ul.level-1, .trans-bg')
                .removeClass('hide-this').slideDown(140); //fadeIn(100);
        })
        .mouseout(function() {
            var o = $(this);
            o.find('ul.level-1, .trans-bg').addClass('hide-this');
            setTimeout(function() {
                o.find('ul.level-1.hide-this, .trans-bg.hide-this').slideUp(140); //fadeOut(70);
            }, 100);
        });
    $('.top-navigation ul.level-1').each(function() {
        $(this).parent().prepend('<div class="trans-bg"></div>');
        $transBg = $(this).parent().find('.trans-bg');
        $transBg.css({ width: $(this).width()+'px', height: $(this).height()+'px', opacity: '0.7' });
    });

});
