cont = null;
bg_div = null;
iframe_cont = null;
timerID = null;
my_iframe = null;
function generate(id, type, ifrSrc, w, h, thumbUrl, shareUrl, linkText){
	cont = document.getElementById(id);
	switch (type){
		case 'icon':		
				add_divs(w,h);
				cont.style.width = '139px';
				cont.style.height = '91px';
				var link = document.createElement('a');
				link.style.position = 'relative';
				link.setAttribute('href','#');
				link.onclick=function(){
					showSlideshow(w,h,ifrSrc);
					return false;
				};
				cont.appendChild(link);
				var img1 = document.createElement('img');
				img1.setAttribute('src',shareUrl);
				img1.style.position = 'absolute';
				img1.style.zIndex = '9998';
				img1.style.border = 'none';
				img1.style.float = 'left';
				img1.onmouseover=function(){
					hover_tb(this);
					return false;
				};
				img1.onmouseout=function(){
					unhover_tb(this);
					return false;
				};
				link.appendChild(img1);
				var shadow = document.createElement('div');
				shadow.style.float = 'left';
				shadow.style.backgroundColor = '#000000';
				shadow.style.opacity = '0.7';
				shadow.style.position = 'absolute';
				shadow.style.zIndex = '9997';
				shadow.style.width = '137px';
				shadow.style.height = '89px';
				shadow.style.margin = '1px';				
				link.appendChild(shadow);
				var img2 = document.createElement('img');
				img2.setAttribute('src',thumbUrl);
				img2.style.position = 'absolute';
				img2.style.zIndex = '9996';
				img2.style.opacity = '0.7';
				img2.style.width = '137px';
				img2.style.height = '89px';
				img2.style.float = 'left';
				img2.style.margin = '1px';
				img2.style.border = 'none';
				link.appendChild(img2);
			break;
		case 'custom_link':
				add_divs(w,h);
				var link = document.createElement('a');
				link.innerHTML = linkText;
				link.setAttribute('href','#');
				link.onclick=function(){
					showSlideshow(w,h,ifrSrc);
					return false;
				};
				cont.appendChild(link);
			break;
	}
}
function showSlideshow(w,h,ifrSrc){
	if(navigator.appName == "Microsoft Internet Explorer"){
		var cw = document.documentElement.clientWidth;
		var ch = document.documentElement.clientHeight;
	}else{
		var cw = window.innerWidth;
		var ch = window.innerHeight;
	}
	bg_div.style.width = cw+'px';
	bg_div.style.height = ch+'px';
	bg_div.style.display = 'block';
	iframe_cont.style.left=parseInt((cw-w)/2)+'px';
	iframe_cont.style.top=parseInt((ch/2)-(h/2)) + 'px';
	iframe_cont.style.display='block';
	make_iframe(w,h,ifrSrc);
	iframe_cont.appendChild(my_iframe);
	bg_div.onclick=function(){
		while (iframe_cont.hasChildNodes()){
			iframe_cont.removeChild(iframe_cont.firstChild);
		}
		bg_div.style.display='none';
		iframe_cont.style.display='none';
	};
	var info_text = document.createElement('div');
	info_text.style.zIndex = '10000';
	info_text.style.color = '#ffffff';
	info_text.style.font = '11px "Lucida Sans","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif';
	info_text.style.textAlign = 'center';
	info_text.style.left = '0';
	info_text.style.width = '100%';
	info_text.innerHTML = 'Click outside the slideshow to close';
	iframe_cont.appendChild(info_text);
}
function add_divs(w,h){
	bg_div = document.createElement('div');
	bg_div.style.position = 'fixed';
	bg_div.style.top = '0';
	bg_div.style.left = '0';
	bg_div.style.backgroundColor = '#000000';
	bg_div.style.opacity = '0.85';
	bg_div.style.filter = 'alpha(opacity=85)';
	bg_div.style.zIndex = '9999';
	bg_div.style.display = 'none';
	cont.appendChild(bg_div);
	iframe_cont = document.createElement('div');
	iframe_cont.style.position = 'fixed';
	iframe_cont.style.width = w;
	iframe_cont.style.height = h;
	iframe_cont.style.zIndex = '10000';
	iframe_cont.style.display = 'none';
	cont.appendChild(iframe_cont);
}
function make_iframe(w,h,ifrSrc){
	my_iframe = document.createElement('iframe');
	my_iframe.setAttribute("width", w);
	my_iframe.setAttribute("height", h);
	my_iframe.setAttribute("frameborder", 0);
	my_iframe.setAttribute("src", ifrSrc);
}
function fadeOp(el, op){
	if(op>el.style.opacity){
		var modif = 0.01;
	}else{
		var modif = -0.01;
	}
	el.style.opacity = parseFloat(el.style.opacity)+modif;
	if(el.style.opacity != op){
		timerID = setTimeout(function(){fadeOp(el, op);}, 10);
	}else{
		return;
	}
}
function hover_tb(el)
{	
	var my_div = el.parentNode.parentNode.getElementsByTagName('a')[0].getElementsByTagName('div')[0];
	clearTimeout(timerID);
	fadeOp(my_div, 1);
}
function unhover_tb(el)
{
	var my_div = el.parentNode.parentNode.getElementsByTagName('a')[0].getElementsByTagName('div')[0];
	clearTimeout(timerID);
	fadeOp(my_div, 0.7);
}
