var Rolling = Class.create(); 
Rolling.prototype ={
	initialize: function(obj){this.lists=$(obj).immediateDescendants();},
	unit: 6,
	i: 0,
	first: 1,
	last: this.unit,
	move:1,
	obj:null,
	lists: null,
	moveTo: function(direction){
				for(var i=0;i < this.lists.length;i++){
	 					if(this.lists[i].className==""){
	 						this.last=i+1;
							this.first=this.last-this.unit;
							this.lists[i].className="hidden";
						}
				}
				
				if(direction=="right"){
					if(this.last>=(this.lists.length)){this.last=0;}
					for(var j=1;j <= this.unit;j++){
						if(this.lists[this.last-1+j]==undefined)break;
						this.lists[this.last-1+j].setStyle({opacity: 0.1});									
						this.lists[this.last-1+j].className="";	
						this.flicker(this.lists[this.last-1+j],1);
					}
				
				}
				else{
					if(this.first<=0){this.first=this.lists.length;}
					for(var j=1;j <= this.unit;j++){
						if(this.lists[this.first-j]==undefined)break;
						this.lists[this.first-j].setStyle({opacity: 0.1});									
						this.lists[this.first-j].className="";	
						this.flicker(this.lists[this.first-j],1);
					}
				}
					
			},
	flicker: 	function (obj,interval){
						obj.style.opacity=0.1;
						var change = $R(1, interval * 10 , false);
							change.each(
							function(value,index){
							setTimeout("changeOpacity('"+obj.id+"','"+value+"')",70*value);
							} 
						);
				} 
}	


