﻿var varpag = 0;
contentWin = null;
 var out ="";

Ajax.Eval = Class.create();
Object.extend(Object.extend(Ajax.Eval.prototype, Ajax.Request.prototype), {
  initialize: function(url, pars) {
    this.transport = Ajax.getTransport();
    this.setOptions({method:'post', parameters:pars});
    this.options.onComplete = (function(transport) {
      eval(transport.responseText);
    });
    this.request(url);
  }
});


// JavaScript Document
function setVideo(idvideo) {
/*	var vurl = idvideo;
	var vswf = new SWFObject(vurl, "id2", "350", "300", "8", "#FFFFFF");
	vswf.addParam("menu", "false");
	vswf.addParam("wmode", "transparent");
	vswf.addParam("quality", "high");
	vswf.addVariable('autostart','true');
	
	
	vswf.write("swfvideo");*/
	if (contentWin != null) {
contentWin.destroy();
}
loadwindow("video.php?video=" + idvideo );	


}
function getId(nameid) {
	return document.getElementById(nameid);
}
function getData() {
	getId('loadData').style.visibility = "visible";
	dsYouTube.setURL(varurl+"?tag="+vartag+"&pag="+varpag);
	dsYouTube.loadData();
}
function setText(varId, varText) {
	getId(varId).innerText = varText;
	getId(varId).textContent = varText;
}
function getVideo() {
	//varpag = 0;
	vartag = getId("criterio").value;
	
	//vartag = vartag.replace(" ", "-");
	setText("query", vartag);

	submitload('youtube-data.php?page='+ varpag + '&src='+ vartag , 'youtube');
}
function pagVideo(pagStep) {

	if (varpag > 0 || pagStep > 0) {
		varpag = varpag + pagStep;
		curpag=getId("pagnum").innerText;
		//alert(curpag);
		setText("pagnum",  parseInt(curpag) + pagStep);
		vartag = getId("criterio").value;
		//vartag = YAHOO.widget.Tab;
//	alert('youtube-data.php?page='+ varpag + '&src='+ vartag);
		submitload('youtube-data.php?page='+ varpag + '&src='+ vartag, 'youtube');
	}
}
function submitload(_URL,target)
 {


new Ajax.Request( _URL, { 
method: 'get',asynchronous: false, evalScripts: true,onComplete: function(transport){ 


	var newData = transport.responseText;
	$(target).innerHTML = newData;
    
   
     
    
	}});
	


    

 
}

function llamarasincrono (url, id_contenedor)
{
    var pagina_requerida = false;
    if (window.XMLHttpRequest)
    {
        // Si es Mozilla, Safari etc
        pagina_requerida = new XMLHttpRequest ();
    } else if (window.ActiveXObject)
    {
        // pero si es IE
        try 
        {
            pagina_requerida = new ActiveXObject ("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            // en caso que sea una versin antigua
            try
            {
                pagina_requerida = new ActiveXObject ("Microsoft.XMLHTTP");
            }
            catch (e)
            {
            }
        }
    } 
    else
    return false;
    	 getId('loadData').style.visibility = "visible";
	
   
    pagina_requerida.onreadystatechange = function ()
    {
        // funcin de respuesta
        cargarpagina (pagina_requerida, id_contenedor);
    }
    pagina_requerida.open ('GET', url, true); // asignamos los mtodos open y send
    pagina_requerida.send (null);
     
}
// todo es correcto y ha llegado el momento de poner la informacin requerida
// en su sitio en la pagina xhtml
function cargarpagina (pagina_requerida, id_contenedor)
{
    if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == - 1))
    document.getElementById (id_contenedor).innerHTML = pagina_requerida.responseText;
    //  eval(document.getElementById(id_contenedor).innerHTML);
    
    if (pagina_requerida.readyState==2)
  {
  getId('loadData').style.visibility = "hidden";
  }
   
}

function loadwindow (url)
{
var _ancho = (window.innerWidth)? window.innerWidth : document.body.clientWidth;
var _alto = (window.innerHeight)? window.innerHeight : document.body.clientHeight;
//alert(_ancho);
if(_ancho > 1024)
{
myancho=_ancho - 400;	
}else{
myancho=_ancho - 100;	
}

		
var win = new Window({className: "darkX", title: url, 
                      top:130, left: 10, width: myancho, height:_alto  -(_alto )/8, 
                      url: url,destroyOnClose: true})
win.showCenter(true,130);  		

}









function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function hideLightbox()
{

	objLightbox.style.display = 'none';
	objOverlay.style.display = 'none';
	objLightbox.innerHTML = "";
	hideconfbox();
}

