/**
* Bulgaria News Functions
* @author Angel Kostadinov (Creozon.com)
* @copyright Creozon
* @version 1.0 since 16.09.2011
*/
var F = (function()
{
	return {
		getDomain: function()
		{
			domain = 'http://' + document.location.toString().match(/:\/\/(.[^\/]+\/(bulgaria-news.bg){0,1})/)[1];
			
			return domain;
		},
		secureFORM:function()
		{
			var domain = this.getDomain();
			
			$('input[name="submit"]').ajaxStop(function()
			{
				$(this).val($(this).attr('title'));
				
				$(this).get(0).disabled = false;
			});
			
			$.ajax(
			{
				type: "GET",
				url: this.getDomain() + 'libraries/services/token.php',
				cache: false,
				success: function(response)
				{
					var token = $('<input type="hidden">');
					
					$(token).attr(
					{
						name: 'security'
					}).val(response).appendTo('#cmsform');
				}
			});
		},
		prepareSearchField: function(input, state)
		{
			switch(state)
			{
				case true:
					$(input).val('');
					break;
				case false:
					if (0 === $(input).val().length)
					{
						$(input).val($(input).attr('title'));
					}
					break;
			}
		},
		init: function()
		{
			/* Exclusive news ticker */
			$('div[id=exclusive] div a').ticker();
			
			/* Top news slideshow */
			$('div.carousel').jCarouselLite(
			{
				visible: 1,
				btnGo:
			    [
			    	'.pagination .1',
			    	'.pagination .2',
			    	'.pagination .3',
			    	'.pagination .4',
			    	'.pagination .5',
			    	'.pagination .6',
			    	'.pagination .7',
			    	'.pagination .8',
			    	'.pagination .9',
			    	'.pagination .10'
			    ],
			    easing: 'easeOutCubic',
			    speed: 1500,
			    auto: 15000,
			    afterEnd: function(item)
			    {
			    	var index = $(item).index() - 1;
			    	
			    	$('.pagination a').eq(index).addClass('active').siblings().removeClass('active');
			    }
			});
			
			$('.times a').mouseover(function()
			{
				var i = $(this).next().attr('src');
				
				$(this).parents().filter('div:first').find('img.switch').attr('src',i);
			});
		}
	}
})();

$(function()
{
	F.init();
})
