// JavaScript Document

$(document).ready(function(){
	$('.rounded').corners();
	$(".scrollable").scrollable({prev:'.prev',next:'.next',items:'.items',size:2, speed:500});     
	$(".scrollable2").scrollable({prev:'.prev',next:'.next',items:'.items',size:3, speed:500});     
	$(".scrollable3").scrollable({prev:'.prev',next:'.next',items:'.items',size:2, speed:500});     
	
	var len=$('div.scrollable2 .slider').children().length;                
    if (len<=3){
        $('div.scrollable2').parent().children('a.next').addClass('disabled');
        $('div.scrollable2').parent().children('a.prev').addClass('disabled');
    }
	
	//calculeaza dimensiune pt rata
	/*$('#noutati .items .detalii').each(function(){
		var dim=$('span.pret',$(this)).css('width');
		$('span.rata',$(this)).css('width',dim);
	});*/
	
	$('#noutati a').hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','default');
	});
	
	
	if($('#email').val()=='')
		$('#email').val('adresa email');
	if($('#search_query').val()=='')
		$('#search_query').val('cauta produse');
	
	$('.buton').hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','default');
	});
	
	$('.simulator_rate').hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','default');
	});
	
	$('a.hasSubmenu').hover(function(){
		$('span img',$(this)).attr('src','/themes/prestashop/images/sageata_meniu_activ.jpg');
	},function(){
		$('span img',$(this)).attr('src','/themes/prestashop/images/sageata_meniu_inactiv.jpg');
	});
	
	$('#meniu a').hover(function(){		
		$('span',$(this)).css('background','#b17812');
		$('span',$(this)).css('paddingBottom','15px');
		//$("#"+($(this).attr('rel'))+" p.tip4").not(':first').css('marginTop','4px');
	},function(){		
		$('span',$(this)).css('background','#412b1e');
		$('span',$(this)).css('paddingBottom','9px');
	});
	
	$('#categories_block_left .acategorie').hover(function(){		
		$(this).css('cursor','pointer');
	},function(){		
		$(this).css('cursor','default');
	});
	
 $('#add_to_cart input').hover(function(){        
        $(this).css('cursor','pointer');
    },function(){        
        $(this).css('cursor','default');
    });

$('.buton_simplu').hover(function(){
        $(this).css('cursor','pointer');
    },function(){
        $(this).css('cursor','default');
    });

	
	$('.dropmenudiv_a').hover(function(){
		$("#meniu a[rel='"+$(this).attr('id')+"'] span").css('background','#b17812');
		$("#meniu a[rel='"+$(this).attr('id')+"'] span img").attr('src','/themes/prestashop/images/sageata_meniu_activ.jpg');
		$("#meniu a[rel='"+$(this).attr('id')+"'] span").css('paddingBottom','15px');
		$('p.tip4',$(this)).not(':first').css('marginTop','4px');
	}, function (){
		$("#meniu a[rel='"+$(this).attr('id')+"'] span").css('background','#412b1e');
		$("#meniu a[rel='"+$(this).attr('id')+"'] span img").attr('src','/themes/prestashop/images/sageata_meniu_inactiv.jpg');
		$("#meniu a[rel='"+$(this).attr('id')+"'] span").css('paddingBottom','9px');
	});										   
	
	
	$('#contul_meu_header ul li.rounded > div').each(function(){
		if ($(this).css('fontSize')=='1px')
			$(this).css('width','110px');
	});
	
	/*aliniez pretul de pe pagina produsului cu rata lunara si cu timbru verde */
	$('.date1 .pret2').each(function(){		
		$(this).css('width',$('.date1 .pret').width()+'px');
	});
	
	//redim height pt produsele afisate pe pagina unei categorii
	redimHeight('.redimHeight');
	redimHeight('.listare_produse .detalii .preturi');
	
	redimHeight('#noutati .detalii .detalii1');
	
	//redim height pt coloanele din meniul de sus - pt categorii si pt brand	
	redimHeight('#dropmenu1 .coloanadrop');
	redimHeight('#dropmenu2 .coloanadrop');
	
	//redim height pt produsele similare de pe pagina unui produs
	redimHeight('.similare .detalii p');
	
	redimHeight('#categorii_favorite .catfav ul');
	
	$('.recomandare .detalii p').width($('.recomandare .detalii p span.pret').width()+$('.recomandare .detalii p span.info').width()+8);
	
	
	$('#produse_comparate').css('width',100+(198*$('#produse_comparate div.lista').children().size()));
	
	
	$('#buy_block span.rounded a').hover(function(){		
		$(this).css('cursor','pointer');
	},function(){		
		$(this).css('cursor','default');
	});
});

function toggleSimulator(){
	$('#rate').toggle();		
}

function redimHeight(element){
	newHeight = 0;
    $(element).each(function(i){
        var height = new Array();
        height[i] = parseInt($(this).height());
        //if (element=='.redimHeight') alert ($(this).innerHeight()+'...'+$(this).outerHeight());
        if (height[i] > newHeight) {
            newHeight = height[i];
        }
    });
    //if (element!='.redimHeight') 
		$(element).height(newHeight);
	//alert(element);	
}

function alegeFactura(id){	
	$('#facturi div').css('display','none');
	$('.'+id).css('display','block');
	
}

//functie pentru setarea unui checkbox produs
function compara_produs(produs) {
	 produs.checked = !produs.checked;
	
	/*if ($('#'+produs).attr('checked')==true)
	 	$('#'+produs).attr('checked', false);
	else
		$('#'+produs).attr('checked', true);*/
	//$('#'+produs).attr('checked', !$(this).attr('checked'));
	//alert($('#'+produs).attr('checked'));
}

//functie pentru lansarea compararii
function compara() {
	var f = $('#form_selectie');
	$('#compara').val(1);
	//f.compara.value=1;
	f.submit();
}
