var AddressBookGMap =
{
	items: {},
	typesIx: {},

	itemsArea: {}, // ako za postavljanje podrucja ne nadem u items onda gledam u itemsArea
	typesAreaIx: {},

	g_map: null,

	// def podaci za http://maps.google.com/maps?q=croatia&z=7
	def_lat:45.81252930977015,
	def_lon:15.976181030273438,
	def_zoom:12,
	g_def_latlon: null,

	item_area_zoom: 14,
	item_zoom: 16,

	open_info_window_item_id: 0, // sadrzi id item-a koji ima trenutno otvoreni prozor infowindow

	g_icons: {}, // assoc niz koji sadrzi ikone za razlicite tipove

	_showMarkerVisibility: {},

	// poziva se NAKON addItem!
	createMap: function(elementId)
	{
		if (typeof('GBrowserIsCompatible') != 'undefined' && GBrowserIsCompatible())
		{
			AddressBookGMap.g_def_latlon=new GLatLng(AddressBookGMap.def_lat, AddressBookGMap.def_lon);
			AddressBookGMap.g_map = new GMap2( document.getElementById(elementId) );
			AddressBookGMap.g_map.setCenter(AddressBookGMap.g_def_latlon, AddressBookGMap.def_zoom );
			AddressBookGMap.g_map.addControl( new GLargeMapControl() );
			AddressBookGMap.g_map.addControl( new GMenuMapTypeControl() );
			AddressBookGMap.g_map.enableContinuousZoom();
			AddressBookGMap.g_map.enableInfoWindow();

			AddressBookGMap._createIcons();

			AddressBookGMap._createMarkers();
		}
	},

	_createIcons: function()
	{
		for(type in AddressBookGMap.typesIx)
		{
			if(typeof( AddressBookGMap.g_icons[type] ) != 'undefined' )
				continue;

			/*
			switch(type)
			{
				case 'lokacije':
				{
					AddressBookGMap.g_icons[type]=new GIcon();
					AddressBookGMap.g_icons[type].image = '/images/gmaps/google-flag-business.png';
					AddressBookGMap.g_icons[type].shadow = '/images/gmaps/google-flag-small-shade.png';
					AddressBookGMap.g_icons[type].iconSize = new GSize(40, 35);
					AddressBookGMap.g_icons[type].shadowSize = new GSize(40, 35);
					AddressBookGMap.g_icons[type].iconAnchor = new GPoint(2, 31); // relativno top/left
					AddressBookGMap.g_icons[type].transparent = '/images/gmaps/google-flag-business-empty.png';
					AddressBookGMap.g_icons[type].infoWindowAnchor = new GPoint(11, 0) // relativno top/left
					AddressBookGMap.g_icons[type].imageMap=[
															1,2,
															3,0,
															28,0,
															30,2,
															30,24,
															28,26,
															8,26,
															3,31,
															1,31
															];

					AddressBookGMap.g_icons[type].printImage = '/images/gmaps/google-flag-business.gif';
					AddressBookGMap.g_icons[type].mozPrintImage = '/images/gmaps/google-flag-business.gif';
					AddressBookGMap.g_icons[type].printShadow = '/images/gmaps/google-flag-small-shade.gif';
				}
				break;
			} // switch
			*/

		} // for
	},

	_getIcon: function(type)
	{
		if(typeof( AddressBookGMap.g_icons[type] ) == 'undefined')
			return G_DEFAULT_ICON;

		return AddressBookGMap.g_icons[type];
	},

	clearItems: function()
	{
		AddressBookGMap.items={};
		AddressBookGMap.typesIx={};

		AddressBookGMap.itemsArea={};
		AddressBookGMap.typesAreaIx={};
	},

	// poziva se PRIJE createMap
	addItem: function(id, type, name, address, city_name, tel, tel_2, fax, email, map_lat, map_lon)
	{
		var obj={};

		obj.id=id;
		obj.type=type;
		obj.name=name;
		obj.address=address;
		obj.city_name=city_name;
		obj.tel=tel;
		obj.tel_2=tel_2;
		obj.fax=fax;
		obj.email=email;
		obj.map_lat=parseFloat(map_lat);
		obj.map_lon=parseFloat(map_lon);

		obj.g_latlon=new GLatLng(obj.map_lat, obj.map_lon);

		obj.g_marker=null; // u addMarkers


		obj.html = AddressBookGMap._createHtml(obj);

		AddressBookGMap.items[id]=obj;

		if(typeof( AddressBookGMap.typesIx[obj.type] ) == 'undefined')
		{

			AddressBookGMap.typesIx[obj.type]=new Array();
		}

		AddressBookGMap.typesIx[ obj.type ][ AddressBookGMap.typesIx[ obj.type ].length ] = obj.id;
	},



	// poziva se PRIJE createMap
	// stavke za zumiranje na area ako nemam odredenu stavku u items ... za adresar mi ne treba ali mi treba za stete!
	addItemArea: function(id, type, name, address, city_name, tel, tel_2, fax, email, map_lat, map_lon)
	{
		var obj={};

		obj.id=id;
		obj.type=type;
		obj.name=name;
		obj.address=address;
		obj.city_name=city_name;
		obj.tel=tel;
		obj.tel_2=tel_2;
		obj.fax=fax;
		obj.email=email;
		obj.map_lat=parseFloat(map_lat);
		obj.map_lon=parseFloat(map_lon);

		obj.g_latlon=new GLatLng(obj.map_lat, obj.map_lon);

		obj.g_marker=null; // u addMarkers


		obj.html = AddressBookGMap._createHtml(obj);

		AddressBookGMap.itemsArea[id]=obj;

		if(typeof( AddressBookGMap.typesAreaIx[obj.type] ) == 'undefined')
		{
			AddressBookGMap.typesAreaIx[obj.type]=new Array();
		}

		AddressBookGMap.typesAreaIx[ obj.type ][ AddressBookGMap.typesAreaIx[ obj.type ].length ] = obj.id;
	},

	_createMarkers: function()
	{
		if(!AddressBookGMap.g_map)
			return;

		for(var i in AddressBookGMap.items)
		{
			var item = AddressBookGMap.items[i];

			item.g_marker=new GMarker(item.g_latlon, AddressBookGMap._getIcon( item.type )  );
			item.g_marker.crosig_address_item_id = item.id;

			GEvent.addListener(item.g_marker, "click", function()
											{
												if( this.crosig_address_item_id != AddressBookGMap.open_info_window_item_id )
												{
													AddressBookGMap.g_map.closeInfoWindow();
													var obj=AddressBookGMap.items[ this.crosig_address_item_id ];
													this.openInfoWindowHtml( obj.html );
												}
											});

			GEvent.addListener(item.g_marker, "infowindowclose", function()
					{

						AddressBookGMap.open_info_window_item_id = 0;
					});

			GEvent.addListener(item.g_marker, "infowindowopen", function()
					{

						AddressBookGMap.open_info_window_item_id = this.crosig_address_item_id;
					});


			if( AddressBookGMap._showMarkerVisibility[item.type] )
			{
				item.addOverlay=true;
				AddressBookGMap.g_map.addOverlay( item.g_marker );
			}
			else
			{
				item.addOverlay=false;
			}

		} // for
	},

	showMarkers: function(type, status, setCookieType)
	{
		if(typeof( AddressBookGMap.typesIx[type] ) == 'undefined' )
		{
			return;
		}

		if(typeof(setCookieType) == 'undefined')
		{
			setCookieType=false;
		}

		for(var i=0; i<AddressBookGMap.typesIx[type].length; i++)
		{
			var itemIx=AddressBookGMap.typesIx[type][i];
			var item=AddressBookGMap.items[ itemIx ];

//							alert('('+item.id+')('+item.name+')');

			if(status && (item.g_marker.isHidden() || !item.addOverlay))
			{
				if(!item.addOverlay)
				{
					item.addOverlay=true;
					AddressBookGMap.g_map.addOverlay( item.g_marker );
				}
				else
				{
					item.g_marker.show();
				}
			}
			else if( !status && !item.g_marker.isHidden())
			{
				item.g_marker.hide();
			}
		} // for


		if(setCookieType)
		{
			if(cookieDomainName)
				$.cookie('adr_' + type, status ? 1 : 0, {expires:365, path:'/', domain:cookieDomainName} );
			else
				$.cookie('adr_' + type, status ? 1 : 0, {expires:365, path:'/'} );
		}

	},

	setMapDefault:function()
	{
		if(!AddressBookGMap.g_map)
			return;

		AddressBookGMap.g_map.closeInfoWindow();
		AddressBookGMap.g_map.setCenter(AddressBookGMap.g_def_latlon, AddressBookGMap.def_zoom );
	},

	setMapItem: function(id)
	{
		if(!AddressBookGMap.g_map)
			return;

		if(typeof ( AddressBookGMap.items[id] ) == 'undefined' )
			return;


		AddressBookGMap.g_map.setCenter(
												  AddressBookGMap.items[id].g_latlon,
												  AddressBookGMap.item_zoom
												);
		
		AddressBookGMap.g_map.closeInfoWindow();
		
		
		//var obj=AddressBookGMap.items[id];
		//AddressBookGMap.g_map.openInfoWindowHtml( obj.html );
		AddressBookGMap.items[id].g_marker.openInfoWindowHtml( AddressBookGMap.items[id].html );
		
	},

	setMapArea: function(id)
	{
		if(!AddressBookGMap.g_map)
			return;

		if(! (typeof ( AddressBookGMap.items[id] ) == 'undefined' ) )
		{
			AddressBookGMap.g_map.setCenter(
												  AddressBookGMap.items[id].g_latlon,
												  AddressBookGMap.item_area_zoom
												);
		}
		else if(! (typeof ( AddressBookGMap.itemsArea[id] ) == 'undefined' ) )
		{
			AddressBookGMap.g_map.setCenter(
												  AddressBookGMap.itemsArea[id].g_latlon,
												  AddressBookGMap.item_area_zoom
												);
		}
	},







	_createHtml: function(obj)
	{
		var  html='<div class="google_office"><h6 class="office_name">'+obj.name+'<'+'/h6>';

		if(obj.address)
			html+='<dl>' +
					'<dt>Adresa:<'+'/dt>'+
					'<dd>'+obj.address+'<'+'/dd>'+
					'<'+'/dl>';

		if (obj.city_name)
			html+='<dl>' +
				'<dt>Mjesto:<'+'/dt>'+
				'<dd>'+obj.city_name+'<'+'/dd>'+
				'<'+'/dl>';

		if (obj.tel || obj.tel_2)
		{
			html+='<dl>' +
					'<dt>Tel:<'+'/dt>';

			if(obj.tel)
				html+='<dd>'+obj.tel+'<'+'/dd>';

			if(obj.tel_2)
				html+='<dd>'+obj.tel_2+'<'+'/dd>';

			html+='<'+'/dl>';
		}

		if(obj.fax)
			html+='<dl>' +
				'<dt>Fax:<'+'/dt>'+
				'<dd>'+obj.fax+'<'+'/dd>'+
				'<'+'/dl>';


		if(obj.email)
			html+='<dl>' +
				'<dt>Email:<'+'/dt>'+
				'<dd><a href="mailto>'+obj.email+'">'+obj.email+'<'+'/a><'+'/dd>'+
				'<'+'/dl>';

		html+='<'+'/div>';


		html+='<div class="map_control_alt">';
		html+='<p>';
		html+='<a href="#" onclick="AddressBookGMap.setMapItem('+obj.id+'); return false;" class="zoom">Zoom<'+'/a>';
		html+='<a href="#" onclick="AddressBookGMap.zoom('+obj.id+'); return false;" class="area">Područje<'+'/a>';
		html+='<a href="#" onclick="AddressBookGMap.zoom(0); return false;" class="def">Zagreb<'+'/a>';

		html+='<'+'/p>';
		html+='<'+'/div>';
		return html;
	},


	// zumira na podrucje ili na kartu te postavlja sel box na odgovarajucu vrijednost
	zoom: function(id)
	{
		var selBox=document.getElementById('podruznica_grad');

		if(typeof(id)=='undefined')
		{

			if(selBox.selectedIndex == 0)
				id = 0;
			else if(selBox.selectedIndex > 0 && selBox.selectedIndex < selBox.options.length)
				id = selBox.options[selBox.selectedIndex ].value;
			else
				return;
		}

		if(id==0)
		{
			AddressBookGMap.setMapDefault();
			selBox.selectedIndex=0;
		}
		else
		{

			AddressBookGMap.setMapArea(  id  );

			if( $('#podruznica_grad option[value='+id+']').length )
			{
				$('#podruznica_grad option[value='+id+']').attr('selected','selected');
			}
			else
			{
				selBox.selectedIndex=0;
			}
		}

	},


	setDefaultMarkerVisibility: function(opt)
	{
		AddressBookGMap._showMarkerVisibility=opt;
	}

}




