function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

function likeIt(val){
  $("#divPic" + val).fadeOut("slow",function(){
  $.get("http://creoflick.net/vote.php", { id: val},
  function(data){
      xmlResponse = data;
      xmlRoot = xmlResponse.documentElement;
      picture = xmlRoot.getElementsByTagName("picture");
	  vote = xmlRoot.getElementsByTagName("vote");
	  pid = xmlRoot.getElementsByTagName("pid");
	  PMessage = picture.item(0).firstChild.data;
	  VMessage = vote.item(0).firstChild.data;
	  id = pid.item(0).firstChild.data;
	  
	  document.getElementById("divPic" + id).innerHTML = PMessage;
	  $("#divPic" + id).fadeIn("slow");	
	  
	  $("#divVoted" + id).fadeOut("slow",function(){
	  document.getElementById("divVoted" + id).innerHTML = VMessage;
	  });
	  $("#divVoted" + id).fadeIn("slow");
  });
  });
}

function submitLink(){
  var li = document.getElementById("link_f").value;
  var com = document.getElementById("comment_f").value;
  $("#popup_submit_inside").fadeOut("slow",function(){
	$.post("http://creoflick.net/submit.php", { li: li, com: com},
    function(){
      var tekst = '<IMG SRC="http://creoflick.net/gfx/new/favorite.png" WIDTH="64" HEIGHT="64" BORDER="0" ALT="Favourite" style="position:relative; top: 25px; left: -10px;">Thx! We will check your link as soon as possible!' ;
	  document.getElementById("popup_submit_inside").innerHTML = tekst;
	  $("#popup_submit_inside").fadeIn("slow");	
	});
  });
}


function sendMail(){
  var li = document.getElementById("mail_f").value;
  var com = document.getElementById("email_f").value;
  $("#popup_sendMail_inside").fadeOut("slow",function(){
	$.post("http://creoflick.net/submit.php", { li: li, com: com},
    function(){
      var tekst = '<IMG SRC="http://creoflick.net/gfx/new/mail.png" WIDTH="64" HEIGHT="64" BORDER="0" ALT="Email"  style="position:relative; top: 25px; left: -10px;">Thx! We will answer as soon as possible.' ;
	  document.getElementById("popup_sendMail_inside").innerHTML = tekst;
	  $("#popup_sendMail_inside").fadeIn("slow");	
	});
  });
}

function searchValidate(searchString){
  if (searchString.length < 3){
    document.sform.search.value = "need at least 3 letter";
	return false;
  }
  else{
    document.sform.submit();
	return true;
  }
}