function hideconfbox()
{
	
	objLightbox2.style.display = 'none';
	objLightbox2.innerHTML = "";
	
		
}






function playVideo(id,loader,title,clearer){

	var video = document.getElementById('video');
	var overlay = document.getElementById('overlay');
	if(loader){
		if(clearer)
			clearList('ul1');
		video.innerHTML = '<div style="text-align: center; font-size: 120%;"><img src="load.gif"><br />loading videos...</div>';
		height= 80;
		width = 220;
	}else{
		
		video.innerHTML = '<div style="text-align: right; font-size: 120%;">'+title.substr(0,60)+'  <img src="images/close.gif" onclick="hideLightbox()"><br/><object width="510" height="420"><param name="movie" value="'+id+'"></param><param name="autoplay" value="1"><param name="wmode" value="transparent"></param><embed src="'+id+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="510" height="420"></embed></object></div>';
		height= 420;
		width = 510;
	}

	//if(firsttime){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
	
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 60 - width) / 2);
			
		video.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		video.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

		overlay.style.height = (arrayPageSize[1] + 'px');
		overlay.style.display = 'block';
	//}
	video.style.display = "block";

}



function show_vimeo(num){

	var video = document.getElementById('video');
	var overlay = document.getElementById('overlay');
	
new Ajax.Request("vimeo.php?video=" + num, { 
method: 'get',asynchronous: true, evalScripts: true,onComplete: function(transport){ 


	var response = transport.responseText ;
	//alert(response);
    
   
     
		video.innerHTML = response;
		height= 420;
		width = 510;
	
	//if(firsttime){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
	
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 60 - width) / 2);
			
		video.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		video.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

		overlay.style.height = (arrayPageSize[1] + 'px');
		overlay.style.display = 'block';
	//}
	video.style.display = "block";
	}});
}





