(function($) {
	$.fn.renderIlike = function(options) {
		return this.each(function() {
			var ilikeContainer = $('<div />').attr("id", "ilike").html($(this).html());
			ilikeContainer.prependTo('body');
			$(this).remove();
			
			$('.our-sites').ilikeFoldOut();
			var news = [];
			var mag = [];
			var chars = [];
			var urls = [];
			var newsContainer = $('span#ilike-news-item');
			var marker = $('span#marker');
			var magzContainer = $('span#ilike-mag');
			var currChar, timer, charTimer, markerIntervall, startTimer;
			var newsIndex = 0; 
			var charIndex = 0;
			
			//next
			//Set target attrubute on all links, due to html specs we do this in javascript
			$('#ilike a').each(function(){
				$(this).attr('target','_blank');
			});
		
			//If the client is safari: attach some safari search attributes
			if($.browser.safari) {
				var ilikesearch = $('#ilikesearch');
				$('#ilikesearch').attr('placeholder', 'Sökord').attr('autosave','iLike').attr('results','5');
				//small hack to make it work
				ilikesearch[0].type="search";
			}
			
			
		});
	};
	
	
	$.fn.ilikeFoldOut = function(options) {
        $.extend({}, options);
        return this.bind('click', function(e) {
			if($('#ilike-list').css('display') == 'block') {
				$(this).removeClass('ilike-selected');
				$('#ilike-list').slideUp("normal");
			}
			else {
				$(this).addClass('ilike-selected');
				$('#ilike-list').slideDown("normal");	
			}
			return false;
		});
    }
})(jQuery);

