// Hello jQuery!
$(document).ready(function(){
//    Add a width class to the slider
    var colNum = ($("#thumbs .col").length * 116);
    if( colNum > 1160 ) {
        $("#slider").addClass("superWide")
    } else {
        $("#slider").addClass("wide" + colNum)
    }
//    Parse the media url and determine the type of media file
//    Return the appropriate html to display the media
    var firstImg = $("#thumbs li.active a").attr("href");
    var firstFilePath = $("#thumbs li.active a").attr("href");
    var firstSplitLink = firstFilePath.split("?");
    var firstEnd = firstSplitLink[0].lastIndexOf(".");
    var firstMediaType = firstSplitLink[0].substring(firstEnd+1).toLowerCase();
    if ( firstMediaType == "swf" ) {
        addMediaToPage(getMediaContent($("#thumbs li.active a")));
    } else {
        $("#imgContainer").html('<img src="' + firstImg + '" alt="" />');
    }
    var firstCaption = $("#thumbs li.active .caption").html();
    $("#captionContainer").html(firstCaption);
//    Generate code based on the type of media to be displayed
    function getMediaContent(el) {
        var filePath = $(el).attr("href");
        var splitLink = filePath.split("?");
        var end = splitLink[0].lastIndexOf(".");
        var mediaType = splitLink[0].substring(end+1).toLowerCase();
        var mediaContent;
        //    Generate code based on the type of media to be displayed
        switch(mediaType) {
            case "swf":
                var urlParams = filePath.split("?");
                link = urlParams[0];
                var properties = getQueryString(urlParams[1]);
                flashVars = properties['var1'];
    
                mediaContent = '<script type="text/javascript">'+
                                'var flashvars = {'+
                                    'var1: "' + flashVars + '"'+
                                '};'+
                                'var params = {'+
                                    'wmode: "transparent",'+
                                    'bgcolor: "transparent",'+
                                    'quality: "high",'+
                                    'allowFullScreen: "false",'+
                                    'allowScriptAccess: "sameDomain"'+
                                '};'+
                                'var attributes = {};'+
                                'swfobject.embedSWF("/flash/galleryVideo_player.swf", "modVideo", "320", "268", "9.0.0","/flash/expressInstall.swf", flashvars, params, attributes);'+
                            '</script>'+
                            '<div id="modVideo">&nbsp;</div>';
            break;
            case "jpg":
            case "jpeg":
            case "gif":
            case "png":
            case "bmp":
                mediaContent = '<img src="' + filePath + '" alt="" />';
            break;
        }
        return mediaContent;
    }
//    To add the media to the page
    function addMediaToPage(mediaContent) {
        $("#imgContainer").html(mediaContent);
    }
//    When you click the thumbnail, make all of the above happen
    $("#thumbs a").click(function(){
        $("#thumbs .col li").removeClass("active")
        $(this).parent().addClass("active")
        $("#imgContainer, #captionContainer").empty();
        var thisCaption = $(this).next(".caption").html()
        addMediaToPage(getMediaContent($(this)));
        $("#captionContainer").html(thisCaption)
        return false;
    })
    function getQueryString(params) {
        var props = new Array();
        $(params.split("&")).each(function(i) {
            var param = this.split("=");
            props[param[0]] = param[1];
        });
        return props;
    }

//    Gallery Dropdown
    $("#otherGalleries").hover (
        function() {
            $(this).addClass("over");
        },
        function() {
            $(this).removeClass("over");
        }
    );




}); // Bye-bye jQuery!
