/*
	
	Copyright © Ubuntu via web
	
	+root/
		+data/
			+default/
				+js/
					-base.js
				
	Описание: 
	
		JavaScript методи за тази кожа
				
*/

// base обект
var base = {
	
	CursorTop : 20,
		
	LoadingText : '<img src="./data/default/images/loading.gif" alt="loading"/>',
	Parent : false,
	WindowId : "Window",
	//Показване на прозорец с информация
	WindowShow : function(con, ok) {
			
		var id = base.WindowId;
		
		if(base.Parent != "pot") core.Redirect("#TopView");
		
		if(document.getElementById(id).style.display!='block'){
			
			core.CenterElement(id);
		
			core.Show(id);
			
			core.SetOpac(60, "screen", false, false);
			core.Show("screen");
			core.OverflowOff();
		}
		
		if(ok) {
			
			con += "<br/><button class='button' onclick='base.WindowHide()'>OK</button>"
			
		}
		core.SetContent(id, con);
		
		core.Parent = 0;
		
	},
	//Показване на прозореца с информация
	WindowHide : function() {
		
		var id = base.WindowId;
		core.Hide(id);
		
		core.Hide("screen");
		core.OverflowOn();

	},
	
	allow : true,
	counter : true,
	src : new Array(),
	
	//Показване на голямо изображение
	ShowPic : function() {
				
		if(base.allow) {
			
			if(document.getElementById("PicView").style.display == "none") {
				
				var pic = base.pic;
				
				var event = base.event;
				
				var div = document.getElementById("PicView");
				div.style.display="block";
				div.innerHTML = '<img src="'+pic+'" style="height: 465px;" />';	
				
				div.style.left = (base.x-(div.offsetWidth/2))+"px";
				div.style.top = (base.y+base.CursorTop)+"px";
			}
			
		}
		
	},
	
	ConfigView : function() {
		
		var name = core.getElementsByClassName("ProductSmall");
		var src;
		
		for(var i = 0; i < name.length; i++) {
		
			base.src[i] = name[i].src;
			
			name[i].onmousemove = function(event) {
				
				base.allow = true;
				base.event = event;
				var div = document.getElementById("PicView");
						
				base.pic = this.src;
				
				if(document.getElementById("PicView").style.display == "none") {
					base.t = setTimeout("base.ShowPic()", 1000);
					base.x = base.GetPosition(event).x;
					base.y = base.GetPosition(event).y;
				}
				else{
					if(base.pic != this.src) {
						var div = document.getElementById("PicView");
						div.innerHTML = '<img src="'+this.src+'" style="height: 400px;" />';
					}
				}
				
				div.style.left = (base.GetPosition(event).x-(div.offsetWidth/2))+"px";
				div.style.top = (base.GetPosition(event).y+base.CursorTop)+"px";
			
				
			}
			
			name[i].onmouseout = function() {
				
				base.StopPic();
				
			}
			
		}
		
		base.src = src;
		
	},
	
	StopPic : function() {
		
		base.allow = false;
		clearTimeout(base.t);
		core.Hide("PicView");
		var div = document.getElementById("PicView");
		div.innerHTML = "";
		
	},
	
	GetPosition : function(e) {

	    e = e || window.event;
	
	    var cursor = {x:0, y:0};
	
	    if (e.pageX || e.pageY) {	
	        cursor.x = e.pageX;	
	        cursor.y = e.pageY;	
	    }
	
	    else {	
	        cursor.x = e.clientX +	
	            (document.documentElement.scrollLeft ||	
	            document.body.scrollLeft) -	
	            document.documentElement.clientLeft;
	
	        cursor.y = e.clientY +	
	            (document.documentElement.scrollTop ||	
	            document.body.scrollTop) -	
	            document.documentElement.clientTop;	
	    }
	
	    return cursor;
	
	}
	
}

onload = function() {
	base.ConfigView();
}
