if(typeof com == 'undefined') com = new Object();
if(typeof com.tiso == 'undefined') com.tiso = new Object();
if(typeof com.tiso.classes == 'undefined') com.tiso.classes = new Object();
if(typeof document.loadHooks == 'undefined') document.loadHooks = [];

com.tiso.classes.Department = function() {}

com.tiso.classes.Department.prototype.ondocumentloaded = function()
{
	if(!(this.container = document.getElementById('product-list'))) return;
	this.objects = productObjects;
	this.tooltipVisible = null;
	for(var i in this.objects)
	{
		var obj = this.objects[i];
		if(!(product = document.getElementById('product-' + obj.id))) continue;
		if(!(link = Shine.getElementsByClass(product, 'a', 'product-image-link')[0])) continue;
		
		var div = Shine.createHTMLElement('div');
		div.id = 'tooltip-' + obj.id;
		Shine.addElementClass(div, 'tooltip');
		div.style.display = 'none';
		div.style.position = 'absolute';
		
		if(obj.description.length > 300 && (idx = obj.description.indexOf(' ', 300)) != -1)
		{
			obj.description = obj.description.substr(0, idx) + '...';
		}
		var s = [];
		s.push('<span class="name">'+obj.name+'</span>');
		s.push('<span class="brand">'+obj.brand+'</span>');
		s.push('<span class="price">'+obj.price+'</span>');
		s.push('<div class="description">'+obj.description+'</div>');
		if(obj.colours.length)
		{
			s.push('<ul class="swatches">');
			for(var j in obj.colours)
			{
				s.push('<li style="background-color: '+obj.colours[j]+';"></li>');
			}
			s.push('</ul>');
		}
		s.push('<div class="bottom"></div>')
		div.innerHTML = s.join('');
		document.getElementsByTagName('body')[0].appendChild(div);
		Shine.addEventHandler(link, 'mousemove', {host: this, handler: this.showToolTip, data: obj.id})
		Shine.addEventHandler(link, 'mouseout', {host: this, handler: this.hideToolTip, data: obj.id})
	}
}
com.tiso.classes.Department.prototype.showToolTip = function(Shine, sender, ev, data)
{
	if(this.tooltipVisible != data && (oldTooltip = document.getElementById('tooltip-' + this.tooltipVisible)))
	{
		oldTooltip.style.display = 'none';
		this.tooltipVisible = data;
	}
	var posx = 0, posy = 0;
	if(ev.pageX || ev.pageY)
	{
		posx = ev.pageX;
		posy = ev.pageY;
	}
	else if(ev.clientX || ev.clientY)
	{
		posx = ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = ev.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	var tooltip = document.getElementById('tooltip-' + data);
	tooltip.style.display = 'block';
	tooltip.style.left = posx + 10 + 'px';
	tooltip.style.top = posy - 60 + 'px';
}
com.tiso.classes.Department.prototype.hideToolTip = function(Shine, sender, ev, data)
{
	var tooltip = document.getElementById('tooltip-' + data);
	tooltip.style.display = 'none';
}
com.tiso.department = new com.tiso.classes.Department();
document.loadHooks.push(function() { com.tiso.department.ondocumentloaded(); });
