$(document).ready(function(){
		$('a').click(function(){$(this).blur()});
		$(".thickbox, .stranavidojes a.playLinkVidoje").replaceAndBox({transition:"elastic"});

		$('.module-kontakt h3').click(function(){document.location.href='kontakt.php'});
		$('.stranafrontpage #levo .custommodule a').attr('href', 'paintabll/paintball-u-srbiji/tereni-za-paintball.html');
		$('.stranafrontpage #levo .blogitem .okvir').each(function(){
				var href = $(this).find('a').attr('href');
				$(this).find('img').wrap('<a href="'+href+'"></a>');
			});
		$('#vr form').submit(function(){
				if( $('#mod_search_searchword').val().length < 3 ){
					alert('Reč za pretragu mora imati 3 ili više slova');
					$('#mod_search_searchword').focus();
					return false;
				}
			});
});


$(document).ready(function(){
		$.fn.colorbox.settings.bgOpacity = "0.9";
		$("a.thickbox").colorbox({transition:"elastic", contentCurrent:""});
		$(".stranacontact .modulemapa a").colorbox({transition:"elastic", contentCurrent:""});
		$(".strana20 .custommodule-galerija-tereni a, .strana18 a.cmslink").colorbox({transition:"elastic", contentCurrent:""});
	});

$(document).ready( function() {
		$('.message').click(function(){$('.message').hide()});
		setTimeout("$('.message').hide()", 3000);
	});


$.fn.replaceAndBox = function(boxAttr,append){ 
	if( append == undefined ){
		append = '?&popup=1';
	}
	return this.each(function() {  
			$(this).attr('href', $(this).attr('href') + append);
			//			alert( $(this).attr('href') );return;
			$(this).colorbox(boxAttr);
		});
}

$(document).ready(function(){
		//		$('.strana23 .blog_all .blog_other h2').html('<a href="#" style="display:block;width:100%;height:100%" title="">&nbsp;</a>');
		$('.strana23 .blog_all .blog_other div.blog_inner_text').hide();
		$('.strana23 .blog_all .blog_other img.mosimage').hide();
		$('.strana23 .blog_all .blog_other div.blog_inner_text:first').show().css('width','830px');
		$('.strana23 .blog_all .blog_other img.mosimage:first').show();
		$('.strana23 .blog_all .blog_other h2:first').addClass('active');
 
		$('.strana23 .blog_all .blog_other h2').click(function(){
				$('.strana23 .blog_all .blog_other h2').removeClass('active');
				$(this).addClass('active');
				$('.strana23 .blog_all .blog_other div.blog_inner_text').hide();
				$('.strana23 .blog_all .blog_other img.mosimage').hide();
				$(this).parent().find('div.blog_inner_text').show().css('width','830px');
				var blogitems = $(this).parent().parent().attr('class').split(/ /);
				blogitemID =  parseInt( blogitems[1].replace(/[a-z]+/,'') );
				$('h1').css('background-position','-'+blogitemID*136+'px 0px');
				$(this).parent().parent().find('img').show();
				//				alert( '0px -'+blogitemID*136+'px');
				return false;
			});
});


/* vidoje !! */
function toggle(id) {
  if ( document.getElementById(id).style.display=="none")
    document.getElementById(id).style.display="";
  else
    document.getElementById(id).style.display="none";
}




var currentPlaylist = null;
var currentLength = 0;
var currentItem = -1; 
var previousItem = -1; 
var currentMute = false; 
var currentVolume = 80; 
var currentPosition = 0; 
var currentState = 'NONE';
var currentLoaded = 0;
var currentRemain = 0;

//var player = null;
function playerReady(thePlayer) {
	player = document.getElementById(thePlayer.id);
	addListeners();
}


function addListeners() {
	if (player) { 
		player.addControllerListener("ITEM", "itemListener");
		player.addControllerListener("MUTE", "muteListener");

		player.addModelListener("LOADED", "loadedListener");
		player.addModelListener("STATE", "stateListener");
		player.addModelListener("TIME", "positionListener");

		player.addViewListener("VOLUME", "volumeListener");
	} else {
		setTimeout("addListeners()",100);
	}
}


function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
}


function positionListener(obj) { 
	currentPosition = obj.position; 
	var tmp = document.getElementById("tim");
	if (tmp) { tmp.innerHTML = "position: " + currentPosition; }
}


function loadedListener(obj) { 
	currentLoaded = obj.loaded; 
	currentRemain = obj.total - currentLoaded;
	var tmp = document.getElementById("ldd");
	if (tmp) { 
		tmp.innerHTML = "bytes loaded: " + currentLoaded +
				"<br>bytes remaining: " + currentRemain; 
	}
}


function volumeListener(obj) { 
	currentVolume = obj.percentage; 
	var tmp = document.getElementById("vol");
	setCookie( 'pvolume', currentVolume );
	if (tmp) { tmp.innerHTML = "volume: " + currentVolume; }
}


function muteListener(obj) { 
	currentMute = obj.state; 
	var tmp = document.getElementById("mut");
	if (tmp) { tmp.innerHTML = "mute: " + currentMute; }
}


