// JavaScript Document

function swapMoviePlayerLink(){
	if (document.getElementById("moviePlayerContent")){
		// set up links
		
		// add onclick and void function to openVideo link
		var openLink = document.getElementById("openVideo");
		openLink.setAttribute("href", "javascript:void(0);");
		openLink.onclick = function(){
			openPlayer("moviePlayerContainer");
		}
		
		// add onclick and void function to closePlayer link
			var closeLink = document.getElementById("closePlayer");
			closeLink.setAttribute("href", "javascript:void(0);");
			closeLink.onclick = function(){
				 closePlayer("moviePlayerContainer");
				}
			
			movieScrollDiv = document.getElementById("movieScroll");
			//movieScrollDiv.style.overflow = "auto";
			

			
			moviePlayerDiv = document.getElementById("moviePlayerContent");
			var mpDivLinks = moviePlayerDiv.getElementsByTagName("a");
			
			for (var i=0; i<mpDivLinks.length; i++){
				 var mpLink = mpDivLinks[i];
				 	 if (mpLink.id.indexOf("closePlayer") == -1){
						  
					     var getLink = mpLink.getAttribute("href");
							 var splitLink = getLink.split("#");
							 var linkId = splitLink[1];
							 mpLink.setAttribute("id", linkId + "Link");
							 mpLink.setAttribute("href", "javascript:void(0);");
							 mpLink.onclick = function(){
								 	openMovie(this);
							
								 }
					}
				
				}
			
		}
	
	}

function openPlayer(thisMovie){
		var thisDiv = document.getElementById(thisMovie);
		thisDiv.style.left = "1px";
}

function closePlayer(thisMovie){
 
	var thisDiv = document.getElementById(thisMovie);
	thisDiv.style.left = "-99999px";
	movieScrollDiv.style.display = "block";
  
	if (document.getElementById("flashHolder")){
			moviePlayerDiv.removeChild(newDiv);
			productsH6.removeChild(movieTitleTxt);
			productsH6.appendChild(pTitle);
	}
}

function openMovie(getMovie){

	movieScrollDiv.style.display = "none";
	var thisTitle = getMovie.title;
	var linkId = getMovie.id
	var movieName = linkId.replace("Link", "")

	newDiv = document.createElement("div");
	newDiv.setAttribute("id","flashHolder");
	
	
	moviePlayerDiv.appendChild(newDiv);
	
	playMovie(movieName, thisTitle);
	
	return newDiv;
	return moviePlayerDiv;
	
}

function playMovie(movieId, thisTitle){
		
		
		if (movieId == "video1"){
			var so = new SWFObject("../flash/DKcard.swf", "demo", "288", "180", "8", "");			
			so.addParam("quality", "high");
			so.addParam("allowScriptAccess", "always");
			so.write("flashHolder");
		} else if (movieId == "video2"){
			var so = new SWFObject("flash/DKcard.swf", "demo", "288", "180", "8", "");			
			so.addParam("quality", "high");
			so.addParam("allowScriptAccess", "always");
			so.write("flashHolder");
		}	else if (movieId == "video3"){
			var so = new SWFObject("flash/DKcard.swf", "demo", "288", "180", "8", "");			
			so.addParam("quality", "high");
			so.addParam("allowScriptAccess", "always");
			so.write("flashHolder");
		}
	
		
		
		productsH6 = document.getElementById("productsTitle");
		
		pTitle = productsH6.firstChild;
		
		movieTitle = thisTitle;
		movieTitleTxt = document.createTextNode(movieTitle);
		productsH6.removeChild(pTitle);
		productsH6.appendChild(movieTitleTxt);
	  
		return productsH6;
		return pTitle;
		return movieTitleTxt;
}

addLoadEvent(swapMoviePlayerLink);