/////////////////////// content edit
function submit_articleRemove(id, headline, refresh)
{
	id=parseInt(id);
	if( id<=0 || isNaN(id) )
		return false;
	
	if(typeof(refresh)=='undefined')
		refresh=0;
	
	if(!confirm('Remove article "'+headline+'"? Are you sure?'))
	{
		return false;
	}
	
	fwajax.phpExecute(
		{url: '/content/article-remove'},
		id,
		refresh
	);
	
	return false;
}

function callback_articleRemove(id, success, refresh, url)
{
	if(success && id)
	{
		if(refresh)
		{
			if(url)
			{
				window.location=url;	
			}
		}
		else
		{
			$('#article_' + id).remove();
		}
	}
	
	return false;
}


function submit_articleCommentLock(id, status, refresh)
{
	id=parseInt(id);
	if( id<=0 || isNaN(id) )
		return false;
	
	if(typeof(refresh)=='undefined')
		refresh=0;

	fwajax.phpExecute(
		{url: '/content/article-comment-lock'},
		id,
		status,
		refresh
	);
	
	return false;
}

function callback_articleCommentLock(id, success, lockStatus, refresh)
{
	if(id && success)
	{
		if(refresh)
		{
			window.location.reload(true);
		}
		else
		{
			if(lockStatus)
			{
				$('#zakljucaj_item_'+id).addClass('displaynone');
				$('#odkljucaj_item_'+id).removeClass('displaynone');
				
				$('#article_'+id+' h1').addClass('locked');
			}
			else
			{
				$('#zakljucaj_item_'+id).removeClass('displaynone');
				$('#odkljucaj_item_'+id).addClass('displaynone');
				$('#article_'+id+' h1').removeClass('locked');
			}
		}
	}
	
	return false;	
}



