/** * (c) 2008, Wacko-Wacko!
 * @author daclip * @include "./WItemObject.js" * @include "./WImageObject.js"
 */
function WSlideBox() {	var trash = null;	var __classptr = this;	var self = null;	var innerSelf = null;	var items = Array();	var itemsCount = -1;		var collections = Array();	var current_collection_id = 0;	var browserHolder = null;	var navigationHolder = null;	var navi_header = null;	var navi_left = null;	var navi_right = null;	var leftControl = false;	var rightControl = false;	var leftControlPtr = null;	var rightControlPtr = null;		/* slide timer vars */	var timer = null;	var currentShiftValue = 0;	var _timerSpeed = 1;	var slideStep = 450;	var scrollStep = 10;	var maxValue = 10000;	var currentSlide = 1;		/* some hacks */	var drawByOne = true;	var active = false;	/* useful stuff */	this.getSelf = function() { return self; }	this.drawByOne = function() { drawByOne = true; }	this.drawOnlyAll = function() { drawByOne = false; }		/* public */	this.setCollection = function(id) {		current_collection_id = id;		set_collection();	}	this.addCollection = function(caption, id, param, sid, sparam, collection_callback) {		add_collection(create_collection_object(caption, id, param, sid, sparam, collection_callback));	}		this.prevCollection = function() {		current_collection_id--;		set_collection();	}		this.nextCollection = function() {		current_collection_id++;		set_collection();	}		this.setNavigationParent = function(object_ptr) {		navigationHolder = object_ptr;		navigationHolder.appendChild(create_navigation(this, 0));	}		this.setBrowserParent = function(object_ptr) {		browserHolder = object_ptr;		browserHolder.appendChild(self);	}				this.add = function(/* WItemObject */ ItemObject) {		add_item(ItemObject);	}			this.draw = function() { draw_all(); }	this.clear = function() { clear_all(); }	this.slideRight = function(n) { this.processSlideRight(n);  }	this.slideLeft = function(n) { this.processSlideLeft(n); }		/* need it */	var checkLeftControl = function() {		if (leftControl == false) {			self.removeChild(rightControlPtr);			self.appendChild(leftControlPtr);			self.appendChild(rightControlPtr);			leftControl = true;		}		if (currentShiftValue <= 0 ) {			self.removeChild(leftControlPtr);			leftControl = false;		}	}		/* slide effect processing */	this.processSlideRight = function(n) {		var __backref = this;		active = true;		var max = (slideStep*currentSlide);		if (n != null) max = n;				if ((currentShiftValue+=scrollStep) >= max) {			clearTimeout(timer);			currentShiftValue=slideStep*currentSlide;			currentSlide++;			checkLeftControl();			currentShiftValue = max;			active = false;			scrollStep=10;			slideStep=450;			return false;		}		set_slidebox_position(currentShiftValue);		timer = setTimeout(function() { __backref.processSlideRight(n); }, _timerSpeed);	}		this.processSlideLeft = function(n) {		var __backref = this;		active = true;		if (currentShiftValue <= -1) {			clearTimeout(timer);			currentShiftValue = 0;			checkLeftControl();			active = false;			scrollStep=10;			slideStep=450;			return false;		}		var max = (slideStep*currentSlide-(slideStep*2));		if (n != null) max = n;		if ((currentShiftValue-=scrollStep) <= max) {			clearTimeout(timer);			currentSlide--;			active = false;			scrollStep=10;			slideStep=450;			return false;		}		set_slidebox_position(currentShiftValue);		timer = setTimeout(function() { __backref.processSlideLeft(n); }, _timerSpeed);	}		/* private */	var set_collection = function() {		currentShiftValue=0;		currentSlide=1;				if (collections[current_collection_id-1] != null) {			set_navi_prev(collections[current_collection_id-1].name, __classptr);		} else {			remove_navi_prev();		}				if (collections[current_collection_id+1] != null) {			set_navi_next(collections[current_collection_id+1].name, __classptr);					} else {			remove_navi_next();		}				var c = collections[current_collection_id];		set_navi_header(c.name);//		if (c.callback && c.id != null)//			c.callback(c.id, c.param, c.sid, c.sparam);//		window.location.href="/ru/projects/"+c.id+"/";					return true;	}		var create_collection_object = function(name, id, param, sid, sparam, callback) {		return {			name: name,			id: id,			param: param,			sid: sid,			sparam: sparam,			callback: callback		};	}		var add_collection = function(collection_object) {		collections.push(collection_object);	}		var set_slidebox_position = function(value) {		self.scrollLeft = value;	}		var draw_all = function() {//		self.appendChild(create_facture("left"));//		self.appendChild(create_facture("right"));		leftControlPtr = create_control_l();		rightControlPtr = create_control_r();		self.appendChild(rightControlPtr);		set_slidebox_position(0);			}	var create_control_l = function() {		var obj = document.createElement("div");		obj.setAttribute("style", "float: left");		obj.style.styleFloat ="left";		obj.className = "Control";		obj.innerHTML ="&larr;"		obj.backptr = __classptr;		obj.style.left = "20px";		obj.onclick = function() {			this.backptr.processSlideLeft();		}		return obj;	}	var create_control_r = function() {		var obj = document.createElement("div");		obj.setAttribute("style", "float: right");		obj.style.styleFloat ="right";		obj.className = "Control";		obj.innerHTML ="&rarr;"		obj.backptr = __classptr;		obj.style.right = "20px";		obj.onclick = function() {			this.backptr.processSlideRight();		}		return obj;	}	var create_facture = function(type) {		var obj = document.createElement("img");		obj.className = "Facture";		if (type == "left") {			obj.src = "/img/left_z.png";			obj.style.left = "0px";		}		else {			obj.src = "/img/right_z.png";			obj.style.right = "-15px";		}				return obj;		}			var create_self = function() {		return document.getElementById("WSB");	}		var create_innerself = function() {		return document.getElementById("WIS");	}	var create_navigation_link = function(caption, pre_html, post_html, link_callback, id) {		var link = document.createElement("a");		link.href = "/ru/projects/"+id+"/";		link.onclick = function() { link_callback(); };		if (pre_html) {			var span = document.createElement("span");			span.innerHTML = pre_html;			link.appendChild(span);		}		link.appendChild(document.createTextNode(caption));		if (post_html) {			var span = document.createElement("span");			span.innerHTML = post_html;			link.appendChild(span);		}				return link;		}		var remove_navi_prev = function() {		if (navi_left.firstChild != null) navi_left.removeChild(navi_left.firstChild);	}	var remove_navi_next = function() {		if (navi_right.firstChild != null) navi_right.removeChild(navi_right.firstChild);			}	var set_navi_prev = function(caption, back_ptr) {		if (navi_left.firstChild != null) navi_left.removeChild(navi_left.firstChild);		navi_left.appendChild(create_naviprev(caption, back_ptr, current_collection_id-1));		return true;	}	var set_navi_next = function(caption, back_ptr) {		if (navi_right.firstChild != null) navi_right.removeChild(navi_right.firstChild);		navi_right.appendChild(create_navinext(caption, back_ptr, current_collection_id+1));		return true;	}	var set_navi_header = function(caption, back_ptr) {		navi_header.removeChild(navi_header.firstChild);		navi_header.appendChild(create_naviheader(caption));		return true;	}		var create_naviprev = function(caption, back_ptr, id) {		return create_navigation_link(caption, "&larr;&nbsp;", null, back_ptr.prevCollection, id);	}	var create_navinext = function(caption, back_ptr, id) {		return create_navigation_link(caption, null, "&nbsp;&rarr;", back_ptr.nextCollection, id);	}	var create_naviheader = function(caption) {		return document.createTextNode(caption);	}	var create_navigation = function(back_ptr, id) {		var table = document.createElement("table");		var tbody = document.createElement("tbody");		var tr = document.createElement("tr");		tbody.appendChild(tr);		table.appendChild(tbody);				// left		var td = document.createElement("td");		td.style.textAlign = "left";		td.appendChild(create_naviprev("Left", back_ptr, id-1));		tr.appendChild(td);		navi_left = td;				// center		var td = document.createElement("td");		td.className = "Header";		td.style.fontWeight = "bold";		td.style.fontSize = "14pt";		td.appendChild(create_naviheader("Center"));		tr.appendChild(td);		navi_header = td;				// right		var td = document.createElement("td");		td.style.textAlign = "right";		td.appendChild(create_navinext("Right", back_ptr, id+1));		tr.appendChild(td);		navi_right = td;		var naviContainer = document.createElement("div");		naviContainer.className = "WSlideBox_Navigation";		naviContainer.appendChild(table);			return naviContainer;			}			/* dnd */	var dnd_obj  = null;	var dnd_mouse = null;	var old_x = 0;	var mousePos = null;	var mouseUp = function() {		dnd_obj.onmousemove = null;		dnd_obj = null;		scrollStep=3;		slideStep=450;	}		var getMouse = function(target, ev){		ev = ev || window.event;		var mousePos  = mouseCoords(ev);		return {x:mousePos.x, y:mousePos.y};	}		var mouseMove = function(ev) {		ev = ev || window.event;		old_x = dnd_mouse.x;		mousePos = mouseCoords(ev);		var c = mousePos.x - old_x;		if (!active && c < -20) {			scrollStep = 10;			__classptr.processSlideRight();		}				if (!active && c > 20) {			__classptr.processSlideLeft();		}	}	var mouseCoords = function(ev) {		if(ev.pageX || ev.pageY){			return {x:ev.pageX, y:ev.pageY};		}		return {			x:ev.clientX,			y:ev.clientY		};	}		var dnd_active = function() {		self.getMouse = getMouse;		self.onmousedown = function(ev){			dnd_obj  = this;			dnd_obj.onmousemove = mouseMove;			dnd_mouse = this.getMouse(this, ev);			old_x = dnd_mouse.x;			return false;		}	}	/* /dnd */		var init = function() {		trash = document.getElementById("trashcont");		self = create_self();		innerSelf = create_innerself();		self.appendChild(innerSelf);//		self.onmouseup   = mouseUp;//		dnd_active();			}	init();}
