﻿var _serviceUrl = "ScriptServices/SlideShowServices.asmx";
var storedSlideshowVolume = { defaultvolume: "50", defaultmuting: "N" };

function GetSlideShowOptions(picIndex, autoStart, menuExtensionHtml, onClickFuntion, onChangeFunction, onCloseFunction, onPlayFunction, onPauseFunction)
{    
    var slideshowOptions = {
        fx: ''
                , dataType: 'json'
                , moveFx: null
                , columns: 1
                , imageHeight: 400
                , prevNext: false
                , firstLast: false
                , wrap: true
                , shuffle: false
                , slideShow: true
                , slideShowStart: true
                , slideShowContinuous: true
                , thumbnails: true
                , thumbnailsPosition: 'bottom'
                , thumbnailsSize: 65
                , imageClickBehavior: 'popup'
                , uiFadeEnabled: false
                , menuPosition: 'below'
                , menuExtensionPosition: 'bottom'
                , menuExtension: menuExtensionHtml
                , menuCompact: true
                , uiFadeDelay: null /* null to disable */
                , resources: [{ height: 240 }, { height: 480 }, { height: 1200}]
                , titleShow: true
                , paplayer_path: 'paplayerSlideShow.swf'
                , aspect: { x: parseInt($('#aspectImageWidth').val()), y: parseInt($('#aspectImageHeight').val()) }
                , aspectThumbs: { x: 4, y: 3 }
                , zoomToFit: true
                , zoomToFitThumbs: true
                , videoPlay: "setVolume(15, 'F')"
                , videoPause: "setMuteFullScreen('F')"
                , videoEnd: 'resumeNext'
                , onChange: onChangeFunction
                , onClick: onClickFuntion
                , imageClickBehavior: null
        };
    return slideshowOptions;
}

function GetFullScreenSlideShowOptions(picIndex, originalAlbumId, autoStart, showCloseButton, menuExtensionHtml, onChangeFunction, onCloseFunction, onPlayFunction, onPauseFunction, afterCloseFunction)
{
    var enableMenuFade = false;
    if(menuExtensionHtml == null || menuExtensionHtml == "")
    {
        menuExtensionHtml = null;
        enableMenuFade = true;
    }

    var slideshowOptions = {
            dataType : "json",
            frameWidth: 0,
	        preload: 1,
	        fx: '',
	        menuPosition: 'bottom',
	        shuffle: false,
	        loadFullImages: true,
	        thumbnails: true,
	        sliderBar: false,
	        picIndexToSelect: picIndex,
	        slideShowStart: autoStart,			
	        slideShowSpeeds: [{ text: 'Slow', speed: 7000 }, { text: 'Medium', speed: 5000 }, { text: 'Fast', speed: 3000}],
            slideShowDelay: 5000,
            showClose: showCloseButton,
            menuFadeEnabled: enableMenuFade,
            menuExtension: menuExtensionHtml,
            menuExtensionPosition: 'bottomright',
            menuActivateFromAnywhere: true,
            onChange: onChangeFunction,
            onClose: onCloseFunction,
            onPlay: onPlayFunction,
            onPause: onPauseFunction,
            originalAlbumId: originalAlbumId,
            afterClose: afterCloseFunction,
            videoWidth: 533,
            videoHeight: 400,
            videoPlay: "setVolume(15, 'F')",            
            videoPause: "setMuteFullScreen('F')",
            videoEnd: 'resumeNext',
            paplayer_path: 'paplayerSlideShow.swf'
        };
    return slideshowOptions;
}

function SaveSlideShowMusic(musicFileId, setType, setId, successHandler, errorHandler)
{
	var args = {};
	args.musicFileId = musicFileId;
	args.setType = setType;
	args.setId = setId;

	var callUrl = _serviceUrl + "/SaveMusicFile";

	//  Format the JSON request
	var jsonData = JSON.stringify(args);
	
	$.ajax({
		type: "POST",
		url: callUrl,
		contentType: "application/json; charset=utf-8",
		data: jsonData,
		dataType: "json",
		success: successHandler,
		error: errorHandler
	});	
}

function HandleVolumeChange(level, muting)
{
//	if ($.cookie)
//	{
//		//	Write to cookie
//		$.cookie("OPF.SS.Music.Level", level + "|" + muting);
//    }

    //  Write to the in-memory object:
    storedSlideshowVolume.defaultvolume = level;
    storedSlideshowVolume.defaultmuting = muting;        
    
    //	Set focus to the body element because
    //	IE grabs focus from page when user interacts with Flash player
    $("body")[0].focus();
}

function InitDefaultVolume()
{
	//	Retrieve from cookie		
	var stored = $.cookie("OPF.SS.Music.Level");
	if (stored && stored != "")
	{
		var storedData = stored.split("|");
		storedSlideshowVolume.defaultvolume = storedData[0];
		storedSlideshowVolume.defaultmuting = storedData[1];
	}

    //  Return the default (if you really want it)
	return storedSlideshowVolume;
}