//////////////////////////////////////////////////////////////
//////////////////// comments ////////////////////////////////

function submit_commentVote(num, id)
{
	// startaj loader
	
	$('.commentVoting_' + id).hide();
	
	fwajax.phpExecute(
		{url: '/comment/commentvote'},
		num,
		id
	);
	
	return false;
}

function callback_commentVote(num, html, id)
{
	var obj=$('#comment_num_'  + id + '_state');
	
	obj.html(html);
	
	if (num < 0)
	{
		//obj.removeClass('numb');
		obj.addClass('neg');
	}
	else
	{
		//obj.addClass('numb');
		obj.removeClass('neg');
	}
/*
	fwajax.phpExecute(
		{url: '/comment/loadocjenekomentara'},
		id,
		0
	);

	// sakri loader
*/
}

function toggleSubComments(comment_id)
{
	//$('#comment_subcomments_' + comment_id).toggle();
	$('#comment_subcomments_' + comment_id).toggleClass('displaynone');

	$('#comment_subcomments_' + comment_id + '_link').toggleClass('opened');
	return false;
}

function submit_commentEdit(id, bestOf, isUser)
{
	if( typeof(bestOf)=='undefined' )
		bestOf=0;

	if( typeof(isUser)=='undefined' )
		isUser=0;

	if( $('#comment_edit_' + id).length )
	{
		$('#comment_extra_' + id).css('display', 'none');
		$('#comment_edit_' + id).remove();
		return false;
	}

	fwajax.phpExecute(
		{url: '/comment/commentedit'},
		id, bestOf, isUser
	);
	
	return false;
}

