/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$.tiltGallery = function(id)
{
    var flashvars =
    {
        useFlickr: "false",
        collumns: "5",
        rows: "3",
        zoomedInDistance: "900",
        zoomedOutDistance: "4500",

        // XML GALLERY OPTIONS
        xmlURL: "../images/archive/"+id+"/gallery.xml",
        maxJPGSize: "1000",
        //
        // END TILTVIEWER-PRO CONFIGURATION OPTIONS
        allowFullScreen: "false",
        useReloadButton: "false",
        showFlipButton: "false",
        showLinkButton: "false",
        enableSounds: "false",
        frameWidth: "15",
        showFullscreenOption: "false",
        tiltAmountIn: "30",
        tiltAmountOut: "75"
    };
    swfobject.embedSWF("../imgGal/TiltViewer.swf", "viewer_content", "100%", "100%", "9.0.28", null, flashvars);
    /*
    // TILTVIEWER-PRO CONFIGURATION OPTIONS
    // To use these options, uncomment them by removing the '//' at the start of the line
    // For a description of config options, go to:
    // http://www.airtightinteractive.com/projects/tiltviewer/pro/config_options.html
    //
    fo.addVariable('useFlickr', 'false');
    fo.addVariable('columns', '5');
    fo.addVariable('rows', '3');
    //fo.addVariable('linkLabel', 'This is the Link text');
    fo.addVariable('zoomedInDistance', '900');
    fo.addVariable('zoomedOutDistance', '4750');
    //fo.addVariable('fontName', 'Arial');
    //fo.addVariable('titleFontSize', '90');
    //fo.addVariable('descriptionFontSize', '32');
    //fo.addVariable('linkFontSize', '41');
    //fo.addVariable('textColor', '0xFF0000');
    //fo.addVariable('linkTextColor', '0x00FF00');
    //fo.addVariable('linkBkgndColor', '0x0000FF');
    //fo.addVariable('frameColor', '0xFF0000');
    //fo.addVariable('backColor', '0x00FF00');
    //fo.addVariable('bkgndInnerColor', '0xFF00FF');
    //fo.addVariable('bkgndOuterColor', '0x0000FF');
    //
    // FLICKR GALLERY OPTIONS
    //fo.addVariable('user_id', '48508968@N00');
    //fo.addVariable('tags', 'jump,smile');
    //fo.addVariable('tag_mode', 'all');
    //fo.addVariable('showTakenByText', 'true');
    //
    
    fo.addVariable('xmlURL', 'gallery.xml');
    fo.addVariable('maxJPGSize', '1000');
    //
    // END TILTVIEWER-PRO CONFIGURATION OPTIONS
    fo.addParam("allowFullScreen","false");
    fo.addVariable('useReloadButton', 'false');
    fo.addVariable('showFlipButton', 'false');
    fo.addVariable('showLinkButton', 'false');
    fo.addVariable('enableSounds', 'false');
    fo.addVariable('frameWidth', '30');
    fo.addVariable('showFullscreenOption', 'false');
    fo.addVariable('tiltAmountIn', '30');
    fo.addVariable('tiltAmountOut', '75');
    */
};

$.videoGallery = function(id)
{
    $('#viewer_content').css('height', '595');
    /*
    $('#viewer_content').html
    (
        '<object width="1000" height="593">'+
            '<param name="movie" value="http://www.youtube.com/v/'+id+'?version=3&hd=1"</param>'+
            '<param name="allowFullScreen" value="true"></param>'+
            '<param name="allowScriptAccess" value="always"></param>'+
            '<embed src="http://www.youtube.com/v/'+id+'?version=3&hd=1"'+
                'type="application/x-shockwave-flash"'+
                'allowfullscreen="true"'+
                'allowscriptaccess="always"'+
                'width="1000" height="593">'+
            '</embed>'+
        '</object>'
    );*/
    swfobject.embedSWF("http://www.youtube.com/v/"+id+"?version=3&hd=1", "viewer_content", "1000", "593", "10.0.0", null, null);
}

//Loading gallery when DOM is ready
$(document).ready(function()
{
    //This.id
    $('.imgGal').bind('click', function(event)
    {
        $.senterPosition();
        $('#viewer_description').text(this.title);
        $('#viewer_name').text(this.name);
        $.viewerOpen();
        $.tiltGallery(this.id);
        event.preventDefault();
    });

    $('.videoGal').bind('click', function(event)
    {
        $.viewerSetup(this.title, this.name)
        $.videoGallery(this.id);
        event.preventDefault();
    });

    $('#viewer_close').bind('click', function(){$.viewerClose();});
    $('#viewer_background').bind('click', function(){$.viewerClose();});
});

$.viewerSetup = function(title, name)
{
    $.senterPosition();
    $('#viewer_description').text(title);
    $('#viewer_name').text(name);
    $.viewerOpen();
}

$.viewerOpen = function()
{
    $('#viewer_background').fadeIn('slow');
    $('#viewer').fadeIn('slow');    
};

$.viewerClose = function()
{
    $('#viewer_background').fadeOut('slow');    
    $('#viewer').fadeOut('slow');
    swfobject.removeSWF('viewer_content');
    //Because removeSWF removs the whole div where the content is, it must be created again
    var c = document.getElementById('viewer_content');
    if(!c)
    {
        $('#viewer').prepend('<div id="viewer_content"></div>');
    }
    $('#viewer_content').empty();
};

$.senterPosition = function()
{
    var viewerWidth = 1020;
    var width = $(window).width();

    var xPos = width/2 - (viewerWidth / 2);
    $('#viewer').css('left',xPos);
};
