$(document).ready(function() {

  $(".show_more").hide();
  $("#more_btn").click(
    function () {
      $("#more_btn").hide();
      $(".space_keeper").hide();
      $(".hide_block").hide();
      $("#hide_btn").show();
      $(".more_block").slideDown('slow');
    });
    
    $("#hide_btn").click(
    function () {
      $("#hide_btn").hide();
      $(".more_block").slideUp('slow');
      $(".hide_block").slideDown();
      $("#more_btn").fadeIn('slow');
    });
    
  $(".more_btn").click(
    function () {
      $(this).hide();
      $(this).parent().hide("slow");
      $(this).parent().next().slideDown("slow");
      
      if (_gaq){
		  _gaq.push(['_trackPageview', '/p/'+project+'/more/'+$(this).parent().parent().parent().attr('name')]);
      }
    });
    
  $(".show_iframe_preview").click(function () {
	  $(this).next(".iframe_preview").toggle();
  });
  
  $("#right_choice").hide();
  $("#left_choice").show();
  $("#left_choice_btn").hover(
  	function () {
     $("#right_choice").hide();
  	 $("#left_choice").show();
  });

  $("#right_choice_btn").hover(
  	function () {
  	 $("#left_choice").hide();
  	 $("#right_choice").show();
  });
  
if ($("#ad_preview").length != 0){
	 // bind event for iframe preview
	 $("#id_name").keyup(iframe_preview); 
	 
	 // run iframe preview at start
	 iframe_preview(); 
}

/*
 * if ($("#id_amount").val() == ''){ $("#id_amount").val('Amount $'); }
 * 
 * $("#id_amount").click(function() { if ($(this).val()=='Amount $') {
 * $(this).val(''); $(this).css("font-weight","bold"); } })
 * 
 * if ( $("#id_email").val() == ''){ $("#id_email").val('Email'); }
 * 
 * $("#id_email").click(function() { if ($(this).val()=='Email') {
 * $(this).val(''); } })
 */  
  if ( $("#id_confirmation_key").val() == ''){
    $("#id_confirmation_key").val('Confirmation key');
  }
  
  $("#id_confirmation_key").click(function() {
	  if ($(this).val()=='Confirmation key') {
		  $(this).val('');
	  }
  })
  
  if ( typeof(sbi) != "undefined" ) {
    setTimeout(confirm_check, 2000);
  }
  
  $(".new_window_link").click(function() {
    window.open(this.href);
    return false;
  })
  $("#close").click(function() {
  	window.close();
  })
  
  $(".btn-mini").mouseover(function() { $(this).css("background-position","-50px 0px"); });
  $(".btn-mini").mouseout(function() { $(this).css("background-position","0px 0px"); });
  
  $(".btn-small").mouseover(function() { $(this).css("background-position","-100px -30px"); });
  $(".btn-small").mouseout(function() { $(this).css("background-position","0px -30px"); });
  
  $(".btn-normal").mouseover(function() { $(this).css("background-position","-150px -60px"); });
  $(".btn-normal").mouseout(function() { $(this).css("background-position","0px -60px"); });
  

      $(".question_mark").hover(function(e){
          var obsah = $("#tt"+this.id[1]).text();
          $('<div id="hov_div">'+obsah+'</div>')
            .css('top',e.pageY + 10)
            .css('left',e.pageX + 20 )
            .appendTo('body');
        
	      },function(){
	        $('#hov_div').remove();
      });
      
      $('.question_mark').mousemove(function(e){
        $('#hov_div').css('top',e.pageY + 10).css('left',e.pageX + 20);
      });
      $('.question_mark').mouseout(function(e){
        $('#hov_div').remove();
      });
      
      $(".hover_above").hover(function(e){
          var obsah = $("#tt"+this.id[1]).text();
          $('<div id="hov_div"><div class="three-block-head-'+this.id[1]+'"></div>'+obsah+'</div>')
            .css('top',e.pageY + 10)
            .css('left',e.pageX + 20 )
            .appendTo('body');
        
	      },function(){
	        $('#hov_div').remove();
      });
      
      $('.hover_above').mousemove(function(e){
        $('#hov_div').css('top',e.pageY + 10).css('left',e.pageX + 20);
      });
      $('.hover_above').mouseout(function(e){
        $('#hov_div').remove();
      });

      $('.want_know').click(function(){
		$(this).next('.show_more').toggle('fast', function() {  });
		
      });

      $('.rpx_social').click(function(){
      	domain = "http://www.bidforfix.com";
      	if (typeof(rpx_social_text) === "undefined") {
			text = "The first platform to empower users of software project to fund development of new features.";      		
		}
		else{
			text = rpx_social_text;
		}

		RPXNOW.loadAndRun(['Social'], function () {
	      var activity = new RPXNOW.Social.Activity(
	       "",
	       text,
	       rpx_share_url);
	      if (typeof(rpx_title) !== "undefined") {
	    	  activity.setTitle(rpx_title);
	      }
	      RPXNOW.Social.publishActivity(activity, { postTruncation: true });
	  });
		
      });

});


function confirm_check(){
   var pom= $.ajax({
       type: "POST",
       url: "/a/confirmed/",
       data: {sbi:sbi},            
       async: false,
   }).responseText;
   
   if (pom =='1'){
   	 $("#confirm_form").hide();
  	 $("#confirm_response").show();
   }
   else{
   	 setTimeout(confirm_check, 4000);
   }
}

function iframe_preview(){
	 $.ajax({
		 url: '/ads/iframe_preview/',
		 cache: false,
		 success: function(data){
		    $("#ad_preview").html(data);
		 },
		 data: ({text: $("#id_name").val()}),
		 type: "POST"
	 });
}