var RollingByAjax = Class.create(); 
RollingByAjax.prototype ={
	url:"/video/genre/RelationInstXml.do",
	initialize: function(obj,rightInstid,totalCount,velocityNum,chnlName){
					this.wrapperId=obj;
					this.rightInstid=rightInstid;
					this.totalCount=totalCount;
					this.velocityNum=velocityNum;
					this.chnlName=chnlName;
  				},
	unit: 6,
	test: function(){alert(this.first)},
	i: 0,
	first: 1,
	Html:"",
	last: this.unit,
	move:1,
	obj:null,
	wrapperId:null,
	lists: null,
	rightInstid: null,
	rightInstno: null,
	direction: "prev",
	param: "",
	page: 1,
	velocityNum:0,
	totalCount:0,
	chnlName: "",
	moveTo: function(direction){
 				 	if(direction=='prev'){
						if(this.page==1){return;}
						else if( this.page==2){
							$('btnMoveOthersToLeft_'+this.velocityNum.toString()).style.display='none';
							if(parseInt((this.totalCount -1) / 6  )==1){
							$('btnMoveOthersToRight_'+this.velocityNum.toString()).show();
							}
						}
						else if(parseInt((this.totalCount -1) / 6  )+1 ==  this.page){
							$('btnMoveOthersToRight_'+this.velocityNum.toString()).show();
							
						}
 						this.page--;
					}	
 
					else if(direction=='next'  ){

						if(parseInt((this.totalCount -1) / 6  ) ==  this.page){
							$('btnMoveOthersToRight_'+this.velocityNum.toString()).hide();
							if(parseInt((this.totalCount -1) / 6  )==1){
								$('btnMoveOthersToLeft_'+this.velocityNum.toString()).style.display='block';
							}
						}
						else if(parseInt((this.totalCount -1) / 6  )+1 ==  this.page){
							return;
						}
						else if(this.page>=1){
							$('btnMoveOthersToLeft_'+this.velocityNum.toString()).style.display='none';
							$('btnMoveOthersToLeft_'+this.velocityNum.toString()).style.display='block';
						}						
						this.page++;
					}

					var url = this.url +'?instid='+this.rightInstid+'&page='+this.page; 	
					this.getXmlData(url , this.wrapperId, ""  );   			
			},
	flicker: 	function (obj,interval){
						obj.style.opacity=0.1;
						var change = $R(1, interval * 10 , false);
							change.each(
							function(value,index){
							setTimeout("changeOpacity('"+obj.id+"','"+value+"')",70*value);
							} 
						);
				}, 
	getXmlData: function(url,pars,func ){ 
										tmpId=pars;
									    var myAjax = new Ajax.Request( 
												
									            url, 
									            { 
									                method: 'get', 
									                parameters: pars, 
									                onComplete: this.setXmlData.bind(this)
									            }
										); 
				},
	setXmlData:	function(originalRequest,pars){		
												xmlData = originalRequest.responseXML;
												data = xmlData.getElementsByTagName("ITEM");
												var HTML ="";
												var chnlText = "화";
												if(this.chnlName == "star") {
													chnlText = "경기"
												}
												for(i=0;i<data.length;i++){
														INSTID  		= xmlData.getElementsByTagName("INSTID").item(i).firstChild.data;
														INSTNO 			= xmlData.getElementsByTagName("INSTNO").item(i).firstChild.data;				
														THUMBNAIL  		= xmlData.getElementsByTagName("THUMBNAIL").item(i).firstChild.data;

														HTML		   += '<div  id="stillcut_'+i+'">\
																		<a href="/video/view/InstView.do?instid='+INSTID +'"><img src="'+THUMBNAIL +'" width="73" height="54"/></a>\
																		<span class="othersTitle">'+ INSTNO + chnlText +'</span>\
																		 </div>';
															 
										 
												}
								 				$(tmpId).update(HTML);	
 				}
}						
var changeOpacity = function (obj,p){  $(obj).setStyle({opacity: 0.1 * p});}	

 
//---드래그-----------------------------------------------------------------------------------------------------------------------------
var Draggable = function(element,useClone,onDragOver,onDragOut,onDrop)
									{	
										this.useClone					= useClone | false;
										this.draggableOBJ				= document.getElementById(element);
										this.clone						= null;
										
										this.onDragOver					= onDragOver || function(){};
										this.onDragOut					= onDragOut || function(){};
										this.onDrop						= onDrop  || function(){};
										this.draggableOBJ.style.position= "absolute";// !!!
										this.draggableOBJ.style.zIndex = 20000;
										this.draggableOBJ.style.cursor  = "move";
										this.top						= null;
										this.left						= null;
										this.pointerTop					= null;  
										this.pointerLeft				= null;
  										this.draggableOBJ.onmousedown	= this.onMouseDown.bindAsEventListener(this);
 										this.draggableOBJonselectstart  = function(){alert('adsf');}
										this.draggableOBJ.ondragstart	= function(){return false;};
										this.inDropzone					= false;
										this.currentDropzone			= null;
										window.document.body.onunload   = this.preventIELeak.bindAsEventListener(this);

									}

Draggable.prototype={
	preventIELeak	:	function(){this.draggableOBJ=null; },
	onMouseDown :	function(event) 
									{ 
										if(this.useClone){
											this.clone						= this.draggableOBJ.cloneNode(true);
											document.body.appendChild(this.clone); 
											this.clone.style.top			=this.draggableOBJ.offsetTop+'px'; 
											this.clone.style.left			=this.draggableOBJ.offsetLeft+'px'; 
											this.clone.style.position		="absolute";
											this.draggableOBJ.style.zIndex = 20000;
											this.clone.style.filter="Alpha(opacity=30)" 
											this.clone.style.opacity="0.3";
										}
										window.document.body.onmouseup			= this.onMouseUp.bindAsEventListener(this);	
										event.preventDefault?event.preventDefault():event.returnValue=false;
										this.top						= this.draggableOBJ.offsetTop; 
										this.left						= this.draggableOBJ.offsetLeft; 
										this.pointerTop					= event.clientX; 
										this.pointerLeft				= event.clientY;
										event.stopPropagation? event.stopPropagation():event.cancelBubble = true; 
										
										window.document.body.onmousemove= this.onMouseMove.bindAsEventListener(this); 
										
	}, 
	onMouseMove	:	function(event)
									{
										var x_							= event.clientX - this.pointerTop;
									 	var y_							= event.clientY - this.pointerLeft;									
										this.draggableOBJ.style.top	= this.top + y_ +"px";
									 	this.draggableOBJ.style.left= this.left + x_  +"px";
										event.stopPropagation? event.stopPropagation():event.cancelBubble = true; 
 
	}, 
				
	onMouseUp	:	function(event)
									{
										window.document.body.onmouseup	= null;
										window.document.body.onmousemove= null;
									} 
}


