$(document).ready(function() {

/***************************************************************************/
	
  $('#rightMenuBox + .rightToggleButton').click(function() {
  
    if ($('#rightMenuBox').css('display') == 'none') {

       $('#rightMenuBox').fadeIn('slow',function () {
            $('#rightMenuBox').css('display','block');
       });
     
     } else {
       
       $('#rightMenuBox').fadeOut('slow',function () {
            $('#rightMenuBox').css('display','none');
       });
     
     
     }
  
  });

/***************************************************************************/
	
  $('.ingredientsToggleButton').click(function() {
  
    if ($('#ingredientsList').css('display') == 'none') {

       $('#ingredientsList').fadeIn('slow',function () {
            $('#ingredientsList').css('display','block');
       });
     
     } else {
       
       $('#ingredientsList').fadeOut('slow',function () {
            $('#ingredientsList').css('display','none');
       });
     
     
     }
  
  });

/***************************************************************************/
  
$('#navmenu-v .first').corner("tr"); 
$('#navmenu-v .toggleTitle:last').corner("br"); 

$('#navmenu-vn .toggleTitle:first').corner("tr"); 
$('#navmenu-vn .toggleTitle:last').corner("br"); 

/***************************************************************************/
  
	$('.detailed').click(function() {
		
		  window.location.href = $(this).parent().find('.toggleTitle a').attr('href');
	
	});

  $('.toggleTitle').mouseover(function() {
  
  	  $('.detailed').stop(true,true);
	  
	  var thisElement = $(this).parent().parent().attr('id');

	  $(this).corner("br 1px"); 
	  
  		if (thisElement != 'rightMenuBox') {
  		
  			$('#rightMenuBox').fadeOut('slow',function () {
  	            $('#rightMenuBox').css('display','none');
  			});
  			
  		}
    		
      if ($(this).parent().hasClass('showed') !== true ) {	
   	  
          $('.menuToggleItem').find('.detailed').slideUp('slow');      
   	            
          $('.menuToggleItem').removeClass('showed');

    	  stop(true, true);

    	  $(this).parent().find('.detailed').show('slow');
    	  
    	  $(this).parent().addClass('showed');
      
      }
    
  });  

/***************************************************************************/

  $('#navmenu-vn .menuToggleItem:last').mouseleave(function() {
	  $('#navmenu-vn .toggleTitle:last').corner("br"); 
  });  

  $('#navmenu-v .menuToggleItem:last').mouseleave(function() {
	  $('#navmenu-v .toggleTitle:last').corner("br"); 
  });  
  
  $('#navmenu-vn').mouseleave(function() {
	  
	  if ($('#navmenu-v').find('.iehover').attr('id') === null) {
		  $('.menuToggleItem').find('.detailed').slideUp('slow');  
		  $('.menuToggleItem').removeClass('showed');
	  }	  

  });  
  
/***************************************************************************/

  $('#navmenu-v').mouseleave(function() {
	  
	  if ($('#navmenu-v').find('.iehover').attr('id') === null) {
		  $('.menuToggleItem').find('.detailed').slideUp('slow');  
		  $('.menuToggleItem').removeClass('showed');
	  }	  

	  $('#navmenu-v .toggleTitle:last').corner("br"); 
	  
  });
  
/***************************************************************************/

  $('.bottomRelational').mouseenter(function() {
	 
	  		$('.detailed').stop(true,true);
	  
		  $(this).find('.detailed').show('fast');
		  
		  $(this).addClass('showed');

  });

  $('.containerText').mouseenter(function() {
		 
	  $(this).parent().animate({height: "185px"}, 400 );

  });
  
  $('.containerText').mouseleave(function() {
		 
	  $(this).parent().animate({height: "160px"}, 400 );

  });

  
  $('.bottomRelational').mouseleave(function() {
	  
		  $(this).find('.detailed').fadeOut('fast');
	  
		  $(this).removeClass('showed');		  
		  
  });

  
/***************************************************************************/

  
  
//  jQuery.each(jQuery.browser, function(i, val) {
  
	  //if (i == 'safari' || i == 'opera') {
	  if (location.pathname == '/' || location.pathname == '') { // just for homepage
	  
		  	$('#containerRight').find('p').empty().remove('p');
		  	$('#containerRight').append('<div class="homeText">Se spune ca trebuie sa le oferim copiilor nostri: radacini si aripi. In timp ce tu te ocupi ca ei sa prinda aripi, Rama te ajuta hranind buna crestere a copilului tau.</div>');
		  	$('#containerRight').append('<p style="text-align: center;margin-left:230px"><a href="http://desprerama.ro/cum-se-face-margarina-de-casa.html" target="_blank" title="Cum sa faci margarina acasa"><img src="http://www.desprerama.ro/uploads/images/originals/c0e7ff4a361dde7cec8474a31eb29987.png" title="Cum sa faci margarina acasa" alt="Cum sa faci margarina acasa" border="0"></a></p>');
  
	  }
	  
//  });
  
  $('#containerRight > p > img').addClass('noDefault');
  
/***************************************************************************/
  
  
  var fontMapping = new Array();
  
  fontMapping['ă'] = '`';
  fontMapping['â'] = 'â';
  fontMapping['î'] = 'î';
  fontMapping['ţ'] = ']';
  fontMapping['ş'] = '[';
  fontMapping['Ă'] = '~';
  fontMapping['Â'] = 'Â';
  fontMapping['Î'] = 'Î';
  fontMapping['Ţ'] = '}';
  fontMapping['Ş'] = '{';
  
  
  function fontMappReplacing(itemTxt) {
	  
	  for ( var i in fontMapping ) {
		  //var gicu = '/' + i + '/g';
		  //itemTxt = itemTxt.replace(gicu,fontMapping[i]);
		  itemTxt = itemTxt.replace(new RegExp(i, 'g'),fontMapping[i]);
	  }
	
	  return itemTxt;
	  
  }

  var embedContent = $('#wrapRight').html();
  //alert(embedContent);
  //$('#wrapRight').html(embedContent.replace(/<embed /,'<embed wmode="transparen " '));
  
  //$().html() = .replace(new RegExp('<embed ', 'g'),'<embed wmode="transparent" ');

  
  jQuery.each($('.home p'), function(i, val) {

      $(this).html(fontMappReplacing($(this).html()));

  });  
  
  
  jQuery.each($('.mainMenuItem'), function(i, val) {

      $(this).html(fontMappReplacing($(this).html()));

  });
  
  jQuery.each($('#containerRight > h2 > a'), function(i, val) {

      $(this).html(fontMappReplacing($(this).html()));

  });
  
  
  jQuery.each($('.bottomRelational .title'), function(i, val) {

      $(this).html(fontMappReplacing($(this).html()));

  });
  
  jQuery.each($('h1'), function(i, val) {

      $(this).html(fontMappReplacing($(this).html()));

  });

  
  //$('.mainMenuItem').html($('.mainMenuItem').html());
  
  $('object').append('<param name="wmode" value="transparent">');

  $('img.lightbox').parent().lightBox();

  $('.media').media();
});