function callback_commentEdit( id, html )
{
	$('#comment_extra_' + id).html( html );
	$('#comment_extra_' + id).css('display', 'block');
}

function submit_commentEditSave( frm )
{
	var obj=$(frm);
	
	fwajax.phpExecute(
		{url: '/comment/commenteditsave'},
			obj.find('textarea[name=comment]').val(),
			obj.find('input[name=key]').val(),
			obj.find('input[name=best_of]').val(),
			obj.find('input[name=is_user]').val()
	);
	
	return false;
}

function callback_commentEditSave(id, txt, bestOf, isUser)
{
	if(typeof(bestOf)=='undefined')
		bestOf=0;

	if( typeof(isUser)=='undefined' )
		isUser=0;

	$('#comment_edit_' + id).remove();
	
	$('#comment_extra_' + id).css('display', 'none');

	if(bestOf != 0)
	{
		alert(txt);
	}
	else
	{
		$('#comment_txt_' + id).html(txt);

		$('#comment_txt_' + id + ' a.ext').attr({target: "_blank"});
	}
}

function submit_commentDelete(id)
{
	fwajax.phpExecute(
		{url: '/comment/commentdelete'},
			id
	);
	
	return false;
}

function callback_commentDelete(id, errorMsg)
{
	if (id == 0)
	{
		alert(errorMsg);
	}
	else
	{
		$('#comment_' + id).remove();
	}
}

