$.tabs = function(selector, start) {
	$(selector).each(function(i, element) {
		$($(element).attr('tab')).css('display', 'none');
		
		$(element).click(function() {
			$(selector).each(function(i, element) {
				$(element).removeClass('selected');
				
				$($(element).attr('tab')).css('display', 'none');
			});
			
			$(this).addClass('selected');
			
			$($(this).attr('tab')).css('display', 'block');
		});
	});
	
	if (!start) {
		start = $(selector + ':first').attr('tab');
	}

	$(selector + '[tab=\'' + start + '\']').trigger('click');
};


function haibaga(idul){
	//Cancel the link behavior   

activeazamodal();         
        //Get the A tag   
        var id = idul;   
       
        //Get the screen height and width   
        var maskHeight = $(document).height();   
        var maskWidth = $(window).width();   
       
        //Set height and width to mask to fill up the whole screen   
        $('#mask').css({'width':maskWidth,'height':maskHeight});   
           
        //transition effect        
        $('#mask').fadeIn(500);       
        $('#mask').fadeTo("slow",0.8);     
       
        //Get the window height and width   
        var winH = $(window).height();   
        var winW = $(window).width();   
                 
        //Set the popup window to center   
        $(id).css('top',  winH/2-$(id).height()/2);     
        $(id).css('left', winW/2-$(id).width()/2);   
        //  $(id).css('top',  ($(window).height()/2) + $(window).scrollTop() - ($(id).height()/2) );   
        //  $(id).css('left', ($(window).width()/2) - ($(id).width()/2) );  
       
        //transition effect   
        $(id).fadeIn(2000); 
}


function activeazamodal() {
$(document).ready(function() {  
    //select all the a tag with name equal to modal   
    $('a[name=modalul]').click(function(e) {
    });          
    //if close button is clicked   
    $('.window .close').click(function (e) {   
        //Cancel the link behavior   
        e.preventDefault();   
        $('#mask, .window').hide();  
        $('select').show();  
    });               
    //if mask is clicked   
    $('#mask').click(function () {   
        $(this).hide();   
        $('.window').hide();
        $('select').show();    
    });            
       
});


$(document).keyup(function(e) {   
  if(e.keyCode == 27) {   
    $('#mask').hide();   
    $('.window').hide(); 
    $('select').show();   
  }   
}); 

$(document).ready(function() {
 // $('body').prepend('<div id="mask"></div>');
	$('select').hide(); 
 $('#container').after('<div id="boxes"><div id="dialog" class="window"> </div></div>');
 $('#container').after('<div id="mask"></div>'); 
 proceseaza('catalog/controller/product/procesator.php','ceva');
 
});

}

function proceseaza(aurl,ceanume) {	
	 $("#dialog").load(aurl);
	}

function salveaza(aurl) {	
	//alert($("#emailul").val());
	//alert($("#mesajul").val());
	// $('#adminForm').submit();
	// return false;
	//$.post(aurl, $("#adminForm").serialize());
$("#dialog").load(aurl,{emailul:$("#emailul").val(),mesajul:$("#mesajul").val()});
	// $("#dialog").load(aurl,$("#formul").serialize());
	//  $("#dialog").load(aurl,{paramsadmin_email",varsta:30});
	}
	
function inchide(){
	$('#mask').hide();   
    $('.window').hide();
    $('select').show(); 
}

function ajaxlink(aurl,ceanume) {


 //$('body').prepend('<div id="incar" name="incar" style="float:left;display:none;"> <img src="catalog/view/theme/default/image/wait3.gif"></div>');
 $('#incar').ajaxStart(function() {
 $(this).show();
 }).ajaxStop(function() {
 $(this).hide();
 });

	
	 $(ceanume).load(aurl);
	}
	
	
		function AdaugaInCos(product_id1,quantity1,last_cat1){
			
			//	data: $('#product :input'),	
			//redirect1=this.window.location;
			//alert(window.location.href);
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',	
			data: ({product_id:product_id1,redirect:window.location.href,last_cat:last_cat1,quantity:quantity1}),
			success: function (html) {
				$('#module_cart .middle').html(html);
			},
			complete: function () {
				var image = $('#image').offset();
				var cart  = $('#module_cart').offset();

				$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

				params = {
					top : cart.top + 'px',
					left : cart.left + 'px',
					opacity : 0.0,
					width : $('#module_cart').width(),
					heigth : $('#module_cart').height()
				};

				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});
			}
		});
	}