jQuery(document).ready(function($) {
/* am folosit aceasta metoda, pentru a evita conflictele cu prototype.js */
	
	if( $('#div_categorii').length > 0 ){
		$('#div_categorii').find('A').click(function(){
			if( this.id.substr(0, 6) == "a_id_c" ){
				// Send Ajax request to set SESSION variable
				$.ajax({
					type: "POST",
					url: "setSession.php",
					data: "variable=div_id_c" + this.id.substr(6, this.id.length) + "&state=" + $("#div_id_c" + this.id.substr(6, this.id.length)).is(":hidden"),
					success: function(){
					},
					error: function(data){
						//alert(data.toSource());
					}
				});				//*/
				$("#div_id_c" + this.id.substr(6, this.id.length)).slideToggle(400); 
			}
		});
	}
	
	if( $('#starra_points').length > 0 ){
		$('#starra_points').find('IMG').mousedown(function(){
			if( this.id.substr(0, 5) == "starr" ){
				lstarrNr = this.id.substr(5, this.id.length);
				$('#punctaj').val(lstarrNr);
				starr_draw(lstarrNr);
			}
		}).mouseover(function(){
			if( this.id.substr(0, 5) == "starr" ){
				lstarrNr = this.id.substr(5, this.id.length);
				
				starr_draw( lstarrNr );
			}
		}).mouseout(function(){
			if( this.id.substr(0, 5) == "starr" ){
				lstarrNr = this.id.substr(5, this.id.length);
				
				starr_reset();
			}
		});
		
		function starr_reset(){
			lstarrNr = $('#punctaj').val();
			
			starr_draw( lstarrNr );
		}
		
		function starr_draw( pstarrNr ){
				for(i=1; i<=pstarrNr; i++){
					$('#starr'+i).attr("src", "images/star_on.gif");
				}
				for(; i<=5; i++){ // i este initializat cu valoarea buna in for-ul anterior
					$('#starr'+i).attr("src", "images/star_off.gif");
				}
		}
	}

	if( $('#t01_compara_produse').length > 0 ){
		$('#produs_de_cumparat').change(function(){
			window.location.href = "compara_produse.php?addNewProduct&id=" + $('#produs_de_cumparat').val();
		});
		$('#comparatie').find("INPUT").click(function(){
			window.location.href = "compara_produse.php?delProduct&id=" + this.id;
		});
	}
	
	if( $('#finalizare_comanda').length > 0 ){
		// implicit campurile sunt ascunse
		$('#alta_adresa01').hide();
		$('#alta_adresa02').hide();
		
		// implicit campurile sunt ascunse
		$('#firma_adresa01').hide();
		$('#firma_adresa02').hide();
		
		$('input:radio[name=adresa]').change(function(){
			if( $('#adresa3').attr('checked')  ){
				$('#alta_adresa01').show();
				$('#alta_adresa02').show();
			}else{
				$('#alta_adresa01').hide();
				$('#alta_adresa02').hide();
			}
			
			if( $('#adresa2').attr('checked')  ){
				$('#firma_adresa01').show();
				$('#firma_adresa02').show();
			}else{
				$('#firma_adresa01').hide();
				$('#firma_adresa02').hide();
			}
		});
	}
	
	if( $('#becuri_atasate').length > 0 ){
		$('#becuri_atasate li').hover(
			function () {
				//show its submenu
				$('ul', this).slideDown(100);

			},
			function () {
				//hide its submenu
				$('ul', this).slideUp(100);        
			}
		);
	}

	if( $('#callback_div_frm').length > 0 ){
		$("#callback_frm").submit(function(){
			$.post(
				"callback_submit.php",
				$("#callback_frm").serialize(),
				function(data){
					$('#callback_div_frm').html(data);
				}
			);
			return false; // ca altfel face submit...
		});
	}
	
});

