var settings = { 
    sensitivity: 5, 
    interval: 50, 
    timeout: 500, 
    out: resetContainer 
}; 

function resetContainer() { 
    $('#em-submenu').fadeOut(200); 
}

$(function() {
	
	/*** Smooth Page Transitions ***/
	if ($.browser.msie || $.browser.webkit) { null; } else {
	$('body').hide(); $('body').load().stop().fadeIn(200); }
	
	/*** CLEAR INPUT FIELDS ONCE ***/
	
	$("input[type=password]").one("focus", function(){
		$(this).attr("value", "");
	});
	
	/*** Submenu ***/
	$('#em-menu a').mouseenter(function() {
		if ($(this).hasClass('trigger')) {
			$('#em-submenu').fadeIn(100);
		} else {
			$('#em-submenu').fadeOut(200);
		}
	});

	$('#em-submenu').hoverIntent(settings);


	/*** Active link ***/

	var currentIndex = window.location.href.split('/')[3];
	$('#em-menu a').removeClass('selected');	
	if (!currentIndex) $('#em-menu li:first-child a').addClass('selected');
	$('#em-menu a[href="'+currentIndex+'"]').addClass('selected');

	$('.em-nav li').click(function(){
		location.href = $(this).find('a').attr('href');
	});



	/*** Lightbox ***/
	$('#em-diplome a.tb-80, #em-exemple a.tb-80, #em-galerie a.tb-80, #em-gallery-slide a.tb-80, div.em-product a.tb-80').lightBox({
	overlayBgColor: '#111',
	overlayOpacity: 0.5,
	imageLoading: 'images/template/plugins/lightbox-ico-loading.gif',
	imageBtnClose: 'images/template/plugins/lightbox-btn-close.gif',
	imageBtnPrev: 'images/template/plugins/lightbox-btn-prev.gif',
	imageBtnNext: 'images/template/plugins/lightbox-btn-next.gif',
	containerResizeSpeed: 10
	});

	
	
	$('#em-edit-frame').wysiwyg({
		autoGrow: true,
		createLink: true
	});

	$('a.addbtn').live('click',function(e){
		e.preventDefault();
		$('#add-prod-box').remove();
		$(this).after('<div id="add-prod-box"></div>');
		$('#add-prod-box').load('includes/html/add-form.php?target='+$(this).attr('href'));
	});
	
	$('a.addpdf').live('click',function(e){
		e.preventDefault();
		$('#add-prod-box').remove();
		$(this).after('<div id="add-prod-box"></div>');
		$('#add-prod-box').load('includes/html/add-form.php?target=pdf');
	});	
	
	
	$('a.editbtn').live('click',function(e){
		e.preventDefault();
		$('#add-prod-box').remove();
		var id = $(this).attr('name').replace('edit-','');
		$('a.addbtn').after('<div id="add-prod-box"></div>');
		$('#add-prod-box').load('includes/html/edit-form.php?target='+id);
	});
	
	$('a.delbtn').live('click',function(e){
		e.preventDefault();
		var id = $(this).attr('name').replace('del-','');
		var result = confirm('Produsul va fi sters.');
		if (result) {
		
			if (location.host=='localhost') {
				var path = location.protocol+'//'+location.host+'/emax-rdy/';
			} else {
				var path = location.protocol+'//'+location.host+'/';
			}
			
			var base = path + 'includes/bin/processor.php?action=delete&id='+id;
			location.href = base;
		} 
	});


	
	$('a.delpdf').live('click',function(e){
		e.preventDefault();
		var id = $(this).attr('name').replace('del-','');
		var result = confirm('Oferta va fi stearsa.');
		if (result) {
			location.href='includes/bin/processor.php?action=delete&obj=pdf&id='+id;
		} 
	});	

$('#em-slider').cycle();

$('input[name=bold_keys]').change(function() {
	$('#editform').submit();
});


});