var FloatingLayer =   function(){
							this.obj			= arguments[0];				
							this.isDraggable 	= arguments[1] || false;
							this.useBackground 	= arguments[2] || false;
							if(this.isDraggable){
								new Draggable(this.obj,false,"","","");
							}
} 
FloatingLayer.prototype ={

	obj	  : null,
	isOpen: false,
	isDraggable: false,
	useBackground: false,
	bglIframe: null,
	bglObj: null,
	func: null,
	open: function(){
					if(!this.isOpen){
						this.func=this.esc.bindAsEventListener(this);
						Event.observe(document, 'keyup', this.func); 
						if(this.useBackground){
							
							if(this.bglObj==null){
								var obj = document.getElementsByTagName("body");
								this.bglIframe = document.createElement('iframe');
								this.bglObj = document.createElement('div');
	 							obj[0].appendChild(this.bglIframe);
								obj[0].appendChild(this.bglObj);
								$(this.bglObj).setStyle({opacity: 0.8, 
													 height:document.body.scrollHeight +100+ 'px',
													 width : document.body.scrollWidth + 'px',
													 zIndex:10001,
													 top:0,
													 left:0,
													 backgroundColor:'#000000',
			 										 position:'absolute'
													}).show();	
								$(this.bglIframe).setStyle({opacity: 0 , 
													 height:document.body.scrollHeight +100+ 'px',
													 width : document.body.scrollWidth + 'px',
													 zIndex:10000,
													 top:0,
													 left:0,
 			 										 position:'absolute'
													}).show();																	
							}
							else{
								$(this.bglObj).show()
								$(this.bglIframe).show()

							}
						}
						$(this.obj).setStyle({opacity: 1, 
	 													 top:window.screen.height / 2 - (380) + 'px',
														 left:document.body.clientWidth / 2 - (641/2) + 'px',
	  													 position:'absolute',
														 display:'block'
													}) 		
						this.isOpen = true;
					}
	},
	close: function(){
						//$("backgroundLayer").hide()
						$(this.obj).hide()
						if(this.useBackground){
							$(this.bglObj).hide()
							$(this.bglIframe).hide()
						}
						this.isOpen = false;
	 					Event.stopObserving(document, 'keyup', this.func); 
	
	},
	esc: function(event){
  			if(event.keyCode=="27")	this.close();
	}	
} 

var FloatingLayer4stillcut = function(){ FloatingLayer.apply(this,arguments); }
FloatingLayer4stillcut.prototype = new FloatingLayer();
FloatingLayer4stillcut.prototype.open = function(){
	try { 	
		$("stillcutView_imageList").update($("stillcutContainer").innerHTML);
		$('stillcutViewer_imageSrc').src=arguments[0].href;
	} catch(e) {
		alert(e);
		return false;
	}
	FloatingLayer.prototype.open.apply(this,arguments);
}

var FloatingLayer4sample = function(){ FloatingLayer.apply(this,arguments); }
FloatingLayer4sample.prototype = new FloatingLayer();
FloatingLayer4sample.prototype.open = function(){
	try { 	
		//$("sampleMovie").start();
		$("wmp").innerHTML='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95 id="sampleMovie" width="210" height="188" >\
							<param name="Filename" value="http://daum-disney.nefficient.co.kr/disney/sample.wmv" />\
							<embed src="http://daum-disney.nefficient.co.kr/disney/sample.wmv" width="210" height="188" autostart="true" />\
							</object>';			
	} catch(e) {
		alert(e);
		return false;
	}
	FloatingLayer.prototype.open.apply(this,arguments);
}
FloatingLayer4sample.prototype.close = function(){
	try { 	
		$("wmp").innerHTML=''

	} catch(e) {
		alert(e);
		return false;
	}
	FloatingLayer.prototype.close.apply(this,arguments);
}
