window.onload = function() {
	/* fix the flash elements for IE browsers */
	flashObjects = document.getElementsByTagName("object");
	for (var i = 0; i < flashObjects.length; i++) {
		flashObjects[i].outerHTML = flashObjects[i].outerHTML;
	}
}

/* document ready function */
$(document).ready(function(){
	/* activate lightBox plugin */
	$("a.lightboxImage").lightBox({
		txtImage: 'Slika',
		txtOf: 'od'
	});
});

function congrats(idVoscilnice, visina_popup) {
	day = new Date();
	id = day.getTime();
	URL = "pop-up-congrats.php?id=" + idVoscilnice;
	leftOffset = (screen.width - 600) / 2;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=0, width=600, height=" + visina_popup + ", left=" + leftOffset + ", top=100');");
}

function dropdownVisible(a) {
	if (a == 1) {
		document.getElementById('dropdown').style.display = 'block';
		document.getElementById('aDrop').onMouseOver = '';
	}
		else document.getElementById('dropdown').style.display = 'none';
}

function tell_a_friend(nid) {
	day = new Date();
	id = day.getTime();
	URL = "tell_a_friend.php?news=" + nid;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=370,height=265,left = 440,top = 200');");
}

function play_a_game(gid) {
	day = new Date();
	id = day.getTime();
	URL = "game.php?id=" + gid;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=660,height=550,left = 250,top = 120');");
}

function ajaxGallery(position, gallery) {
	// position: 0 = top 4 galleries, 1 = bottom 4 galleries
	// gallery: gallery ID in the database
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// something went wrong
				alert("Vaš brskalnik žal ne podpira AJAX tehnologije.");
				return false;
			}
		}
	}
	// create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if (position == 0) document.getElementById('upperGalleries').innerHTML = ajaxRequest.responseText;
			else if (position == 1) document.getElementById('lowerGalleries').innerHTML = ajaxRequest.responseText;
		}
	}
	
	// we get the appropriate data	
	var timeQuery = new Date();
	timeGET = timeQuery.getTime();
	var queryString = "?gallery=" + gallery + "&position=" + position + "&time=" + timeGET;
	ajaxRequest.open("GET", "ajax-gallery.php" + queryString, true);
	ajaxRequest.send(null);
}

function ajaxPoll(id_poll, user_is_voting) {
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// something went wrong
				alert("Vaš brskalnik žal ne podpira AJAX tehnologije.");
				return false;
			}
		}
	}
	// create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('pollOptions').innerHTML = ajaxRequest.responseText;
			document.getElementById('pollCommands').innerHTML = "";
		}
	}
	
	// we get the appropriate data
	var id_vote = 0;
	for (var i = 0; i < document.getElementsByName('poll').length; i++) {
		if (document.getElementsByName('poll')[i].checked) id_vote = document.getElementsByName('poll')[i].value;
	}
	
	if (id_vote == 0 || user_is_voting == 0) id_vote = 0;	// id_vote = 0 means that we just show the results
	
	var timeQuery = new Date();
	timeGET = timeQuery.getTime();
	var queryString = "?id_poll=" + id_poll + "&id_vote=" + id_vote + "&time=" + timeGET;
	ajaxRequest.open("GET", "ajax-poll.php" + queryString, true);
	ajaxRequest.send(null);
}

function ajaxCalendarDay(news_id, day) {
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// something went wrong
				alert("Vaš brskalnik žal ne podpira AJAX tehnologije.");
				return false;
			}
		}
	}
	// create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('photoAndGalleryContainer').innerHTML = ajaxRequest.responseText;
		}
	}
	
	document.getElementById('photoAndGalleryContainer').innerHTML = "<div id=\"photoAndGalleryTop\"><!-- --></div><div id=\"photoAndGalleryBody\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#E61187; font-weight:bold; font-size:14px;\">... prosimo, počakajte ...</span></div> <!-- photoAndGalleryBody -->	<div id=\"photoAndGalleryBottom\"><!-- --></div><div style=\"margin-top:5px;\">&nbsp;</div>";
	var timeQuery = new Date();
	timeGET = timeQuery.getTime();
	var queryString = "?nid=" + news_id + "&day=" + day + "&time=" + timeGET;
	ajaxRequest.open("GET", "ajax-calendar-day.php" + queryString, true);
	ajaxRequest.send(null);
}

function beleziKlik(id,link) {
	$.post('http://www.tocnoto.si/sponsor-redirect.php?id='+id+'&url='+link);
}