function rotateNews(id,cssProperty,cssOut,cssIn,d1,d2,d3)//{{{
{

	var pn = $(id);
	var pnf = pn.lastChild;

	var fx = new Fx.Tween(pnf, {
		property: cssProperty,
		duration: 4000,
		transition: Fx.Transitions.Sine.EaseInOut
	});
 
	(function(){ fx.start(cssOut); }).delay(d1);
	(function(){ pnf.dispose().inject(pn,'top'); }).delay(d2);
	(function(){ fx.start(cssIn); }).delay(d3);
}//}}}
function cookieGroup(group,domain)//{{{
{
	var cookie = new Hash.Cookie('data', {'domain':'.'+domain, path: '/'});
	cookie.set('group',group);
}//}}}
function cookieProduct(product,domain)//{{{
{
	var cookie = new Hash.Cookie('data', {'domain':'.'+domain, path: '/'});
	cookie.set('product',product);
}//}}}
function cookiePG(product,group,domain)//{{{
{
	cookieProduct(product,domain);
	cookieGroup(group,domain);
}//}}}
window.addEvent('load', function()//{{{
{
	numnews = $('news1').childNodes.length;

	if(numnews > 2)
	{
		var rotateAllNews = function() {
					rotateNews('news1','width','0px','300px',0,4100,4200);
					rotateNews('news2','height','0px','150px',9000,13100,13200); 
		}
		//init cycle
		rotateAllNews.periodical(18000);
		//start at load
		//rotateAllNews();
	}

});//}}}
window.addEvent('domready', function() //{{{
{
	var cookie = new Hash.Cookie('data', {domain: '.uscom.si', path: '/'});
	group = cookie.get('group');
	product = cookie.get('product');
	sfxNav(product,group,'sfx_prev');
	sfxNav(product,group,'sfx_next');
});//}}}
function sfxNav(product,group,action)//{{{
{
	var jsonRequest = new Request.JSON(
			{
				url: "ajax.php",
				onSuccess: function(ret)
				{
					$(action).set('html',ret.html); 
				}
			}
			).get({'action': action, 'product': product, 'group': group});
}//}}}
window.addEvent('domready', function() //{{{
{
	var jsonRequest = new Request.JSON(
			{
				url: "ajax.php",
				onSuccess: function(data) { if(data) toolboxUpdate(data); }
			}
			).get({'action': 'toolbox'});
	
});//}}}
function toolboxUpdate(data)//{{{
{
	var input = new Element('input', {
		'value': 'nova nalepka',
		'styles': {
			'border':'1px solid #EEE',
			'margin':'0px 1px 2px 1px',
			'padding': '3px 3px',
			'-moz-box-shadow':'1px 1px 1px #CCC',
			'-moz-border-radius':'5px'
		},
		'events': {
			'change': function(){
				this.value = this.value.trim();
				toolboxNewTag(this.value,'');
				toolboxSaveTag(this.value);
				this.select();
			},
			'focus': function(){
				this.select();
			}
		}
	});
	$('toolbox').grab(input);

	$('toolbox').setStyle('padding','5px 0px 4px 5px');
	if(data.links) data.links.each(function(link){toolboxLink(link);}); 
	if(data.hottags) data.hottags.each(function(tag){toolboxHotTag(tag);}); 
}//}}}

function toolboxSaveTag(tag,id)//{{{
{
	var jsonRequest = new Request.JSON(
			{
				url: "ajax.php",
				onSuccess: function(ret)
				{
				}
			}
			).get({'action': 'tag_add', 'tag': tag});
}//}}}
function toolboxDelTag(id)//{{{
{
	var jsonRequest = new Request.JSON(
			{
				url: "ajax.php",
				onSuccess: function(ret)
				{
				}
			}
			).get({'action': 'tag_del', 'id': id});
}//}}}

Element.implement({ fadeAndDestroy: function(duration) {//{{{
		duration = duration || 600;
		this.set('tween', {
			duration: duration,
			onComplete: this.destroy.bind(this)
		});
		this.fade('out');
	}
});//}}}
function toolboxLink(link) {//{{{
	 toolboxNewTag(link.text,'<b>'+link.on_user+'</b> - '+link.on_timestamp,link.id); 
}//}}}
function toolboxNewTag(tag,info,id)//{{{
{
	var obj = new Element('a', {
		'html': tag,
		'info': info,
		'tagid': id,
		'styles': {
			'background-color': 'FFFFA8',
			'margin':	'0px 2px 4px 3px',
			'padding': '3px 5px',
			'cursor': 'pointer',
			'-moz-box-shadow':'1px 1px 1px #BFBF86',
			'-moz-border-radius':'5px',
			'opacity': '0',
			'white-space':'nowrap'
		},
		'events': {
			'click': function(){
				$('toolbox').firstChild.value = this.innerHTML;
				toolboxDelTag(this.getAttribute('tagid'));
				$('info').set('html','');
				$('info').setStyle('padding','0');
				obj.fadeAndDestroy();
			},
			'mouseenter': function(){
				this.tween('color', '#D60069');
				$('info').set('html',this.getAttribute('info'));
				$('info').setStyle('padding','3px 8px');
			},
			'mouseleave': function(){
				this.tween('color', '#000');
				$('info').set('html','');
				$('info').setStyle('padding','0');
			}
		}
	});
	$('toolbox').grab(obj);
	obj.fade('in');
}//}}}
function toolboxHotTag(tag)//{{{
{
	var obj = new Element('button', {
		'html': tag.value,
		'styles': {
			'border':'1px solid #EEE',
			'background-color': 'white',
			'margin':'0px 2px 4px 3px',
			'color': '#aaa',
			'cursor': 'pointer',
			'-moz-box-shadow':'1px 1px 1px #CCC',
			'-moz-border-radius':'5px',
			'white-space':'nowrap'
		},
		'events': {
			'click': function(){
				$('toolbox').firstChild.value = this.innerHTML;
				$('toolbox').firstChild.fireEvent('change');
				this.fadeAndDestroy();
			},
			'mouseenter': function(){
				this.tween('color', '#000');
			},
			'mouseleave': function(){
				this.tween('color', '#aaa');
			}
		}
	});
	$('toolbox2').grab(obj);
}//}}}


