/* Setting up the tree categories */
CKEDITOR.replace('content');

var treeCat = new intelli.tree({
	id: 'tree',
	type: 'checkbox',
	hideRoot: false,
	menuType: intelli.config.categories_tree_type,
	callback: function()
	{
		var catId = $(this).val().replace('_crs', '');

		/* hiding any notification boxes */
		intelli.display('notification', 'hide');

		$('#categoryTitle > strong').text($(this).attr('title'));
		$('#category_id').val(catId);
	},
	dropDownCallback: function(id, title)
	{
		/* hiding any notification boxes */
		intelli.display('notification', 'hide');

			$('#categoryTitle > strong').text(title);
			$('#category_id').val(id);
	}
});

/* Initialization tree categories */
treeCat.init();

intelli.display('#tree', 'show');

var a = document.getElementsByTagName("a");

for(var i = 0; i < a.length; i++)
{
	if(a[i].id != '' && a[i].id.charAt(0) == 'b')
	{
		a[i].onmousedown = countBannerClick;
	}
}

function countBannerClick()
{
	var tp = this.id.charAt(0);
	
	if(tp != 'b')
	{
		return true;
	}

	if(this.id.length < 2)
	{
		return true;
	}

	itemid = this.id.substring(1);
	if(parseInt(itemid.charAt(0)) < 1 || itemid.match(/\D/))
	{
		return true;
	}
	i = new Image();
	h = Math.random();

	i.src= root + 'controller.php?plugin="banners"&file="banner-count"&id=' + itemid + '&type='+tp+'&h='+h;

	return true;
}

function changeType()
{
	type = $('#typeSelecter option:selected').val();

	$('#imageTitle, #imageParams, #imageUrl, #bannerurl, #htmlsettings, #mediasize, #bannerThumbnail, #uploadcontainer, #textcontainer, #planetextcontainer, #imageFit').hide('slow');

	switch(type) 
	{
		case "html":
			$('#htmlsettings, #textcontainer').show('slow');
		break;
		
		case "text":
			$('#planetextcontainer, #bannerurl').show('slow');
		break;
		
		case "local":
			$('#bannerThumbnail, #mediasize, #imageTitle, #uploadcontainer, #bannerurl').show('slow');
			if($('#setown').attr("checked"))	{	$('#imageParams').show('slow');	}
			if($('#imageKeepRatio').attr("checked"))	{	$('#imageFit').show('slow');	}
		break;
		
		case "remote":
			$('#imageUrl, #mediasize, #imageTitle, #bannerurl').show('slow');
			if($('#setown').attr("checked"))	{	$('#imageParams').show('slow');	}
			if($('#imageKeepRatio').attr("checked"))	{	$('#imageFit').show('slow');	}
		break;

		case "flash":
			$('#uploadcontainer, #bannerThumbnail, #mediasize').show('slow');
		break;
	}
}
changeType();

function getTarget(sObj)
{
	type = sObj.options[sObj.selectedIndex].value;

	if('other' == type) 
	{
		$('#settarget input').val('');	
		$('#settarget').show();	
	}
	else
	{
		$('#settarget').hide();	
		$('#settarget input').val(this.value);
	}
}

function imageFit()
{
	if ($('#file').val().substr(-3) != 'swf')
	{
		$('#imageFit').slideToggle();
	}else{
		$('#imageFit').hide("slow");
	}
}


