var counter=0;
var maxcounter=null;
var shiftamount;
var intervalID;
$(document).ready(function(){
						   
						   
							  createPopUp();
							 
							  
							  $('a').each(function(n){
													 			
													 			var temp=$(this).attr('rel');
																if(temp=="video")
																{
																	
																			$(this).bind('click',openpopup);
																}
																
																			
																	
																	});
							  
						   });




function createPopUp(e)
{
	//
	W = $(window).width();
	H = $(window).height();
	
	var cStyle="position:fixed; top:0px; left:0px; display:none;";
	var shadowstyle = "position:absolute; top:0px; left:0px; width:"+W+"px; height:"+H+"px; background:url(images/popupbg.png);";
	var pstyle = "position:relative; width:40px; height:40px; background:#FFFFFF; overflow:hidden;";
	pstyle = pstyle+"-moz-box-shadow:0px 0px 10px #000000; -webkit-box-shadow:0px 0px 10px #000000;"
	var crossstyle="position:absolute; top:0px; left:0px; cursor:pointer;";
	crossstyle = crossstyle+"-moz-box-shadow:0px 0px 3px #000000; -webkit-box-shadow:0px 0px 3px #000000; display:none;"
	
	var htmlc = "<div id='popup' style='"+cStyle+"'><div id='sh' style='"+shadowstyle+"'></div><div id='popupcontent' style='"+pstyle+"'></div>";
	htmlc = htmlc+"<img id='crossbt' style='"+crossstyle+"' src='http://www.webguru-development.com/debdulal/eardoc/images/cross.jpg'/></div>";
    
	
    $('body').append(htmlc);
	$('#sh').css('opacity',0.9);
	resizing();
	$(window).resize(resizing);
	$('#crossbt').click(function(){
								   
								      $('#popup').fadeOut('fast',function(){  $('#popupcontent').css('width',40);   
																			  $('#popupcontent').css('height',40); 
																			  resizing(); 
																			  $('#crossbt').hide();
																			  $('#frame').hide();
																			  
																			});
								  })

}


function resizing()
{
  W = $(window).width();
  H = $(window).height();
  $('#sh').css('width',W);
  $('#sh').css('height',H);
  $('#sh').css('overflow','hidden');
  
  wx = $('#popupcontent').width();
  hx = $('#popupcontent').height();
  $('#popupcontent').css('left',(W-wx)/2);
  $('#popupcontent').css('top',(H-hx)/2);
  $('#crossbt').css('left',((W-wx)/2)+wx);
  $('#crossbt').css('top',(H-hx)/2);
	
}


function openpopup(e)
{
	
	W = $(window).width();
    H = $(window).height();
	e.preventDefault();
	var source=$(this).attr('href');
		//edited code begins here
	var PreSource="http://www.youtube.com/embed/";
	var numCharacters = source.length;
	var StartPos=source.indexOf("v=") + 2;
	var EndPos=numCharacters;
	var newsource="";
	if(source.indexOf("&") >= 0)
	{
		EndPos=source.indexOf("&");
	}
	for(i=StartPos;i<EndPos;i++)
	{
		newsource = newsource + source.charAt(i);
	}

	newsource=PreSource+newsource;
	//edited code ends here
	
	
	$('#popup').fadeIn('fast',function(){
									   
	$('#popup #popupcontent').html("<iframe id='frame' style='display:none;' frameborder='0' id='video' width='650' height='366' src='"+newsource+"'></iframe>");
	obj = new Object();
	obj.width = 650;
	obj.height  = 366;
	obj.left = (W - 650)/2;
	obj.top = (H - 366)/2;
	$('#crossbt').css('left',((W-650)/2)+650);
    $('#crossbt').css('top',(H-366)/2);
	
	$('#popup #popupcontent').animate(obj,500,function(){
													       $('#crossbt').fadeIn();
														   $('#frame').fadeIn();
														  
													     
														 });
										
										})
	
}
