
function hide(element) {
$("#"+ element).fadeOut("slow");
}

function show(element) {
$("#"+ element).fadeIn("slow");
}

function toggle(element) {
$("#"+ element).slideToggle("slow");
}


function fadeto(element, percent) {
$("#"+ element).fadeTo("slow", percent);
}


function send(page, letter, fieldnum, lenght) {
	$.post(page, { letter: letter, fieldnum: fieldnum, lenght: lenght },
	  function(data){
		// alert("Data Loaded: " + data);
		$("#shipsplacement").empty();
		$("#shipsplacement").append(""+ data);

	  });
}

function fight(letter, fieldnum) {
	$.post('includes/ships_battle.php', { letter: letter, fieldnum: fieldnum },
	  function(data){
		// alert("Data Loaded: " + data);
		$("#battle").empty();
		$("#battle").append(""+ data);

	  });
}



function smiley(TheValue){
document.getElementById("slika_post_komentar").value += TheValue + ' ';
}


function loadpage(div, page) {
	$("#"+ div).load(page);	
}


function check()
{
   var refreshId = setInterval(function() 
   {
		$('#battle').load('includes/ships_battle.php');
		$('#history').load('includes/history.php');
		$('#check').load('includes/check.php');  

   }, 2000);
   
}

function compare() {
   var refreshId = setInterval(function() 
   {	
		if($("#myplayid").html() != $("#nowplaying").html()) {
				$("#lastplayed").empty();
				$("#lastplayed").append($("#nowplaying").html());
		}
  
		if($("#myplayid").html() == $("#nowplaying").html()) {
			if($("#lastplayed").html() != $("#nowplaying").html()) {
				//alert("Equal");
				sound();
				$("#lastplayed").empty();
				$("#lastplayed").append($("#nowplaying").html());
			}
		}


		
	
	}, 2000);
}

function checkforjoin() {
   var refreshId = setInterval(function() 
   {	
		$("#checkforjoin").load('includes/check_for_join.php');
	}, 2000);
}

function prepare() {
	
   var soundrefresh = setInterval(function() 
   {	
		placeship();
		clearInterval(soundrefresh);
	}, 2000);
}


function match_end() {
   	clearInterval(refreshId);
}

function placeship() {
	soundManager.play('placeship');	
}

function sound() {
	soundManager.play('play');	
}

function language(lang) {
	$.cookie('language', lang, { expires: 20 });
	if(lang == 'en') {
		var text = 'Language changed !';
	}
	if(lang == 'yu') {
		var text = 'Jezik promjenjen';
	}
	
	$("#languagename").empty();
	$("#languagename").prepend(text);
	$("body").load('index.php');
}


function new_table(msg_to_ask, msg_confirm) {
	var answer = confirm (msg_to_ask)
	if (answer) {
		alert (msg_confirm);
		clean_table();
	}
	else {
		return false;
	}
}

function clean_table() {
	$("#nonexistingelement").load('includes/clean_table.php');
	send('includes/placeship.php', '', '', '');
}

$(document).ready(function() {
	$('#howtoplay').addClass('explanation');
	$('#last10matches').addClass('explanation');
	$('#whatisbattleships').addClass('explanation');
	
	FB.init("068296f091b7b235aa9c63a4409b9e31", "xd_reciever.html");
});

function callPublish(msg, image, description, caption, name, url, question) {
  FB.ensureInit(function () {
	var attachment = {'media':[{'type':'image','src':''+ image,'href':'http://apps.facebook.com/mybattleships/'}], 'description':'' + description, 'caption':''+ caption, 'name':'' + name, 'href':'' + url};
    FB.Connect.streamPublish('', attachment, null, null, question);
  });
}

function callPublish2(msg, image, image2, description, caption, name, url, question){
FB.ensureInit(function () {
	var attachment = {'media':[{'type': 'image', 'src': ''+image, 'href':'http://apps.facebook.com/mybattleships/'}, {'type': 'image', 'src': ''+image2, 'href':'http://apps.facebook.com/streetiagame/'}], 'description':'' + description, 'caption':''+ caption, 'name':'' + name, 'href':'' + url};
	FB.Connect.streamPublish('', attachment, null, null, question);
});
}


