

(function(){
  var
  img = null,
  texta = null,
  autoanimate = true,
  timeOut = null,
  lastitem = 0,
  animateTimeOut = 5000,
  data = [],
  dataloaded = false,
  initiated = false,
  ready = false,
  animate = function() {
    if (!autoanimate) {
    // do nothing
    } else if(img && texta) {
      var item;
      if (data[lastitem + 1]) {
        item = data[lastitem + 1];
        lastitem = lastitem + 1;
      } else {
        item = data[0];
        lastitem = 0;
      }
      if (item.imgpath)
        img.attr('src', item.imgpath).show();
      else
        img.hide();
      texta.text(item.text).attr('href', item.link);
      if (data.length > 1) {
        timeOut = setTimeout(function() {
          animate()
        }, animateTimeOut);
      }
    }
  },
  setAutoanimate = function(set) {
    if (timeOut)
      clearTimeout(timeOut);
    autoanimate = set;
    if (autoanimate)
      timeOut = setTimeout(function() {
        animate()
      }, animateTimeOut);
  },
  initiate = function() {
    if (!initiated && dataloaded) {
      initiated = true;
      if (data.length > 0) {
        img = $('#latesttopjobs td.img img');
        texta = $('#latesttopjobs table.description a');
        $('#latesttopjob').parent()
        .mouseenter(function(){
          setAutoanimate(false);
        })
        .mouseleave(function(){
          setAutoanimate(true);
        });
        autoanimate = true;
        animate();
      }
    }
  };

  /*  $.post($('head base').attr('href') + 'json.php?controller=default&action=indexboxads', {}, function(j, textStatus) {
    if (textStatus == 'success' && j.data) {
      data = j.data;
      lastitem = j.randomkey;
      if (j.data[j.randomkey]) {
        $('#latesttopjobs table.description a').text(j.data[j.randomkey].text).attr('href', j.data[j.randomkey].link);
        if (j.data[j.randomkey].imgpath)
          $('#latesttopjobs td.img img').attr('src', j.data[j.randomkey].imgpath);
        dataloaded = true;
        if (ready)
          initiate();
      }
    }
    }, 'json');*/
  
  $(document).ready(function() {
    $('#latesttopjobs a:last').unbind('click');
    ready = true;
    initiate();
  });

})();


function validateEmail(email) 
{ 
  var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
  return email.match(re) 
}


function signUp(email) {
  if (validateEmail(email)) {
    $.post(BASEURL + "ajax.php?controller=user&action=registernewuser", { email: email }, function(data) {
	    
    result = eval( "(" + data + ")" );
    if(result.status == "error") {
	openSignupErrorBox();
    }
    else {
      location.href = result.data;
    }
    });
  }
  else {
      openSignupErrorBox();
  }
}



  function openSignupErrorBox() {
	var TBemailError = $.thickbox.attach(null, {
	  contentSelector : '#TBEmailError',
	  closeSelector : '#TBEmailError .buttons a'
	});
	$.thickbox.show(TBemailError);
  }

