var W = 0, H = 0;
var sBTop=0,sBLeft=0,cBTop=0,cBLeft=0;
var sBW=0,sBH=0,cBW=14,cBH=14;
var wB_vS='',wB_hS='',sB_vS='',sB_hS='',cB_vS='',cB_hS='';

window.onload = function(){
	slider("CGNNews","up",10000,10);
//	slider("news_area","down",5000,10);
}
/////////////////////////////yukarı aşağı
function slider(id, way,bigInterval,smallInterval){
	if(!document.getElementById(id)) return;
	var head = Array();var temp = document.getElementById(id);
	for(var i = 0;i<temp.childNodes.length;i++){
		if(temp.childNodes.item(i).id){head.push(temp.childNodes.item(i).id);}
	}
	
	if(way=="up"){ 		setTimeout(function(){ rollUp(head,bigInterval,smallInterval,0)},bigInterval);}
	if(way=="down"){ 	setTimeout(function(){ rollDown(head,bigInterval,smallInterval,0)},bigInterval);}
	if(way=="left"){ 	setTimeout(function(){ rollLeft(head,bigInterval,smallInterval,0)},bigInterval);}
	if(way=="right"){ 	setTimeout(function(){ rollRight(head,bigInterval,smallInterval,0)},bigInterval);}
}


function rollUp(head,bigInterval,smallInterval,visible){
	if(head.length==0 || head.length==1) return;
	var v2 = (visible+1)% head.length;
	toTopMoveUp(visible,v2,head,140,0,270,smallInterval);
	setTimeout(function(){ rollUp(head,bigInterval,smallInterval,v2)},bigInterval);
}

function toTopMoveUp(v1_id,v2_id,head,went,now,last,smallInterval){
	if(now>went){
		document.getElementById(head[v1_id]+"").style.cssText="top: "+last+"px; width:250;height:140;position: absolute;";
	}else{
		document.getElementById(head[v1_id]+"").style.cssText="top: "+(now* -1)+"px;width:250;height:140; position: absolute;";
		document.getElementById(head[v2_id]+"").style.cssText="top: "+(140-now)+"px;width:250;height:140; position: absolute;";
		now += 5;
		setTimeout(function(){ toTopMoveUp(v1_id,v2_id,head,went,now,last,smallInterval)},smallInterval);
	}
}

function rollDown(head,bigInterval,smallInterval,visible){
	if(head.length==0 || head.length==1) return;
		var v2 = (visible+1)% head.length;
	toTopMoveDown(visible,v2,head,0,140,270,smallInterval);
	setTimeout(function(){ rollDown(head,bigInterval,smallInterval,v2)},bigInterval);
}

function toTopMoveDown(v1_id,v2_id,head,went,now,last,smallInterval){
	if(now<went){
		document.getElementById(head[v1_id]+"").style.cssText="top: "+last+"px;width:250;height:140; position: absolute;";
	}else{
		document.getElementById(head[v1_id]+"").style.cssText="top: "+(140-now)+"px;width:250;height:140; position: absolute;";
		document.getElementById(head[v2_id]+"").style.cssText="top: "+(-1 * now)+"pxwidth:250;height:140;; position: absolute;";
		now -= 5;
		setTimeout(function(){ toTopMoveDown(v1_id,v2_id,head,went,now,last,smallInterval)},smallInterval);
	}
}

function rollLeft(head,bigInterval,smallInterval,visible){
	if(head.length==0 || head.length==1) return;
	var v2 = (visible+1)% head.length;
	toLeftMoveLeft(visible,v2,head,0,270,270,smallInterval);
	setTimeout(function(){ rollLeft(head,bigInterval,smallInterval,v2)},bigInterval);
}

function toLeftMoveLeft(v1_id,v2_id,head,went,now,last,smallInterval){
	if(now<went){
		document.getElementById(head[v1_id]+"").style.cssText="left: "+last+"px;width:250;height:140; position: absolute;";
	}else{
		document.getElementById(head[v1_id]+"").style.cssText="left: "+(-1 * (270-now))+"px;width:250;height:140; position: absolute;";
		document.getElementById(head[v2_id]+"").style.cssText="left: "+(now)+"px;width:250;height:140; position: absolute;";
		now -= 5;
		setTimeout(function(){ toLeftMoveLeft(v1_id,v2_id,head,went,now,last,smallInterval)},smallInterval);
	}
}

function rollRight(head,bigInterval,smallInterval,visible){
	if(head.length==0 || head.length==1) return;
	var v2 = (visible+1)% head.length;
	toLeftMoveRight(visible,v2,head,270,0,270,smallInterval);
	setTimeout(function(){ rollRight(head,bigInterval,smallInterval,v2)},bigInterval);
}

function toLeftMoveRight(v1_id,v2_id,head,went,now,last,smallInterval){
	if(now>went){
		document.getElementById(head[v1_id]+"").style.cssText="left: "+last+"px;width:250;height:140; position:absolute;";
	}else{
		document.getElementById(head[v1_id]+"").style.cssText="left: "+(now)+"pxwidth:250;height:140;; position: absolute;";
		document.getElementById(head[v2_id]+"").style.cssText="left: "+((-1*270)+(now))+"px;width:250;height:140; position: absolute;";
		now += 5;
		setTimeout(function(){ toLeftMoveRight(v1_id,v2_id,head,went,now,last,smallInterval)},smallInterval);
	}
}

function startAnket(){
	var xmlObject = getXmlHttp();
	if(xmlObject==false){return;}
	xmlObject.onreadystatechange = function(){
		if (xmlObject.readyState == 4) {
			var retVal = xmlObject.responseText;
			document.getElementById("left_poll_area").innerHTML=retVal;
		}
	};
	xmlObject.open('POST', "php/getPoll.php", true);
	xmlObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlObject.setRequestHeader("Content-length", 5);
	xmlObject.setRequestHeader("Connection", "close");
	xmlObject.send("id=-1");
}


