var Limonata = {};

Limonata.Cookie = {};

Limonata.Cookie.write =
	function(name, value)
	{
		var date = new Date();		
		date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));

		document.cookie = name + '=' + value + '; expires=' + date.toGMTString() + '; path=/';
	};


Limonata.Form = {};

Limonata.Form.limitTextareas =
	function()
	{
    	$('textarea[maxlength]').keyup
    	(
    		function()
    		{
				var maxLength = parseInt($(this).attr('maxlength'));

    	        if($(this).val().length > maxLength)
    	        {
    	        	$(this).val($(this).val().substr(0, maxLength));
    	        }
    	    }
    	);
	};
	
Limonata.Form.postToUrl =
	function(id, url)
	{
		var form = document.getElementById(id);
		
		form.action = url;
		
		form.submit();
	};

Limonata.Form.post =
	function(id)
	{
		var form = document.getElementById(id);
		
		form.submit();
	};

Limonata.Font = {};

Limonata.Font.size = 10;

Limonata.Font.set =
	function(sign)
	{
		switch (sign)
		{
			case '0':
				Limonata.Font.size = 10;
				break;
			case '+':
				if (Limonata.Font.size >= 12)
					return;
				
				Limonata.Font.size++;				
				break;	
			case '-':
				if (Limonata.Font.size <= 10)
					return;
				
				Limonata.Font.size--;
				break;
			default:
				Limonata.Font.size = parseInt(sign);
				break;
		}
		
		document.body.style.fontSize
			= Limonata.Font.size + 'px';
		
		Limonata.Cookie.write('LIMONATA.FONT', Limonata.Font.size);
	};

Limonata.Style = {};

Limonata.Style.set =
	function(title)
	{
		var links = document.getElementsByTagName('link');
		
		for (var i = 0; i < links.length; i++)
		{
			if (links[i].attributes['rel'].value.indexOf('stylesheet') > -1)
			{
				if (links[i].attributes['rel'].value.indexOf('alternate') > -1)
				{
					links[i].disabled = true;
				}
				
				if
					(
						links[i].attributes['title'] &&
						links[i].attributes['title'].value == title
					)
				{
					links[i].disabled = false;
					
					Limonata.Cookie.write('LIMONATA.STYLE', i);
				}
			}
		}
		
		if (title == 'Renk 1')
			Limonata.Cookie.write('LIMONATA.STYLE', 1);
	};
	
Limonata.Style.top =
	function(id, pos)
	{
		var obj = document.getElementById(id);
		
		obj.style.top = pos;
	};

Limonata.Class = {};

Limonata.Class.has =
	function(id, name)
	{
		var obj = document.getElementById(id);
		
		var objAttributeClass = obj.className;
		
		if (objAttributeClass == null || objAttributeClass == '')
		{
			return false;
		}
		
		var objAttributes = objAttributeClass.split(' ');
		
		for (var i = 0; i < objAttributes.length; i++)
		{
			if (objAttributes[i] == name)
				return true;
		}
		
		return false;
	};

Limonata.Class.toogleall =
	function(ids, name)
	{
		for (var i = 0; i < ids.length; i++)
		{
			Limonata.Class.toogle(ids[i], name);
		}
	};
	
Limonata.Class.toogle =
	function(id, name)
	{
		if (Limonata.Class.has(id, name))
		{
			Limonata.Class.remove(id, name);
		}
		else
		{
			Limonata.Class.add(id, name);
		}
	};
	
Limonata.Class.add =
	function(id, name)
	{
		var classList;
		
		var obj = document.getElementById(id);
		
		var objAttributeClass = obj.className;
	
		if (objAttributeClass != null && objAttributeClass != '')
		{
			classList = objAttributeClass.split(' ');
		}
		else
		{
			classList = new Array();
		}
		
		classList.push(name);
		
		obj.className = classList.join(' ');
	};
	
Limonata.Class.remove =
	function(id, name)
	{
		var classList = new Array();
	
		var obj = document.getElementById(id);
		
		var objAttributeClass = obj.className;

		if (objAttributeClass != null && objAttributeClass != '')
		{
			var objAttributes = objAttributeClass.split(' ');
			
			for (var i = 0; i < objAttributes.length; i++)
			{
				if (objAttributes[i] == name)
					continue;
				
				classList.push(objAttributes[i]);
			}
		}
		
		obj.className = classList.join(' ');
	};
	
Limonata.Location = {};

Limonata.Location.fromOption =
	function(o)
	{
		window.location.href = o.value;
	};

Limonata.Share = {};

Limonata.Share.url =
	function(service)
	{
		var title = encodeURIComponent(window.document.title);
		var url = encodeURIComponent(window.location.href);
	
		switch(service)
		{
			case 'facebook':
				var sURL = 'http://www.facebook.com/sharer.php?u=' + url + '&title=' + title;
				break;
			case 'twitter':
				var sURL = 'http://twitter.com/home?status=' + title + ' ' + url;
				break;
			case 'google':
				var sURL = 'http://www.google.com/bookmarks/mark?op=edit&bkmk=' + url + '&title=' + title;
				break;
			case 'myspace':
				var sURL = 'http://www.myspace.com/Modules/PostTo/Pages/?l=2&u=' + url + '&t=' + title + '&c=' + title;
				break;
			case 'yahoo':
				var sURL = 'http://bookmarks.yahoo.com/myresults/bookmarklet?u=' + url + '&t=' + title;
				break;
		}
		
		window.open(sURL, '_blank', 'width=800,height=600,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
	};

Limonata.Search = {};

Limonata.Search.toogle =
	function()
	{
		Limonata.Class.toogle('search-tsd', 'none');
		Limonata.Class.toogle('search-google', 'none');
	};
	
Limonata.Suggest = {};

Limonata.Suggest.popup =
	function()
	{
		window.open('/siteyi-oner', '_blank', 'width=500,height=300,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
	};

Limonata.FeatureImage = {};

Limonata.FeatureImage.href = null;

Limonata.FeatureImage.change =
	function(href, src, alt)
	{
		var url = document.getElementById('article-feature-url');
		
		if (Limonata.FeatureImage.href == href)
			return;
		
		Limonata.FeatureImage.href = href;
	
		$('#article-feature-image')
			.eq(0)
			.fadeOut(100, function() { url.href = href; url.title = alt; this.src = src; this.alt = alt; })
			.fadeIn(100);
	};

Limonata.Vote = {};
	
Limonata.Vote.prepare =
	function(name, info, thanks)
	{
		$('.' + name).rating
		(
			{
				callback:
					function(value, link)
					{
						$('.' + name).rating('disable');
				
						$.post
						(  
							window.location.href,  
							{ rating: value },  
							function(responseText)
							{
								$('#' + info).html(responseText);
								
								Limonata.Class.toogle(thanks, 'hidden');  
							},  
							"html"  
						); 
					}
			}
		);
	};

Limonata.Effect = {};

Limonata.Effect.adIndex = -1;

Limonata.Effect.adSlide =
	function()
	{
		var adList = $('.adslide a');
	
		if (Limonata.Effect.adIndex == -1 || Limonata.Effect.adIndex == adList.length - 1)
			Limonata.Effect.adIndex = 0;
		else
			Limonata.Effect.adIndex++;
	
		adList
			.eq(Limonata.Effect.adIndex)
			.animate({opacity: 'show'}, 1500)
			.delay(5000)
			.animate({opacity: 'hide'}, 1000);
	
		window.setTimeout(Limonata.Effect.adSlide, 9000);
	};
	
$.fn.rating.options.required = true;