/**
 * Jocurile.us 0.2.0
 **/

 /*
 *Cand DOM este gata bindauim event-uri si ascundem element etc...
 */
$(document).ready(function(){
//Overimg popup effect
/*
*$('.fresh').hover(function() {
 $(this).css('position','relative');
 $(this).animate({
  left: '-15',
  height: '100',
  top: '-8',
  width: '140',
  border: '2px solid rgb(0, 255, 204)'
  }, 500, function() {
  // Animation complete.
  });},
  function(){
  $(this).animate({
  left: '0',
  height: '87',
  top: '0',
  width: '110',
  border: '0px solid #FFFFFF'
  }, 500, function() {
  $(this).css('position','inherit');
  });
});
*
*/
//end overimg popup effect


//Only if we are on the game page
if($('#joc').length){


var timer = 10000;
progress = $('.progress');
loader = 0;
loadInt = Math.ceil((Math.random()+0.7)*10);

var t = setInterval(function(){
    progress.css('width', loader+'%');
    $('#ap_pb_text').text(Math.ceil(loader)+'%');
    loader += Math.random();
    if(Math.floor(loader) >= 99){
    clearInterval(t);
    DoAdCleanup();
    }
	if(Math.ceil(loader) >= loadInt && loadInt < 18){
	$('#placeholder').css('display','none');
	$('#skip').css('display','');
	}
     },timer/100);

  $('#togglecom').hide();
  $('#togglerep').hide();
 /*
 *Hook the button
 */
  $('#showrep').click(function() {
    $("#togglerep").animate({
      "height": "toggle",
      "opacity": "toggle"
    }, {
      duration: 600
    });
  });
  $('#showcomm').click(function() {
    $("#togglecom").animate({
      "height": "toggle",
      "opacity": "toggle"
    }, {
      duration: 600
    });
  });

}

$('#skip').live('click',function(){DoAdCleanup();clearInterval(t);});
});

/*
 * Ajax report post
 */
$(function() {

  $("#rep").click(function() {
    // validate and process form
    // first hide any error messages

    var email = $("input#email").val();
    if (email == "") {
      $("input#email").focus();
      return false;
    }
    var reports = jQuery.trim($("textarea#problema").val());
    if (reports == "") {
      $("textarea#problema").focus();
      return false;
    }

    var fileid = $("input#fileid").val();
    var nume = $('h4 > b').html();
    var dataString = 'email=' + email + '&comment=' + reports ;

    $.ajax({
      type: "POST",
      url: "/file.php?action=report&id="+ fileid + "&nume=" + nume,
      data: dataString,
      success: function() {
        $('#reports').html("<div id='message'></div>");
        $('#message').html("<h2>Raportul a fost adaugat!</h2>")
        .append("<p>Problema va fi rezolvata curand.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='http://www.mybarbie.biz/templates/barbie/images/check.png' />");
        setTimeout( function(){$("#togglerep").fadeOut("fast");}, 2000);
        });
      }
    });
    return false;
  });
});
/*
 * Ajax comments post
 */
$(function() {

  $("#addcomm").click(function() {
    // validate and process form
    // first hide any error messages

    var name = jQuery.trim($("input#name").val());
    if (name == "") {
      $("input#name").focus();
      return false;
    }
    var comment = jQuery.trim($("textarea#comment").val());
    if (comment == "") {
      $("textarea#comment").focus();
      return false;
    }

    var fileid = $("input#fileid").val();
    var dataString = 'nume=' + name + '&message=' + comment ;

    $.ajax({
      type: "POST",
      url: "/file.php?action=addcomment&id="+ fileid,
      data: dataString,
      success: function() {
        $('#comments').html("<div style=\"height: 97px;margin-left:65px;margin-top:17px;\" id='message'></div>");
        $('#message').html("<h2>Comentariu a fost adaugat!</h2>")
        .append("<p>Va dorim distractie placuta in continuare!.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img style=\"left:-35px;top:-45px;\" id='checkmark' src='http://www.mybarbie.biz/templates/barbie/images/check.png' />"); 
         setTimeout( function(){$("#togglecom").fadeOut("fast");}, 2000);
        });
      }
    });
    return false;
  });
});

function DoAdCleanup(){
  $('#ap_preroll').css('margin-bottom','0px');
  $('#joc').css('visibility','visible');
  $('#reclamasus').css('display','block');
  $('#ap_preroll').html('');
}
