$(document).ready(function(){
	function megaHoverOver(){
		$(this).find(".sub").stop().show().css({"opacity":"1"});
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").hide();
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
	try {
		$("ul#topnav li .sub").css({'opacity':'0'});
		$("ul#topnav li").hoverIntent(config);
	} catch(err) {
	}
});

function sepete_at(urun_no, ozellik) {
	$.ajax({
		type: 'GET',
		url: 'index.php?p=Sepet-Islemleri&a=ekle&urun_no='+parseInt(urun_no)+'&ozellik='+(ozellik||''),
		data: '',
		success: function(cevap) {
			if(cevap.substring(0,6)!='Tamam.') {
				uyari(cevap.substring(5));
			} else {
				$('#sepet_blogu').load("index.php?p=Sepet-Islemleri&a=blok_icin_yazdir");
				sepeti_goster();
			}
		}
	});
}
function sepet_artir(sepet_no) {
	$.ajax({
		type: 'GET',
		url: 'index.php?p=Sepet-Islemleri&a=artir&sepet_no='+parseInt(sepet_no),
		data: '',
		success: function(cevap) {
			if(cevap.substring(0,6)!='Tamam.') {
				uyari(cevap.substring(5));
			} else {
				$('#sepet_blogu').load("index.php?p=Sepet-Islemleri&a=blok_icin_yazdir");
			}
		}
	});
}
function sepet_azalt(sepet_no) {
	$.ajax({
		type: 'GET',
		url: 'index.php?p=Sepet-Islemleri&a=azalt&sepet_no='+parseInt(sepet_no),
		data: '',
		success: function(cevap) {
			if(cevap.substring(0,6)!='Tamam.') {
				uyari(cevap.substring(5));
			} else {
				$('#sepet_blogu').load("index.php?p=Sepet-Islemleri&a=blok_icin_yazdir");
			}
		}
	});
}
function sepet_cikart(sepet_no) {
	$.ajax({
		type: 'GET',
		url: 'index.php?p=Sepet-Islemleri&a=cikart&sepet_no='+parseInt(sepet_no),
		data: '',
		success: function(cevap) {
			if(cevap.substring(0,6)!='Tamam.') {
				uyari(cevap.substring(5));
			} else {
				$('#sepet_blogu').load("index.php?p=Sepet-Islemleri&a=blok_icin_yazdir");
			}
		}
	});
}
function ilceleri_getir(il_no,isim,alan,others) {
	if(others) {
		others = '&others='+others;
	} else {
		others = '';
	}
	$('#'+alan).load('index.php?p=Sepet-Islemleri&a=ilceleri_getir&no='+parseInt(il_no)+'&name='+isim+others);
}
function sepeti_goster() {
	$.get("index.php?p=Sepet-Islemleri&a=acilir_sepet_icin_yazdir", "", function(veri){
		msg = "<div style=\"width:800px;\">"+veri+"</div>";
		phpBil.BOX.pencere("<h3 style=\"margin:0px 4px 8px 0;padding:0;font-size:14px;\">Alışveriş Sepeti</h3>"+msg, 'mesaj_kutusu', "800px");
		phpBil.BOX.buton_ekle("onclick=\"phpBil.BOX.kapat();\"", "Sepeti Kapat");
	});
}
