// DDH EPLAYER JAVASCRIPT FUNCTIONS


var wimpyWindow;
var winOpen=0;



var wimpyWindow;
var isMultiple=0;
var winOpen=0;
var tempFile;
var tempArtist;
var tempTitle;
var tempGraphicURL;
var tempHotlinkURL;

var arrayIndex;
var arrayLength;
var isMultiple;
var cueMultipleFirst = 0;

var fileArray;
var artistArray;
var titleArray;
var graphicsArray;
var hotlinkArray;

var windowWidth = 480;
var windowHeight = 140;

function wimpyIsOpen(){
    if (winOpen==1){
        if (wimpyWindow.closed){
            return false;
        } else {
            //doSerialze();
            return true;
        }
    } else {
        return false;
    }
    //return true;
}

function doSerialze() {
    var whoa;

    whoa = wimpyWindow.toSource();

    alert(whoa);
    alert("gug");

}

function wimpyPopAndPlayMultiple(theFiles, theArtists, theTitles, hotlinkURLs, graphicURLs) {
    fileArray = theFiles.split("|");
    artistArray = theArtists.split("|");
    titleArray = theTitles.split("|");
    hotlinkArray = hotlinkURLs.split("|");
    graphicsArray = graphicURLs.split("|");

    isMultiple = 1;
    arrayIndex = 0;
    arrayLength = fileArray.length;

    if(wimpyIsOpen()){
        //since we're already loading the first right here, we don't need to load it again from the array iterator
        cueMultipleFirst = 1;
        playMultipleTrack();
    } else {
        wimpyPopPlayer();
    }
}

function wimpyPopAndCueMultiple(theFiles, theArtists, theTitles, hotlinkURLs, graphicURLs) {
    fileArray = theFiles.split("|");
    artistArray = theArtists.split("|");
    titleArray = theTitles.split("|");
    graphicsArray = graphicURLs.split("|");
    hotlinkArray = hotlinkURLs.split("|");

    isMultiple = 1;
    arrayIndex = 0;

    arrayLength = fileArray.length;

    if(wimpyIsOpen()){
        cueMultipleFirst = 1;
        cueMultipleTrack();
    } else {
        wimpyPopPlayer();
    }
}



function wimpyPopAndPlay(wimpyPopPage, theWidth, theHeight, theFile, theArtist, theTitle, hotlinkURL, graphicURL){
    isMultiple = 0;

    if(wimpyIsOpen()){
        myLoadAndPlay(theFile, theArtist, theTitle, hotlinkURL, graphicURL);
    } else {
        tempFile = theFile;
        tempArtist = theArtist;
        tempTitle = theTitle;
        tempHotlinkURL = hotlinkURL;
        tempGraphicURL = graphicURL;

        //wimpyPopPlayer();
    	
		wimpyWindow = window.open(wimpyPopPage,'wimpyMP3player','width='+theWidth+',height='+theHeight,theFile);
		wimpyWindow.focus()
		winOpen=1;
	
	}
}

function wimpyPopAndCue(theFile, theArtist, theTitle, hotlinkURL, graphicURL){
    isMultiple = 0;

    if(wimpyIsOpen()){
        myAppendPlaylist(theFile, theArtist, theTitle, hotlinkURL, graphicURL);
    } else {
        tempFile = theFile;
        tempArtist = theArtist;
        tempTitle = theTitle;
        tempHotlinkURL = hotlinkURL;
        tempGraphicURL = graphicURL;

        wimpyPopPlayer();
    }
}

function myLoadAndPlay(file, artist, title, itemID, imageUrl) {
    wimpyWindow.wimpy_addTrack(true,file, artist, title, 'http://www.ddhestore.co.uk/add.php%3Faction%3DaddPlayer%26product%3D' + itemID + '%26type%3Daudio%26quantity%3D1', imageUrl);
    wimpyWindow.focus();
}

function myAppendPlaylist(file, artist, title, itemID, imageUrl) {
    wimpyWindow.wimpy_appendPlaylist('track', file, artist, title, 'http://www.ddhestore.co.uk/add.php%3Faction%3DaddPlayer%26product%3D' + itemID + '%26type%3Daudio%26quantity%3D1', imageUrl);
    wimpyWindow.focus();
}

function loadFirstTrack() {
    myLoadAndPlay(tempFile, tempArtist, tempTitle, tempHotlinkURL, tempGraphicURL);
}

function playMultipleTrack() {
    myLoadAndPlay(fileArray[arrayIndex], artistArray[arrayIndex], titleArray[arrayIndex], hotlinkArray[arrayIndex], graphicsArray[arrayIndex]);
}

function cueMultipleTrack() {
    myAppendPlaylist(fileArray[arrayIndex], artistArray[arrayIndex], titleArray[arrayIndex], hotlinkArray[arrayIndex], graphicsArray[arrayIndex]);
}



// CUSTOM LAUNCH FUNCTION
function launchEplayer(wimpyPopPage,theWidth,theHeight,theFile,theArtist,theTitle,graphicURL,hotlinkURL) {
	if (wimpyIsOpen()){
		wimpyWindow = window.open(wimpyPopPage,'wimpyMP3player','width='+theWidth+',height='+theHeight,theFile);
		wimpyWindow.focus()
		winOpen=1;
	} else {
		//wimpyWindow.wimpy_loadAndPlay(theFile, theArtist, theTitle, graphicURL, hotlinkURL);
		//wimpyWindow.focus()
		
		if(wimpyIsOpen()){
			wimpyWindow.wimpy_loadAndPlay(theFile, theArtist, theTitle, graphicURL, hotlinkURL);
			wimpyWindow.focus()
			winOpen=1;
		} else {
			wimpyWindow = window.open(wimpyPopPage,'wimpyMP3player','width='+theWidth+',height='+theHeight,theFile);
			wimpyWindow.focus()
			winOpen=1;
		}
		
	}
}
