(function($) {
	$.fn.ibox = function(options){
		var options = $.extend({
			hiz		:1200,
			satir	:3
		},options);
		$(this).css({'margin':'0px','padding':'0px','text-align':'left'})
		var w = $(this).width();
		var h = $(this).width();
		addStyles('.ibox{margin:0px; padding:0px;width:'+w+'px; height:'+h+'px;}');
		addStyles('.ibox li{width:'+w+'px; height:'+h+'px;margin:0px; padding:0px; display: inline-block;list-style:none none; }');
		this.html('<ul class="ibox"><li rel="0">&nbsp;</li><li rel="1">&nbsp;</li><li rel="2">&nbsp;</li></ul>');
		this.each(function() {
			var obj = $(this);
			var w = $("li", obj).width();
			var len = ibox.length-1;
			var sabit = true;
			obj.width = w;
			obj.css("overflow","hidden");
			$("ul", obj).css('width',3*w);
			var s = 0;
			$("li", obj).each(function (k,v){
				$(this).addClass('box_'+s);
				s =(s < len)?s+1:0;
			});
			s =(s < len)?s:0;
			function kopyala(){
				var cp = $("ul li", obj).eq(0).clone();
				cp.removeClass('box_'+cp.attr('rel')).addClass('box_'+s).attr('rel',s);
				$("ul", obj).append(cp);
				$("ul li:last", obj).click(function(){
					document.location.href= '/ekrangoruntuleri/';
				});
				$("ul li", obj).eq(0).remove();
				$("ul", obj).css('height',(4)*w).css('marginLeft',0);
				sabit = true;
				s =(s < len)?s+1:0;
			};
			
			function kaydir(){
				if (sabit){
					sabit = false;
					$("ul",obj).animate({ marginLeft: (w*-1)}, { queue:false, duration:options.hiz, complete:kopyala });					
					sayac = setTimeout(function(){kaydir();},options.hiz+2000);		
				};
			};
			var sayac;
			sayac = setTimeout(function(){kaydir();},2000);
		});
	};
})(jQuery);

$(document).ready(function(){	
	if (typeof(ibox)=='object'){
		for (i in ibox)	{
			addStyles('.box_'+i+' {background:url('+ibox[i]+') no-repeat top center;}');
		}
	}
	$(".boxBody").ibox();
});	
function addStyles(rule){
     var sheet = document.styleSheets[0],
          ln = (sheet.cssRules||sheet.rules).length;
     if (sheet.addRule) {
         rule = rule.match(/(.*){(.*)}/);
         sheet.addRule(rule[1],rule[2], ln);
     } else {
         sheet.insertRule(rule, ln);
     };
     return arguments.callee;
};
 
