var template_url = '/comics-unleashed/wp-content/themes/comics-unleashed/';
var pag = 0;
function play(video,img,add){
	var s0 = new SWFObject(template_url + "player/DemoPlayer3.swf","ply","425","342","8","#000000");
	s0.addParam("allowfullscreen","true");
	s0.addParam("allowscriptaccess","always");
	s0.addParam("flashvars","addid=" + add + "&img=" + img + "&streamer=rtmp://entstudios.fcod.llnwd.net/a973/o25/flv/" + video);
	s0.write("player");
}

function video(id,catid,video,image,add){
	function whenLoading(){
		e = document.getElementById(results_div);
		e.innerHTML = '<div class="cargando"></div>';
	}
	function whenCompleted(){
		play(video,image,add);
	}
	var results_div = 'video';
	var mysack = new sack(template_url + "video.php" );
	mysack.method = 'POST';
	mysack.setVar( "id", id );
	mysack.setVar( "catid", catid );
	mysack.onLoading = whenLoading;
	mysack.onCompletion = whenCompleted;
	mysack.element = results_div;
	mysack.runAJAX();
	return false;
}

function videos(){
	function whenLoading(){
		e = document.getElementById(results_div);
		e.innerHTML = '<div class="cargando"></div>';
	}
	var results_div = 'videos';
	var mysack = new sack(template_url + "videos.php" );
	mysack.method = 'POST';
	mysack.setVar( "pag", pag );
	mysack.onLoading = whenLoading;
	mysack.element = results_div;
	mysack.runAJAX();
	return false;
}

function videos_anterior(){
	pag--;
	return videos();
}

function videos_siguiente(){
	pag++;
	return videos();
}

function tmDisplayBanner(banners, divName, width, height, defaultSize) {
	if (!defaultSize) defaultSize = "300x250";
	var size = width + 'x' + height;
	var adDiv = document.getElementById(divName);
	
	// Loop through all the banners
	for (var i in banners) {
		var banner = banners[i];
		// Find the correct sized one
		var bannerSize = banner.size ? banner.size : banner._size;
		if ((bannerSize == null) || (bannerSize == "undefinedxundefined") || (bannerSize == "NaNxNaN"))
			bannerSize = defaultSize;
		if (bannerSize == size) {
			// Remove old ads
			var old_iframe = document.getElementById("acudeo_iframe");
			if (old_iframe) {
				adDiv.removeChild(old_iframe);
			}
			var old_span = document.getElementById("acudeo_span");
			if (old_span) {
				adDiv.removeChild(old_span);
			}
			var old_a = document.getElementById("acudeo_a");
			if (old_a) {
				adDiv.removeChild(old_a);
			}
			
			// If there is a iframe, use it
			var htmlUrl = banner.htmlUrl ? banner.htmlUrl : banner._htmlUrl;
			var swfUrl = banner.swfUrl ? banner.swfUrl : banner._swfUrl;
			var imageUrl = banner.imageUrl ? banner.imageUrl : banner._imageUrl;
			var clickUrl = banner.clickUrl ? banner.clickUrl : banner._clickUrl;
			if (htmlUrl) {
				// Create the iframe
				var iframe = document.createElement("iframe");
				iframe.setAttribute("id", "acudeo_iframe");
				iframe.style.width = width + "px";
				iframe.style.height = height + "px";
				iframe.style.border = "0";
				iframe.scrolling = "no";
				iframe.marginWidth = "0";
				iframe.marginHeight = "0";        
				iframe.frameBorder = "no";
				adDiv.appendChild(iframe);
				
				// IE has a weird caching issue, so we have to append the 
				// iframe, then set the src
				var new_iframe = document.getElementById("acudeo_iframe");
				new_iframe.src = htmlUrl;
				new_iframe.frameborder = "no";
				
			// Otherwise if there is a SWF URL, use that
			} else if (swfUrl) {
				// Get the object HTML
				var objHtml = '<object';
				objHtml += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height+ '" id="acudeo_swf">';
				objHtml += '<param name="movie" value="' + swfUrl + '" />';
				objHtml += '<param name="quality" value="high" />';
				objHtml += '<param name="wmode" value="transparent" />';
				objHtml += '<param name="allowfullscreen" value="true" />';
				objHtml += '<param name="allowscriptaccess" value="always" />';
				objHtml += '<!--[if !IE]>-->';
				objHtml += '<object type="application/x-shockwave-flash" data="' + swfUrl + '" width="' + width + '" height="' + height + '" id="acudeo_swf">';
				objHtml += '<param name="quality" value="high" />';
				objHtml += '<param name="wmode" value="transparent" />';
				objHtml += '<param name="allowfullscreen" value="true" />';
				objHtml += '<param name="allowscriptaccess" value="always" />';
				objHtml += '<!--<![endif]-->';
				objHtml += '<a href="http://www.adobe.com/go/getflashplayer">';
				objHtml += '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />';
				objHtml += '</a>';
				objHtml += '<!--[if !IE]>-->';
				objHtml += '</object>';
				objHtml += '<!--<![endif]-->';
				objHtml += '</object>';
		
				// Create a span to hold the
				var span = document.createElement("span");
				span.setAttribute("id", "acudeo_span");
				
				// Append the span and set the HTML
				if (navigator.appName.indexOf("Microsoft") != -1) {
					adDiv.appendChild(span);
					var span = document.getElementById("acudeo_span");
					span.outerHTML = objHtml;
				} else {
					span.innerHTML = objHtml;
					adDiv.appendChild(span);
				}
				
			// Otherwise if there is an image, use that
			} else if (imageUrl) {
				// Create the anchor tag
				var a = document.createElement("a");
				a.setAttribute("href", clickUrl);
				a.setAttribute("target", "_blank");
				a.setAttribute("id", "acudeo_a");
				
				// Create the image tag
				var img = document.createElement("img");
				img.setAttribute("src", imageUrl);
				img.setAttribute("border", 0);
				img.setAttribute("width", width);
				img.setAttribute("height", height);
				a.appendChild(img);
				
				// Add the tag
				adDiv.appendChild(a);
      		}
		}
	}
}


function displayCompanionBanners(banners) {
     document.getElementById("adDiv2").style["display"] = "";
	 tmDisplayBanner(banners, "adDiv2", 300, 250);
}
function hideCompanionBanners() {
     document.getElementById("adDiv2").style["display"] = "none";
}