function loadOcjeneKomentara(comment_id, show_voters)
{
	fwajax.phpExecute(
		{url: '/comment/loadocjenekomentara'},
		comment_id, show_voters
	);
}

function callback_loadOcjeneKomentara(html, show_voters, comment_id)
{
    $('#comment_voters_' + comment_id).html(html);
	if (show_voters == 1) {
        $('#comment_num_' + comment_id + '_state').addClass("opened");
		$('#comment_voters_' + comment_id).show();
	}
}

function submit_commentReply(id, level, article_id, odgovoriTxt, odustaniTxt)
{
	if( $('#comment_reply_' + id).length )
	{
		$('#comment_extra_reply_link_' + id).text(odgovoriTxt); 
		$('#comment_extra_reply_link_' + id).attr('title', odgovoriTxt); 
		$('#comment_reply_' + id).remove();
		
		$('#comment_extra_reply_' + id).css('display', 'none');
		return false;
	} else {
		$('#comment_extra_reply_link_' + id).text(odustaniTxt); 
		$('#comment_extra_reply_link_' + id).attr('title', odustaniTxt); 
	}

	fwajax.phpExecute(
		{url: '/comment/commentreply'},
		id, level, article_id
	);
	
	return false;
}

function callback_commentReply( id, level, article_id, html )
{
	$('#comment_extra_reply_' + id).html( html );
	$('#comment_extra_reply_' + id).css('display', 'block');
}

function submit_commentReplySave(frm, id, level, article_id)
{
	var obj=$(frm);
	

	
	fwajax.phpExecute(
		{url: '/comment/commentreplysave'},
		obj.find('textarea[name=comment]').val(),
		id, level, article_id,
		obj.find('#uvijeti_' + id).attr('checked') ? 1 : 0
	);
	
	return false;
}

function callback_commentReplySave( id, level, article_id, html, odgovoriTxt, brojOdgovoraTxt  )
{
	$('#form_reply_' + id + ' p.red').remove();
	
	//if ($('#comment_' + child_id).length) return;

    $('#comment_reply_' + id).remove();
    $('#comment_extra_reply_link_' + id).text(odgovoriTxt);				
	$('#comment_extra_reply_link_' + id).attr('title', odgovoriTxt);				

    $('#comment_subcomments_' + id).append(html);

    $('#comment_subcomments_' + id).removeClass('displaynone'); // .show()

    $('#comment_subcomments_' + id + '_link').removeClass('displaynone');
	
	$('#comment_subcomments_' + id + '_link').addClass('opened');

	var counter_text = $('#subcomments_counter_' + id).text();
	
	var number_var = Number( counter_text.substr(counter_text.indexOf(':')+1 ) );
	number_var = number_var + 1;

	//$('#subcomments_counter_' + id).text(number_var + ' odgovor' + padezi( number_var, 'a') );
	$('#subcomments_counter_' + id).text(brojOdgovoraTxt + ': ' + number_var ); 

	if(commentEditTimeoutHandle == 0)
	{
		commentEditCounter();
	}

	$('#comment_subcomments_' + id + ' a.ext').attr({target: "_blank"});
	
	
	$('#comment_extra_reply_' + id).css('display', 'none');
}

function callback_commentReplySaveReEnable(id, txt)
{
	$('#form_reply_' + id + ' p.red').remove();
	
	//alert('1');
	$('#reply_submit_button_' + id).removeAttr('disabled');
	//alert('2');
	
	// form_reply_{$comment_id}
	if(txt != '')
	{
		$('#form_reply_' + id).prepend( '<p class="red">' + txt + '</p>' );
	}
}

function toggleSubCommentsAll()
{
	var comment=0;
	if ($('#toggleSubComments_link').hasClass('close_all'))
	{
		comment=2;
		toggleSubCommentsAll_Open();
	}
	else
	{
		comment=1;
		toggleSubCommentsAll_Close();
	}
	
	if(site_cookie_domain!='')
	{
		$.cookie('cmt', comment, {expires: 365, path: '/', domain: site_cookie_domain});
	}
	else
	{
		$.cookie('cmt', comment, {expires: 365, path: '/'});
	}

	return false;
}

