// JavaScript Document
// Author: Ashok Kumar Gupta
// Copyright Warner/Chappell Music
// This document is sole property of Warner/Chappell Music

// Based on browser DOM parsing
var isIE =navigator.appName.indexOf("Microsoft") != -1;
function audioComponent(movieName) {
    if (isIE) {
        return window[movieName]
    }else {
        return document[movieName]
	}
}
function loadPlayListHome(media,index,win){
	//var msrc = '/resources/flash/benji/homemusicplayer.swf';
	audioComponent("homemusicplayer").wrappermedia(media,index,win,"menu");
}
// This function load music player respective to the param values
var mmediaValue;
var mindexValue;
//var vidPaneID;
function loadPlayList(media,index,win){
		var msrc = '/resources/flash/player/b2baudioplayer.swf';
		mmediaValue = media;
		mindexValue = index;
		closeWindow();
		if(vidPaneID == null){
				vidPaneID = document.createElement('div');
				vidPaneID.setAttribute('id','mpcontainer');
				vidPaneID.setAttribute('class','playSingleStyle');
				vidPaneID.setAttribute('className','playSingleStyle');
				vidPaneID.style.top='180px';                     // Starting location horozontal
				vidPaneID.style.left='455px';                    // Starting location verticle
			}else{
				vidPaneID = document.getElementById('mpcontainer');
				vidPaneID.innerHTML = "";
				vidPaneID.style.display = "none";
		}
	 var bodyEle = document.getElementsByTagName('body')[0];
     vidPaneID.style.display='block';
	 var layerstring = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
	 layerstring += "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0'";
	 layerstring +="width='240' height='170' id='b2baudioplayer' align='middle'><param name='allowScriptAccess'";
	 layerstring +="value='sameDomain' /><param name='allowFullScreen' value='false' />";
	 layerstring +="<param name='movie' value='"+msrc+"' />";
	 layerstring +="<param name='flashvars' value='_mediaName="+media+"&_index="+index+"&_window="+win+"' />";
	 layerstring +="<param name='quality' value='high' /><param name='wmode' value='window' />";
	 layerstring +="<embed src='"+msrc+"' quality='high' wmode='window' flashvars='_mediaName="+media+"&_index="+index+"&_window="+win+"' width='240' height='170' name='b2baudioplayer' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	vidPaneID.innerHTML = layerstring;
	bodyEle.appendChild(vidPaneID);
}

function updateindex(media,index){
	mmediaValue = media;
	mindexValue = index;
}
function updatesingle(asset,type){
	mmediaValue = asset;
	mindexValue = type;
}

// This function pop-out player
function popoutPlaylist(){
	newmusicwindow = window.open("/playerList.html","","width=240,height=170,scrolling=0,resizable=0,statusbar=0");
	newmusicwindow.focus();
	vidPaneID.innerHTML = "";
	vidPaneID.style.display = "none";
}

function popoutSingle(){
	newmusicwindow = window.open("/playSingle.html","","width=240,height=170,scrolling=0,resizable=0,statusbar=0");
	newmusicwindow.focus();
	document.getElementById('mpcontainer').innerHTML = "";
	document.getElementById('mpcontainer').style.display = "none";
}


// Function to provide relevant Error message

function misssingAsset(msg){
	if(msg == 'SecurityError'){
		alert('Please make sure you have access to the mentioned domain.');
	}else if(msg == 'XMLIOError'){
		alert('Please make sure XML path is correct and then reload player.');
	}else if(msg == 'SongIOError'){
		if(navigator.userAgent.indexOf("Safari") != -1){
			return;
		}else{
			alert('Please make sure song path is correct.');
		}
	}
	closePlayer();
}