function startdrag() {

var Dom = YAHOO.util.Dom;
var Event = YAHOO.util.Event;
var DDM = YAHOO.util.DragDropMgr;

//////////////////////////////////////////////////////////////////////////////
// example app
//////////////////////////////////////////////////////////////////////////////
YAHOO.example.DDApp = {
    init: function() {

        var rows=3,cols=2,i,j;
        for (i=1;i<cols+1;i=i+1) {
            new YAHOO.util.DDTarget("per"+i);
        }
		/*
        for (i=1;i<cols+1;i=i+1) {
            for (j=1;j<rows+1;j=j+1) {
                new YAHOO.example.DDList("li" + i + "_" + j);
            }
        }*/
		// new YAHOO.example.DDList("Latestnews");
		// new YAHOO.example.DDList("Features");
		 //new YAHOO.example.DDList("Videos");
		// new YAHOO.example.DDList("Interviews");
		// new YAHOO.example.DDList("Podcasts");
		 


        Event.on("showButton", "click", this.showOrder);
       
    },

    showOrder: function() {
        var parseList = function(ul,ul2,ul3) {
            var items = ul.getElementsByTagName("li");
             var items2 = ul2.getElementsByTagName("li");
             var items3 = ul3.getElementsByTagName("li");
           
            for (i=0;i<items.length;i=i+1) {
                out += "left" +  "," + items[i].id + "/";
                if(items2[i]!=undefined)
                {
                out += "right" +  "," + items2[i].id + "/";
                }
            }
           if(items2.length > items.length)
           {
            for (i=items.length;i<items2.length;i=i+1) {
                out += "right" +  "," + items2[i].id + "/";
                
            
            }
           }
           
           
            for (i=0;i<items3.length;i=i+1) {
                out += "per" +  "," + items3[i].id + "/";
                
            }
            
            return out;
        };

        var ul1=Dom.get("per1"), ul2=Dom.get("per2");ul3=Dom.get("per3");
        
         var out ="order=";
        parseList(ul1,ul2,ul3);
        submitload("save.php?" + out, "misc");
        var newWindow = window.open('index.php?dummy=' + new Date().getTime(), '_self');

    },

    switchStyles: function() {
        Dom.get("pers1").className = "draglist_alt";
        Dom.get("pers22").className = "draglist_alt";
    }
};

//////////////////////////////////////////////////////////////////////////////
// custom drag and drop implementation
//////////////////////////////////////////////////////////////////////////////

YAHOO.example.DDList = function(id, sGroup, config) {

    YAHOO.example.DDList.superclass.constructor.call(this, id, sGroup, config);

    this.logger = this.logger || YAHOO;
    var el = this.getDragEl();
    Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent

    this.goingUp = false;
    this.lastY = 0;
};

YAHOO.extend(YAHOO.example.DDList, YAHOO.util.DDProxy, {

    startDrag: function(x, y) {
        this.logger.log(this.id + " startDrag");

        // make the proxy look like the source element
        var dragEl = this.getDragEl();
        var clickEl = this.getEl();
        Dom.setStyle(clickEl, "visibility", "hidden");

        dragEl.innerHTML = clickEl.innerHTML;

        Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
        Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
        Dom.setStyle(dragEl, "border", "2px solid gray");
    },

    endDrag: function(e) {

        var srcEl = this.getEl();
        var proxy = this.getDragEl();

        // Show the proxy element and animate it to the src element's location
        Dom.setStyle(proxy, "visibility", "");
        var a = new YAHOO.util.Motion( 
            proxy, { 
                points: { 
                    to: Dom.getXY(srcEl)
                }
            }, 
            0.2, 
            YAHOO.util.Easing.easeOut 
        )
        var proxyid = proxy.id;
        var thisid = this.id;

        // Hide the proxy and show the source element when finished with the animation
        a.onComplete.subscribe(function() {
                Dom.setStyle(proxyid, "visibility", "hidden");
                Dom.setStyle(thisid, "visibility", "");
            });
        a.animate();
    },

    onDragDrop: function(e, id) {

        // If there is one drop interaction, the li was dropped either on the list,
        // or it was dropped on the current location of the source element.
        if (DDM.interactionInfo.drop.length === 1) {

            // The position of the cursor at the time of the drop (YAHOO.util.Point)
            var pt = DDM.interactionInfo.point; 

            // The region occupied by the source element at the time of the drop
            var region = DDM.interactionInfo.sourceRegion; 

            // Check to see if we are over the source element's location.  We will
            // append to the bottom of the list once we are sure it was a drop in
            // the negative space (the area of the list without any list items)
            if (!region.intersect(pt)) {
                var destEl = Dom.get(id);
                var destDD = DDM.getDDById(id);
                destEl.appendChild(this.getEl());
                destDD.isEmpty = false;
                DDM.refreshCache();
            }

        }
    },

    onDrag: function(e) {

        // Keep track of the direction of the drag for use during onDragOver
        var y = Event.getPageY(e);

        if (y < this.lastY) {
            this.goingUp = true;
        } else if (y > this.lastY) {
            this.goingUp = false;
        }

        this.lastY = y;
    },

    onDragOver: function(e, id) {
    
        var srcEl = this.getEl();
        var destEl = Dom.get(id);

        // We are only concerned with list items, we ignore the dragover
        // notifications for the list.
        if (destEl.nodeName.toLowerCase() == "li") {
            var orig_p = srcEl.parentNode;
            var p = destEl.parentNode;

            if (this.goingUp) {
                p.insertBefore(srcEl, destEl); // insert above
            } else {
                p.insertBefore(srcEl, destEl.nextSibling); // insert below
            }

            DDM.refreshCache();
        }
    }
});

Event.onDOMReady(YAHOO.example.DDApp.init, YAHOO.example.DDApp, true);

}








function pressPlay()
{
}


function confBox(_URL){

	var video = document.getElementById('conf-box');
	var overlay = document.getElementById('overlay');
	//video.innerHTML = '<div style="text-align: right; font-size: 120%;">aml  <img src="images/close.gif" onclick="hideLightbox()"><br/><object width="510" height="420"><param name="movie" value="http://www.youtube.com/v/RWT1qOypLvM"></param><param name="autoplay" value="1"><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/RWT1qOypLvM&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="510" height="420"></embed></object></div>';
		 new Ajax.Updater(video, _URL, { 
method: 'get',asynchronous: false, evalScripts: true});
		
	
	height= 820;
		width = 510;


	//if(firsttime){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
	
		
		
			var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2) ;
	var lightboxLeft = ((arrayPageSize[0] - 60 - width) / 2);
			
		video.style.top = (lightboxTop < 200) ? "200px" : lightboxTop + "px";
		video.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

		overlay.style.height = (arrayPageSize[1] + 'px');
		overlay.style.display = 'block';
	//}
	video.style.display = "block";
	

		
	
}




function send_form(ser){
//serial= $(ser).serialize(true);
//alert(dest);

//_URL=$(ser).action;

//alert($(ser).value);

new Ajax.Request("addper.php?sqr=" + $(ser).value ,{ asynchronous: false,
  onComplete: function(transport){ 
	
	var response = transport.responseText ;
	
  // alert(response);

 
	}});





}