function itemListener(obj) { 
	if (obj.index != currentItem) {
 		previousItem = currentItem;
		currentItem = obj.index;

		if (previousItem == -1) { getPlaylistData(); }

		var tmp = document.getElementById("itm");
		if (tmp) { 
			tmp.innerHTML = "current item: " + currentItem +
				"<br>previous item: " + previousItem;
		}

		var tmp = document.getElementById("item");
		if (tmp) { tmp.innerHTML = "item: " + currentItem; }

		var tmp = document.getElementById("pid"); 
		if (tmp) { 
			tmp.innerHTML = "(received from the player with the id: <i><b>" + obj.id + "</b></i>)"; 
		} 

		printItemData(currentItem);
	}
}


function printItemData(theIndex) {
	var plst = null;
	plst = player.getPlaylist();

	if (plst) {
		var txt = '';
		txt += '<li><b>item number: </b>' + theIndex + ':</li>';
		txt += '<li><b>title: </b>' + plst[theIndex].title + '</li>';
		txt += '<li><b>author: </b>' + plst[theIndex].author + '</li>';
		txt += '<li><b>file: </b>' + plst[theIndex].file + '</li>';
		txt += '<li><b>image: </b>' + plst[theIndex].image + '</li>';
		txt += '<li><b>link: </b><a href="' + plst[theIndex].link + '">' + plst[theIndex].link + '</a></li>';
		//txt += '<li><b>description: </b>' + plst[theIndex].description + '</li>';

		var tmp = document.getElementById("itmsDat");
		if (tmp) { tmp.innerHTML = txt; }
	} 	
}


function getPlaylistData() { 
	var plst = null;
	plst = player.getPlaylist();

	if (plst) { 
		currentPlaylist = plst; 

		var txt = ''; 
		for(var i in currentPlaylist) { 
			txt += '<input type="checkbox" id="cb' + i + '" checked="checked" /> &nbsp; ';
			txt += currentPlaylist[i].title;
			txt += '<br />';
		}
		var tmp = document.getElementById("plstDat");
		if (tmp) { tmp.innerHTML = txt; }
	}	
}


function loadCheckedPlaylistData() { 
	if (currentPlaylist) { 
		var j = 0; 
		var lst = new Array();
		for(var i in currentPlaylist) { 
			if(document.getElementById('cb' + i).checked) {
				lst[j] = {
					author:currentPlaylist[i].author,
					description:currentPlaylist[i].description,
					duration:currentPlaylist[i].duration,
					file:currentPlaylist[i].file,
					link:currentPlaylist[i].link,
					image:currentPlaylist[i].image,
					start:currentPlaylist[i].start,
					title:currentPlaylist[i].title,
					type:currentPlaylist[i].type
				}
				j++;
			}
		}
		if(lst.length > 0) { player.sendEvent('LOAD', lst); }
	}	
}


function getLength() { currentLength = player.getPlaylist().length; return(currentLength); };


function loadFile(theFile) { currentItem = -1; previousItem = -1; player.sendEvent('LOAD', theFile); };


function createPlayer(holderID) {
	//	return;
	var flashvars = new Array();
	if( getCookie( 'pstate' ) == '0' || getCookie( 'ppopup' ) == '1' ){
		flashvars['autostart']="false";
	}
	else{
		if( !/Linux/.test(navigator.platform.test)){
		//		alert( 'pstate: '+getCookie( 'pstate' )+',volume: '+getCookie('pvolume') );
			flashvars['autostart']="true";
		}
		else{
			flashvars['autostart']="false";
		}
	}
	flashvars['skin']="http://www.odmorise.net/negative/playerskins/negative.swf";
	if( !isdefined('playlist') ){
		flashvars['file'] = "media/negative.xml";
	}
	else{
		flashvars['file'] = playlist;
	}
	if( ( vol = getCookie('pvolume') ) !== ''){
		flashvars['volume'] = vol;
	}
	var params = {
	allowfullscreen:"true", 
	allowscriptaccess:"always"
	}
	var attributes = {
	id:"playerBre",  
	name:"playerBre"
	}
	swfobject.embedSWF("player.swf", holderID, "320", "32", "9.0.115", false, flashvars, params, attributes);
	player = document.getElementById('playerBre');
}

function isdefined( variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}



function setCookie(n, v) {
	var cookieStr = "";
	var date = new Date();
	date.setTime(date.getTime()+(3*30*24*60*60*1000));
	var expiry = "; expires="+date.toGMTString();
	cookieStr = n + " = " + v + ";expires="+expiry+";path=/ "  ;
	document.cookie = cookieStr;
}

function getCookie(c_name){
	if (document.cookie.length>0){
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1){ 
					c_start=c_start + c_name.length+1; 
					c_end=document.cookie.indexOf(";",c_start);
					if (c_end==-1) c_end=document.cookie.length;
					return unescape(document.cookie.substring(c_start,c_end));
				} 
		}
	return "";
}