function toggleSubCommentsAll_Open()
{
	$('#toggleSubComments_link').removeClass('close_all');
	$('#toggleSubComments_link').addClass('open_all');
	
	$('#toggleSubComments_link').text('Zatvori sve');
	
	$('.wrap_comment').removeClass('displaynone');
	
	$('a.toogle_answer').addClass('opened');
}


function toggleSubCommentsAll_Close()
{
	$('#toggleSubComments_link').removeClass('open_all');
	$('#toggleSubComments_link').addClass('close_all');
	
	$('#toggleSubComments_link').text('Otvori sve');
	$('.wrap_comment').addClass('displaynone');
		
	$('a.toogle_answer').removeClass('opened');
}

function fromCookieSubCommentsAll()
{
	if($.cookie('cmt')==2)
	{
		toggleSubCommentsAll_Open();
	}
}

///////////////////////////////////////////////////////
///////////////////////////////////////////////////////












$(document).ready(function() {



//  general

// open up links to external content in new browser window/tab
$("a[href^='http']").attr('target','_blank');
$("a[href^='http://www']").not('a.thickbox').not('.natjecaj ul a').not('a.xplayer').addClass('outlink');
$("a[href^='http://']").not('a.thickbox').not('.natjecaj ul a').not('a.xplayer').addClass('outlink');

//mijenjam rijeći sa ikonama

var el = $('.article_text');

if (/Tel.:/ig.test(el.html()))
	el.html(el.html().replace(/Tel\.:/ig, '<img class="rep_ico" src="/images/ico/ico-tel.png" width="18" height="16" alt="Tel.:" />'));

if (/Fax.:/ig.test(el.html()))
	el.html(el.html().replace(/Fax\.:/ig, '<img class="rep_ico" src="/images/ico/ico-fax.png" width="18" height="16" alt="Fax.:" />'));

if (/Email:/ig.test(el.html()))
	el.html(el.html().replace(/Email:/ig, '<img class="rep_ico" src="/images/ico/ico-mail.png" width="18" height="16" alt="Email:" />'));

	


// log bar style helper 
	/*
	$("#log li a").mouseover(function(){

		var linkli=$(this).parent();

		linkli.next().addClass("pipe_black");
		linkli.prev().addClass("pipe_black");
		
	}).mouseout(function(){

		var linkli=$(this).parent();

		linkli.next().removeClass("pipe_black");
		linkli.prev().removeClass("pipe_black");

	});
	*/



//add class to last list element
	//$('.gallery li:last-child').addClass('last');
	
	$('.search_results div:last-child').prev('dl').addClass('last');
	$('.lista_diskusija li:last-child').addClass('last');
	$('.natjecaj ul li:last-child').addClass('last');
	$('.sidebar dl.third_lev dt:first-child').addClass('first');
	
	
	/*
	$('.gallery li').each(function (i) {
		i = i+1;
		$(this).addClass('item'+i);
  	});
	
	$('#tabs-11 li').each(function (i) {
		i = i+1;
		$(this).addClass('item'+i);
  	});
	*/


//add class to every fourth item galerije 
	if($("ul.gallery ").length){ 
		$("ul.gallery li").each(function(i){ var remainder = (i + 1) % 4; 
			if(remainder === 0){ $(this).addClass("last"); } }); 
		}
		
	if($('ul.pub_list_lar').length){ 
		$('ul.pub_list_lar li').each(function(i){ var remainder = (i + 1) % 4; 
			if(remainder === 0){ $(this).addClass('last'); } }); 
		}
		
	if($('.info_block ul.pub_list').length){ 
		$('ul.pub_list li').each(function(i){ var remainder = (i + 1) % 6; 
			if(remainder === 0){ $(this).addClass('last'); } }); 
		}
	


//  hover start
	
	$('li.wrap_text').hover(
	function() { $(this).addClass('wrap_text_hover'); },
	function() { $(this).removeClass('wrap_text_hover'); });

	$('table.docs').hover(
	function() { $(this).addClass('over_docs'); },
	function() { $(this).removeClass('over_docs'); });
	
	$('ul.links').hover(
	function() { $(this).addClass('over_links'); },
	function() { $(this).removeClass('over_links'); });
	
	$('.home_news_list li').hover(
	function() { $(this).addClass('over_h_list'); },
	function() { $(this).removeClass('over_h_list'); });
	
	$('div.natjecaj').hover(
	function() { $(this).addClass('over_natjecaj'); },
	function() { $(this).removeClass('over_natjecaj'); });
	
	$('.iso_holder').hover(
	function() { $(this).addClass('show_big'); },
	function() { $(this).removeClass('show_big'); });
	
	$('.pub_list_lar li').hover(
	function() { $(this).addClass('hover'); },
	function() { $(this).removeClass('hover'); });

	$('#search_box input.text').focus(
		function() { 
			$(this).parent('li.wrap_text').addClass('wrap_text_focus')
										  .animate({ width: '147px' }, 500 );
											
	
	});
	
	$('#search_box input.text').click(function(e){
		e.stopPropagation();
	});
	
	$(document).click(function(){
		$('#search_box li.wrap_text_focus').removeClass('wrap_text_focus')
										   .animate({ width: '67px' }, 500 );

	});
	
	$('div.natjecaj a.more').click(function(){
		$(this).children('span.ico').toggleClass('close_ico');
		$(this).next('ul').toggle();
		return false;
	});

	

//  hover stop



//  Link style setup
	$('table.docs a[href$=".pdf"]').parent().next('td.ext').append('<span class="pdf">pdf</span>');
	$('table.docs a[href$=".xls"]').parent().next('td.ext').append('<span class="xls">xls</span>');
	$('table.docs a[href$=".doc"]').parent().next('td.ext').append('<span class="doc">doc</span>');
	$('table.docs a[href$=".xdoc"]').parent().next('td.ext').append('<span class="xdoc">xdoc</span>');
	$('table.docs a[href$=".pps"]').parent().next('td.ext').append('<span class="ppt">ppt</span>');
	$('table.docs a[href$=".zip"]').parent().next('td.ext').append('<span class="zip">zip</span>');
	$('table.docs a[href$=".rar"]').parent().next('td.ext').append('<span class="rar">rar</span>');
	
	$('.big_link_block a.outlink').append('<span class="out_ico">&nbsp;</span>');



//  Table style setup
	
	$('table.docs tbody tr:odd').addClass('odd');
	$('table.docs tbody tr:even').addClass('even');
	$('table.events tbody tr:odd').addClass('odd');
	$('table.events tbody tr:even').addClass('even');
	
	$('table.zebra tr:odd').addClass('odd');
	$('table.simple_zebra tr:odd').addClass('odd');

	




//  Comment toggle more
	
	//var parentItem = $(this).parents('.comment_item').next('div.discuss');
	/*
	$('a.n_answer').toggle(
		function(e){
			e.preventDefault();
			$(this).addClass('n_answer_opened')
			$(this).parents('.comment_item').next('div.discuss').show();
		},
		function(e){
			e.preventDefault();
			$(this).removeClass('n_answer_opened')
			$(this).parents('.comment_item').next('div.discuss').hide()
		}
 	);
	
	//var parentItem = $(this).parents().next('div.wrap_add_comm');
	$('a.answer').toggle(
		function(e){
			e.preventDefault();
			//$(this).addClass('test')
			$(this).parents('.comment_item').children('li.wrap_add_comm').show();
		},
		function(e){
			e.preventDefault();
			//$(this).removeClass('test')
			$(this).parents('.comment_item').children('li.wrap_add_comm').hide()
		}
 	);
	*/
	
//  Kalendar small selected
	
	//if($('input[checked*="checked"]'))
	//if($('label.dog input').attr('checked')=='checked')
	$('label#pre input').click(
		function(){
			$(this).addClass('selected')
			$('label#sem input').removeClass('selected')
			set_colors();
		}
 	);
	$('label#sem input').click(
		function(){
			$(this).addClass('selected')
			$('label#pre input').removeClass('selected')
			set_colors();
		}
 	);
	
	function set_colors() {
		if ($('label#pre input').hasClass('selected'))
		{
			$('.kalendar_small').removeClass('set_seminar');
			$('.kalendar_small').addClass('set_predavanje');
		}
		else if ($('label#sem input').hasClass('selected'))
		{
			$('.kalendar_small').removeClass('set_predavanje');
			$('.kalendar_small').addClass('set_seminar');
		}
	}
	set_colors();

	/*
	$('.add_event a').toggle(
		function(e){
			e.preventDefault();
			$(this).addClass('selected')
		},
		function(e){
			e.preventDefault();
			$(this).removeClass('selected')
		}
 	);
	*/



// input file style help
	$("input[type=file]").filestyle({ 
		image: "../images/ico/sprite-buttons.png",
		imageheight : 30,
		imagewidth : 97,
		width : 158
	});
	
	
// publikacije home
	function goBigPub () {
		$(this).animate({
							height:'160px',
							width:'118px',
							top:'-51px',
							left:'-40px',
							padding:'10px',
   							borderWidth: '2px'
							}, 100 )
				  .addClass('box_hover')
				  .parent('li').addClass('pop');
	}
	
	function goSmallPub () {
		$(this).animate({
							height:'80px',
							width:'57px',
							top:'0px',
							left:'0px',
							padding:'0px',
   							borderWidth: '1px' 
							}, 80, function() { $(this).parent('li').removeClass('pop'); }
							)
			       .removeClass('box_hover')
				   
	}
	
	$('ul.pub_list a.box').hoverIntent
	({
		sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		interval: 100, // number = milliseconds for onMouseOver polling interval    
		over: goBigPub, // function = onMouseOver callback (REQUIRED)    
		timeout: 200, // number = milliseconds delay before onMouseOut    
		out: goSmallPub // function = onMouseOut callback (REQUIRED)  
	 })

	
	
	
	
	
 $("#block").animate({ 
        width: "70%",
        opacity: 0.4,
        marginLeft: "0.6in",
        fontSize: "3em", 
        borderWidth: "10px"
      }, 1500 );




							
});    //document ready stop

