/*
 * Nice youtube embedder with autoplay cookie check
 * This software is licenced under General Public Licence
 * Matt Jaworski - www.mjaworski.pl
 * You can make commitments/changes to this code, as long as this header remains intact
 */

//get the div element and load config from DOM
var responseDiv=document.getElementById('youtubeAutoPlay');
var howManyDays = responseDiv.className;
var	movieURL=responseDiv.innerHTML;
alert(movieURL);

//check the cookie and determine whether to autoplay the movie or not and set appropriate flag
var autoplay=1;
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf('YTplayed' + "=");
  if (c_start!=-1)
    {
    	c_start=c_start + 'YTplayed'.length+1;
    	c_end=document.cookie.indexOf(";",c_start);
    	if (c_end==-1) c_end=document.cookie.length;
    	YTplayed = unescape(document.cookie.substring(c_start,c_end));
    	
    	if(YTplayed=='YES') 
    	{
    		autoplay=0;
    	}
    	else
    	{
    		//set the flag to 1
    		autoplay=1;
       	}
    }
  }
  
//set the cookie if needed
if(autoplay==1)
{
		// and set the cookie so next time we visit it wont play again
      	var exdate=new Date();
		exdate.setDate(exdate.getDate()+howManyDays);
		document.cookie='YTplayed'+ "=" +'YES'+((howManyDays==null) ? "" : ";expires="+exdate.toGMTString());
}

//print response inline NO WHITESPACES ALLOWED IN THE STRING
var response='<embed height="241" width="310" allowfullscreen="true" allowscriptaccess="always" src="'+movieURL+'&amp;autoplay='+autoplay+'" type="application/x-shockwave-flash" style="margin: 0px; float: left;"></embed>';
responseDiv.innerHTML=response;