 $(document).ready(function(){
 	//idgw
   $('.idgw_text').hide();
   if($('#idgw_link_before').length) {
   		//alert('Hello!');
   	   $('#idgw_link_before').hide();
   		var idgw_link = $('#idgw_link_before').html();
   		$('#idgw_section_first').before('<div id="idgw_link_after">' + idgw_link + '</div>');
   }
   if($('#idgw_section_first').length) {   
   		$('#idgw_section_first').before('<div id="click">READ MORE:</div>');
   }
   $('.idgw_title').addClass('idgw_title_js');
   $('.idgw_title').prepend('↪&nbsp;');   
   $(".idgw_title").click(function() {
     $(this).next('.idgw_text').toggle('fast');
   });

	// embed  
   $('#embed').hide();
   $("#embed_button").click(function() {
     $('#embed').toggle('fast');
   });   
   
   $("#embed").focus(function() {
     this.select();
   });  	 
   
   //tags
   if($('#tags').length) {
	   	$("#tags").autocomplete("autocomplete_tags.php", {
			width: 400,
			highlight: false,
			multiple: true
		});
		
		$("#send_tags").submit(function(){ 
			$("#tags_saved_text").stop().css('opacity','1').html('<img src="spin.gif" alt="" />');
			$.post("save_tags.php", { tags: $("#tags").val(), id: $("#id").val() },
  function(data){
    if(data.success=="1") {
    	$("#tags_saved_text").hide().text('Tags saved.').fadeIn('fast').fadeOut(10000);
    	
    	if($("#tags_area").html() == '')
    		$("#tags_area").hide();
    		
    	$("#tags_area").load('ajax_tags_box.php',{id: $("#id").val()},function(){
    		if($("#tags_area").html() != '') {
    			$("#tags_area").show('slow');
    			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: $("#similar_stuff").offset().top}, 1100 );
    		} 
    	});
    	
 	
    	
    }
    else if(data.success=="2") {
    	$("#tags_saved_text").hide().text('Uuups! You are not logged in!').fadeIn('fast').fadeOut(10000);      	
    } else {
    	$("#tags_saved_text").hide().text('Uuups! Not saved :|').fadeIn('fast').fadeOut(10000);    	
    }
  }, "json");

	 $("#tags_saved_text").ajaxError(function(event, request, settings){
	   $(this).hide().text('Uuups! Not saved :|').fadeIn('fast').fadeOut(10000); 
	 });


			return false;
		});

   }
   
   //ratings
   
   $(".rate-submit").hide();
   
   $('.hover-star').rating({ 
  focus: function(value, link){ 
    var tip = $('#rating-text');
    tip.stop().css('opacity','1')
     tip.removeClass("ratingTextMessage");
    tip.html(link.title || 'value: '+value); 
  }, 
  blur: function(value, link){ 
    var tip = $('#rating-text');
    if(!tip.hasClass("ratingTextMessage")) {
    	tip.html(''); 
    }
  },
  callback: function(value, link){ 
  	eid = $(this.form).children("input[name='eid']").attr("value");
		$.post("ajax-rate.php", { rating: value, eid: eid},
		  function(data){
		  	$('#rating-text').addClass("ratingTextMessage").stop().css('opacity','1').hide().html(data.replay).fadeIn('fast').fadeOut(5000); 
		  },'json');

  }  
	});
 });

