jQuery.noConflict();  
jQuery(document).ready(function(){
  jQuery('#search-field').attr({value: 'buscar', style: 'color:#999;'});
  jQuery('#search-field').focus(function(){
  	if(jQuery(this).attr("value")=="buscar") jQuery(this).attr({value: '', style: 'color:#222;'});
  });
  jQuery('#search-field').blur(function(){
  	if(jQuery(this).attr("value")=="") jQuery(this).attr({value: 'buscar', style: 'color:#999;'});
  });
  
  jQuery('#main-nav li').hover(function(){
  	jQuery(this).children('.sub-menu').css('display','none').slideDown('fast');
  },function(){
  	jQuery(this).children('.sub-menu').stop(true, true).css('display','none');
  });
  
  jQuery('#show-form').click(function(){
  	jQuery('#foto-form').slideToggle();
  	return false;
  });
  
  if ( jQuery('div.error').length == 0 ) {
      jQuery('.single-forum .bbp-topic-form').hide().after("<a href='' id='show-form' class='big-pink-button alignright'>Comienza un Tema &darr;</a>");
      jQuery('.single-topic .bbp-reply-form').hide().after("<a href='' id='show-form' class='big-pink-button alignright'>Responde a Este Tema &darr;</a>");
      
      jQuery('#show-form').click(function(){
            jQuery('.bbp-topic-form, .bbp-reply-form').slideToggle();
            jQuery(this).fadeOut();
            return false;
        });
  }
  
  jQuery('#showawpcpadpage').prepend('<div class=\"error\"><p>Hemos movido los clasificados a los nuevos <a href=\"http://berlinenespanol.net/forums\">foros</a>. Dejerameos estos aquí por un tiempo, pero ya no se podrá colocar mas anuncios. Visita los <a href=\"http://berlinenespanol.net/forums/foro/clasificados-2/\">nuevos clasificados</a> para colocar un anuncio nuevo.</div>');
  
  jQuery('#drill').click(function(){
		
		var i=0;
		if (!drillWords){
		var drillWords = new Array();
		} else {drillWords=[];}
		var word;
		var def;
		var lastWord;
		jQuery(".word").each(function(){
			word = jQuery(this).text();
			def = jQuery(this).siblings(".def").text();
			drillWords[i]= new Array(word,def);
			i++;
		})
		maxNum=drillWords.length;
		firstRandNum=newWord(maxNum);
		jQuery("#drill-container, #overlay-back").fadeIn();
		jQuery("p.bigword").text(drillWords[firstRandNum][0]);
		jQuery("p#answer").text(drillWords[firstRandNum][1]);
		lastWord=drillWords[firstRandNum][0];
		jQuery('#show_answer').click(function(){
			jQuery('#answer').slideDown();
		  });
		jQuery("#next-word").click(function(){
			jQuery("#answer").hide();
			var nextWord = newWord(maxNum);
			if (lastWord == drillWords[nextWord][0] && drillWords.length > 1 ) {
				while ( lastWord == drillWords[nextWord][0] ) {
					nextWord = newWord(maxNum);
				}
			}
			jQuery(".bigword").text(drillWords[nextWord][0]);
			jQuery("#answer").text(drillWords[nextWord][1]);
			lastWord = drillWords[nextWord][0];
		});
		jQuery('#back').click(function(){
			jQuery("#drill-container, #overlay-back").fadeOut();
			jQuery("#answer").slideUp();
		});
		return false;
		
	});
});

function newWord(maxNum){
 	var randomNumber=Math.floor(Math.random()*maxNum);
	return randomNumber;
 }