////////////////////////////////////////////////////////////////
//anchor slide start
/*******
*** Anchor Slider by Cedric Dugas ***
*** Http://www.position-absolute.com ***
Never have an anchor jumping your content, slide it.
Don't forget to put an id to your anchor !
You can use and modify this script for any project you want, but please leave this comment as credit.
*****/

$(document).ready(function() {
  $("a.anchorLink").anchorAnimate();
  
  $('#more_news_link').bind('click', function(event){
		event.preventDefault();	
		fwajax.phpExecute({ url: '/ajax/loadmorenews' });
  });
});

jQuery.fn.anchorAnimate = function(settings) {

 settings = jQuery.extend({
 speed : 1100
 }, settings);

 return this.each(function(){
 var caller = this
 $(caller).click(function (event) {
 event.preventDefault()
 var locationHref = window.location.href
 var elementClick = $(caller).attr("href")

 var destination = $(elementClick).offset().top;
 $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
 window.location.hash = elementClick
 });
 return false;
 })
 })
}

//anchor slide stop
////////////////////////////////////////////////////////////////

function callback_loadMoreNews(html)
{
	if (html == '')
		return;

	$('.home_news_list').html(html);
	$('#more_news_link').hide();
	$('#archive_link').show();
}

function submit_glossaryWord(currentDivId, orgId, newId, letter, lang, page)
{
	var newDivId=currentDivId + '_' + newId;

	var obj=$( '#' + newDivId );

	if( obj.size() == 0 )
	{
		fwajax.phpExecute( { url: '/ajax/glossaryWord' }, // bez langsegmenta
			currentDivId,
			orgId,
			newId,
			letter,
			lang,
			page
		);
	}
	
	return false;
}

