var photoHeight;
var videoHeight;

$(document).ready(function() {
    
    $('.inspirationGallery').css({float: 'left'});
    $('.articleRwVideoGalleryWrapper').css({opacity: 0});
    
    setTimeout(getHeights, 500);
    
    $('a.articleImages').click(function(e) {
        e.preventDefault();
        if(!$(this).parent().hasClass('selected')) {
            $('.articleRwPhotoGalleryWrapper').stop(true, true);
            $('.articleRwVideoGalleryWrapper').stop(true, true);
            $('.inspirationToggleBox ul li').removeClass('selected');
            $(this).parent().addClass('selected');
            galleryShowImages();
        }
    });
    $('a.articleVideos').click(function(e) {
        e.preventDefault();
        if(!$(this).parent().hasClass('selected')) {
            $('.articleRwPhotoGalleryWrapper').stop(true, true);
            $('.articleRwVideoGalleryWrapper').stop(true, true);
            $('.inspirationToggleBox ul li').removeClass('selected');
            $(this).parent().addClass('selected');
            galleryShowVideo();
        }        
    });
    
    $('.articleRwVideoGalleryWrapper ul li a').click(function(e) {
        e.preventDefault();
        $('.articleRwVideoGalleryWrapper ul li').removeClass('selected');
        $(this).parent().addClass('selected');
        $(document).scrollTo('.top', 500);
        playVideo($(this).attr('title'), $(this).attr('href'));
    });
});

function playVideo(splashFile, videoFile) {
    var swf;
    if (navigator.appName.indexOf("Microsoft") != -1) {
        swf = window["articleRwGalleryVideo"];
    } else {
        swf = document["articleRwGalleryVideo"];
    }
    swf.playVideo(splashFile, videoFile);
}
/*    
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}
function sendToActionScript(value) {
    thisMovie("ExternalInterfaceExample").sendToActionScript(value);
}*/

function galleryShowImages() {
    //alert('showing images');
    $('.articleRwVideoGalleryWrapper').animate({opacity: 0}, 300, "swing", function() {
        $('.articleRwVideoGalleryWrapper').css({display: 'none'});
        $('.articleRwPhotoGalleryWrapper').css({display: 'block'});
        $('.inspirationGallery').animate({height: photoHeight+51+'px'}, 300, "swing", function() {
            $('.articleRwPhotoGalleryWrapper').animate({opacity: 1}, 300, "swing");
        });        
    });
    
    $('.viewSlideshow').show();
}

function galleryShowVideo() {
    //alert('showing video');
    $('.articleRwPhotoGalleryWrapper').animate({opacity: 0}, 300, "swing", function() {
        $('.articleRwPhotoGalleryWrapper').css({display: 'none'});
        $('.articleRwVideoGalleryWrapper').css({display: 'block'});
        $('.inspirationGallery').animate({height: videoHeight+51+'px'}, 300, "swing", function() {
            $('.articleRwVideoGalleryWrapper').animate({opacity: 1}, 300, "swing");
        });
    });
    
    $('.viewSlideshow').hide();  
}

function getHeights() {
    if($('.articleRwVideoGalleryWrapper').height() < 100) {
        videoHeight = 360;
    } else {
        videoHeight = $('.articleRwVideoGalleryWrapper').height();
    }
    if($('.articleRwPhotoGalleryWrapper').height() < 100) {
        photoHeight = 360;
    } else {
        photoHeight = $('.articleRwPhotoGalleryWrapper').height();
    }
}
