$(document).ready
(
	function() 
	{
		// activate fancy zoom
		$('.video_link').fancyZoom({width:493, height:320}); 
		$('.video_link_big').fancyZoom({width:840, height:400});
		$('.iframe_link').fancyZoom({width:485, height:150});
		$('#euro_product_link').fancyZoom({width:485, height:150}); 
		$('#npp_product_link').fancyZoom({width:485, height:150}); 
				
		//save the url to the swf and video
		// use hash to lightbox panel for fancy zoom to work
		function ReplaceFancyZoomLink(elem)
		{
			$(elem).data('url', $(elem).attr('href'));
			$(elem).attr('href', '#lightbox');
		}

		$('.video_link').each
		(
			function(i)
			{
				ReplaceFancyZoomLink(this);
			}
		);
		
		// create swf object on video link click
		$('.video_link').click
		(
			function()
			{	
				var pnlLightbox = $('#lightbox');
				pnlLightbox.html("");
				LoadContentInLightWindow(this, $(this).data('url'), 'video', 480, 290, 'small');
			}
		);
		
		$('.video_link_big').each
		(
			function(i)
			{
				ReplaceFancyZoomLink(this);
			}
		);
		
		// create swf object on video link click
		$('.video_link_big').click
		(
			function()
			{	
				var pnlLightbox = $('#lightbox');
				pnlLightbox.html("");
				LoadContentInLightWindow(this, $(this).data('url'), 'video', 830, 400, 'big');
			}
		);
		
		 $('.iframe_link').each
		(
			function(i)
			{
				ReplaceFancyZoomLink(this);
			}
		);
    
        $('.iframe_link').click
		(
			function()
			{	
				var pnlLightbox = $('#lightbox');
				pnlLightbox.html("");
				LoadContentInLightWindow(this, $(this).data('url'), 'iframe', '', '', '');
			}
		);	
		
    
		// remove swf object html when closing
		$('#zoom_close').click
		(
			function() {			    
				var pnlLightbox = $('#lightbox');
				if(pnlLightbox.html() != null)
				{
				    if(pnlLightbox.html().indexOf('embed') > -1 || pnlLightbox.html().indexOf('object') > -1 || pnlLightbox.html().indexOf('img') > -1)
					    pnlLightbox.html("");
				}
			}
		);		
		
	}
);
function loadVideo(video, preview_img, autoplay, width, height, size)
{
    var params = {
            allowfullscreen: "true",
            allowscriptaccess: "sameDomain",
            wmode: "opaque"
    };
    
    var flashvars = {};
    
    var swfPlayer = '/flash/player.swf';

    $('#zoom').removeClass();    
    
    if (size == 'big')
    {
        swfPlayer = video;
        flashvars = { localXMLPath: '/xml/batch_products.xml', autostart: autoplay, controlbar : "bottom", icons: "false", dock: "true", image: preview_img };
        $('#zoom').addClass('big');
    }
    else
    {
        flashvars = { file: video, autostart: autoplay, controlbar: "bottom", icons: "false", dock: "true", image: preview_img };
        $('#zoom').addClass('small');
        
    }
    
    var attributes = {};   
    //$('#zoom_content2').prepend("<div style='text-align: left; margin: 0px 0px 8px 15px;'>&nbsp;</div>");
    
    swfobject.embedSWF(swfPlayer, "zoom_video", width, height, "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
} 

function LoadContentInLightWindow(element, strUrl, strContentType, width, height, strVideoSize)
{
  var pnlLightbox = $('#lightbox'); 
  if(strContentType == "iframe")
  {       
	imageHTML = "<iframe src =" + strUrl + " frameborder='0' width='100%'><p>Your browser does not support iframes.</p></iframe>"		
	pnlLightbox.html(imageHTML);		
  }
  else
  {
    loadVideo(strUrl, "", true, width, height, strVideoSize);
  }
} 

function openEuroProductInfo()
{
	$('#euro_product_link').simulate('click');
}
function openNppProductInfo()
{
	$('#npp_product_link').simulate('click');
}