function callback_glossaryWord(oldPathId, orgId, html)
{
	if(html=='')
		return;

	$('#term_' + oldPathId).addClass('no-border');
	$('#term_' + oldPathId).after(html);
}

function submit_glossaryGet(orgId, newId)
{
	xajax_glossaryGet(orgId, newId);
	return false;
}

function callback_glossaryGet(html)
{
	$('#glossary_footer').html(html);
}

function setActiveTab(tab_num)
{
	$("#tabs").tabs('select', tab_num - 1);
	$(".search_tab").val(tab_num);
}

function vote(formDom)
{
	var obj=$(formDom);

	if( ! $('input[name=answer][checked]', obj).length )
		return false;

	return true;
}


function checkPollScore()
{
	var v=$.cookie('poll_id');
	
	if(v==null)
		return;
	
	v=parseInt(v);
	
	//console.log('2) poll_id cookie=('+v+')');
	
	if(isNaN(v) || v<=0)
		return;
	
	var o=$('#poll_score_' + v);
		
	if(o.length)
	{
		$('#poll_form').hide();
		o.show();
		
		submit_newPollScore(v);
	}
}

function submit_newPollScore(pollId)
{
	fwajax.phpExecute(
		{url: '/ajax/newpollscore'},
		pollId
	);
}


function callback_newPollScore(pollId, htmlScore)
{
	if(htmlScore && pollId>0)
		$('#poll_score_' + pollId + ' dl.form_item').html( htmlScore );
}


