// Index
// ---------------------------------------------
var index = new Object;
$(document).ready(function(){
	index = {

		// Init
		// ---------------------------------------
		init : function(){
			$(document).pngFix();
			if($.cookie('color')) index.color($.cookie('color'));
			var lst = $('div.carousel');    for(var i=0; i<lst.length; i++) index.carousel(lst[i]);
			try { document.execCommand("BackgroundImageCache", false, true); } catch(e) {}
			
			//$('H1').click(function(){ location.href = loc+'default.aspx'; });
		},


		// Carousel
		// ---------------------------------------
		carousel : function(div){
			var cnt = $(div).find('div.cnt');
			var lst = $(div).find('ul');	
			//alert(lst.find('li').width());
			
			
			var min = lst.width()-((lst.find('li').length-1)*(208)); //lst.find('li').width()
			var max = 0;
			var spd = 0;
			var int = false;			
			var mov = function(){
				var pos = parseInt(lst.css('margin-left'))-spd;
				if(pos < max && pos > min) lst.css('margin-left',pos);
			}
			cnt.mousemove(function(e){
				var wdt = cnt.width();
				var off = cnt.offset();
				var pos = e.clientX-off.left;
				if(pos>(wdt/2)) { spd = (pos-(wdt/2)); }
				else if (pos<(wdt/2)) {spd = -((wdt/2)-pos);}
				spd = parseInt(spd/50);
			});
			cnt.hover(function(){ int = setInterval(function(){ mov(); },10); },function(){ clearInterval(int); });
			$(div).find('a.prv').hover(function(){ if(spd >= 0) spd = -5; int = setInterval(function(){ mov(); },10);}, function(){ clearInterval(int); });
			$(div).find('a.nxt').hover(function(){ if(spd <= 0) spd = 5;  int = setInterval(function(){ mov(); },10);}, function(){ clearInterval(int); });
								
			var sayi=parseInt(lst.find('li').length/7);
			lst.width((lst.find('li').length+sayi)*lst.find('li').width()); 
			
			
			
		}
	}

	index.init();
});