function gallery_controller( p_arr_entiteti, p_size, p_url_template, p_url_target, p_galerija_suff, p_app_rewrite_base )
{
	if(p_arr_entiteti.length == 0) return false;


	var THUMB_COUNT = 0;

	var SLIKA_ID = 1;
	var ENTITET_TIP = 0;
	var ENTITET_OPIS = 2;
	var VIDEO_TIP = 3;
	var VIDEO_CODE = 4;
	var KEYFIELD_VALUE = 5;
	var INPUT_TOKEN = 6;

	this._arr_entiteti = p_arr_entiteti;
	this._size = p_size;

	this._current_page = 1;
	this._current_index = 0;

	this._total_pages = 1;
	this._thumbs_per_page = 0;

	this._main_varijacija = null;

	this._galerija_suff = p_galerija_suff;

	this._app_rewrite_base = p_app_rewrite_base;

	// array sa brojem thumbova ovisno o velicini galerije
	this._arr_size_defs = [
	[10],
	[10]
	];

	this._arr_img_size = [
	['w450'],
	['w185'],
	];

	//this._arr_img_omjer = ['w450'];

	this._url_template = p_url_template;
	this._url_target = p_url_target;

	this._init = function()
	{
		this._thumbs_per_page = this._arr_size_defs[ this._get_size_index() ][ THUMB_COUNT ];
		this._total_pages = Math.ceil( this._arr_entiteti.length / this._thumbs_per_page);
		this._main_varijacija = this._arr_img_size[ this._get_size_index() ][ 0 ];
		this.show_thumbs();

		//this.show( 0 );
	}

	this.show_thumbs = function()
	{
		var _html = '';
		var _html_input_token = '';

		// popuni thumbs dio
		for ( index = 0; index < this._thumbs_per_page; index++ ){
			var _abs_index = this._get_absolute_index( index );

			var arr_entitet = this._arr_entiteti[ _abs_index ];

			if( _abs_index <= this._arr_entiteti.length -1 ){
				// prikazi thumb

				if( arr_entitet[ ENTITET_TIP ] != 1 ){
					// video
					_html = '<a href="javascript:obj_galerija_' + this._galerija_suff +'.show(' + index + ')"><img src="' + this._app_rewrite_base + 'templates/assets/images/elements/video_icon_gallery.png" class="video_icon" /><img src="fw3k/util_scripts/get_slika_varijacija.php?slika_id=' + arr_entitet[ SLIKA_ID ] + '&var_suff=55x40" border="0"></a>';
				} else {
					// slika
					//alert( this._arr_entiteti[ INPUT_TOKEN ] );
					if( typeof( arr_entitet[ INPUT_TOKEN ] ) != 'undefined' && arr_entitet[ INPUT_TOKEN ] != '' ){
						_html_input_token = '&input_token=' + this._arr_entiteti[ INPUT_TOKEN ] + '&new_temp=1';
					}
					_html = '<a href="javascript:obj_galerija_' + this._galerija_suff +'.show(' + index + ')"><img src="' + this._app_rewrite_base + 'slika-56x40-' + arr_entitet[ SLIKA_ID ] + '.jpg?' + _html_input_token + '" border="0"></a>';
				}
				$( '#galerija_thumb_' + (index + 1) + '_' + this._galerija_suff ).html( _html );
			} else {
				// prikazi prazan thumb
				$( '#galerija_thumb_' + (index + 1) + '_' + this._galerija_suff ).html( '&nbsp;' );
			}
		}

	}

	this.show = function( p_index )
	{
		this._current_index = p_index;

		var arr_entitet = this._arr_entiteti[ this._get_absolute_index( p_index ) ];

		if( (arr_entitet != 'undefined') ){

			var _omjer_id = 0;

			var _url_template = this._url_template;
			var _url_target = this._url_target;
			var _var_suff = this._main_varijacija;
			var _size = this._size;
			var _galerija_suff = this._galerija_suff;
			var _html_input_token = '';

			var _obj_gallery = this;

			if( _url_target == null ){
				_url_target = '_self';
			}

			var app_rewrite_base = this._app_rewrite_base;

			$( '#galerija_canvas_' + _galerija_suff ).fadeOut( 'normal', function()
			{

				$( '#galerija_spinner_' + _galerija_suff ).show();

				if( arr_entitet[ ENTITET_TIP ] == 1 ){
					//alert( 'tu sam!' );

					if( typeof( arr_entitet[ INPUT_TOKEN ] ) != 'undefined' && arr_entitet[ INPUT_TOKEN ] != '' ){
						_html_input_token = '&input_token=' + arr_entitet[ INPUT_TOKEN ] + '&new_temp=1';
					}

					var _html = '<img id="galerija_image" onload="javascript:obj_galerija_' + _galerija_suff + '.hide_spinner()" src="' + app_rewrite_base + 'images-content/get_image_variation.php?image_id=' + arr_entitet[ SLIKA_ID ] + '&quality=90&var_suff=' + _var_suff + _html_input_token + '" border="0">';
					var _link = '<img src="templates/assets/images/button_opsirnije_voditelj.gif" alt="OpĹˇirnije" />';

					if( _url_template != null ){
						//alert( this._url_template );
						_html = '<a href="' + _url_template.replace( '{id}', arr_entitet[ KEYFIELD_VALUE ] ) + '" target="' + _url_target + '">' + _html + '</a>';

						_link = '<a href="' + _url_template.replace( '{id}', arr_entitet[ KEYFIELD_VALUE ] ) + '" target="' + _url_target + '">' + _link + '</a>';
					}

					// slika
					$( '#galerija_canvas_' + _galerija_suff ).html( _html );
					//alert( _html );
					if( $.browser.opera ){
						_obj_gallery.hide_spinner();
					}
					// link
					$( '#galerija_link_' + _galerija_suff ).html( _link );

				} else {
					var video_code = arr_entitet[ VIDEO_CODE ];
					var video_tip = arr_entitet[ VIDEO_TIP ];
					// video
					$('#galerija_canvas_' + _galerija_suff ).load( 'index.php?cmd=ajax_show_video&video_code=' + video_code + '&video_tip=' + video_tip + '&video_slika_id=' + arr_entitet[ SLIKA_ID ] + '&size=' + _size + '&controlbar=over', null, function()
					{
						// sakrij spinner
						$( '#galerija_spinner_' + _galerija_suff ).hide();
						$( '#galerija_canvas_' + _galerija_suff ).show();
					}
					);

					if( _url_template != null ){
						var _txt_link = '<a href="' + _url_template.replace( '{id}', arr_entitet[ KEYFIELD_VALUE ] ) + '" target="' + _url_target + '">' + arr_entitet[ ENTITET_OPIS ] + '</a>';

						$( '#galerija_canvas_caption_link_' + _galerija_suff ).html( _txt_link );
					}
				}


			});

			// prikazi caption
			$( '#galerija_canvas_caption_' + _galerija_suff ).text( arr_entitet[ ENTITET_OPIS ] );

			// prikazi lead
			$( '#galerija_canvas_lead_' + _galerija_suff ).text( arr_entitet[ 3 ] );

			// prikazi poziciju
			$( '#galerija_status_' + _galerija_suff ).text( (this._get_absolute_index( this._current_index ) + 1) + '/' + this._arr_entiteti.length );
		}
	}

	this.next = function()
	{
		if( this._get_absolute_index( this._current_index ) < (this._arr_entiteti.length - 1) ){
			this._current_index ++;

			// ako prelazimo na slijedecu stranicu
			if( this._current_index > this._thumbs_per_page - 1 ){
				this._current_index = 0;
				this._current_page++;

				this.show_thumbs();
			}

			this.show( this._current_index );
		}
	}

	this.prev = function()
	{
		if( this._get_absolute_index( this._current_index ) > 0 ){
			this._current_index --;

			// ako prelazimo na prethodnu stranicu
			if( this._current_index < 0){
				this._current_index = this._thumbs_per_page - 1;
				this._current_page--;

				this.show_thumbs();
			}

			this.show( this._current_index );
		}
	}

	this.next_page = function()
	{
		if( this._current_page < this._total_pages ){
			this._current_page ++;
			this._current_index = 0;

			this.show_thumbs();
			//this.show( this._current_index );
		}
	}

	this.prev_page = function()
	{
		if( this._current_page > 1 ){
			this._current_page --;
			this._current_index = this._thumbs_per_page - 1;

			this.show_thumbs();
			//this.show( this._current_index );
		}
	}


	this.hide_spinner = function()
	{
		$( '#galerija_spinner_' + this._galerija_suff ).hide();
		$( '#galerija_canvas_' + this._galerija_suff ).fadeIn( 200 );
	}

	this.show_spinner = function()
	{
		//$( '#galerija_canvas' ).html( '&nbsp;' );
		$( '#galerija_canvas_' + this._galerija_suff ).hide();
		$( '#galerija_spinner_' + this._galerija_suff ).show();
	}

	this._get_size_index = function()
	{
		if( this._size == 'normal' ){
			return 0;
		}
		if( this._size == 'small' ){
			return 1;
		}
		return null
	}

	// index je zero based
	this._get_absolute_index = function( p_index )
	{
		return (this._current_page - 1) * this._arr_size_defs[ this._get_size_index() ][ THUMB_COUNT ] + p_index;
	}

	this._init();
}


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

function ad_comparer_add( p_ad_id, p_rewrite_base , p_return_url )
{

	//kako se u nekim situacijama ne prikazuje compare_box ovdje ga automatski prikazuje
	$( '#div_ad_compare_box' ).show();

	// dodaje oglas koristeci ajax poziv
	// i ukoliko postoji placeholder za listu oglasa za usporebu
	// osvjezava tu listu
	$( '#div_ad_compare_list' ).hide();
	$( '#div_ad_compare_spinner' ).show();

	$( '#div_ad_compare_list' ).load( p_rewrite_base + 'index.php?cmd=compare_ads&action=ajax_add_ad', { ad_id: p_ad_id , return_url: p_return_url }, function()
	{
		$( '#div_ad_compare_spinner' ).hide();
		$( '#div_ad_compare_list' ).show();
	}
	);
}

function ad_comparer_remove( p_ad_id, p_rewrite_base , p_return_url )
{
	// mice oglas koristeci ajax poziv
	// i ukoliko postoji placeholder za listu oglasa za usporebu
	// osvjezava tu listu
	$( '#div_ad_compare_list' ).hide();
	$( '#div_ad_compare_spinner' ).show();

	$( '#div_ad_compare_list' ).load( p_rewrite_base + 'index.php?cmd=compare_ads&action=ajax_remove_ad', { ad_id: p_ad_id , return_url: p_return_url }, function()
	{
		$( '#div_ad_compare_spinner' ).hide();
		$( '#div_ad_compare_list' ).show();
	}
	);
}


function change_default_text(p_object, p_default, p_event) {
	if (p_event == "focus") {
		if (p_object.value == p_default) {
			p_object.value = "";
		}
	} else {
		if (p_object.value == "") {
			p_object.value = p_default;
		}
	}
}

function hide_banner_containers() {

	if ($("#banner_ticker").length > 0 && $("#banner_ticker").height() < 15) {
		$("#banner_ticker").hide();
		// alert('Gasi banner_ticker');
	}

	if ($("#banner_sidebar").length > 0 && $("#banner_sidebar").height() < 15) {
		$("#banner_sidebar").hide();
		// alert('Gasi banner_sidebar');
	}

	if ($("#banner_top").length > 0 && $("#banner_top").height() < 15) {
		$("#banner_top").hide();
		// alert('Gasi banner_top');
	}

	if ($("#banner_full1").length > 0 && $("#banner_full1").height() < 15) {
		$("#banner_full1").hide();
		// alert('Gasi banner_full1');
	}

	if ($("#banner_full2").length > 0 && $("#banner_full2").height() < 15) {
		$("#banner_full2").hide();
		// alert('Gasi banner_full2');
	}

	if ($("#banner_full3").length > 0 && $("#banner_full3").height() < 15) {
		$("#banner_full3").hide();
		// alert('Gasi banner_full3');
	}

	if ($("#banner_full4").length > 0 && $("#banner_full4").height() < 15) {
		$("#banner_full4").hide();
		// alert('Gasi banner_full4');
	}

	if ($("#banner_half_left").length > 0 && $("#banner_half_left").height() < 15) {
		$("#banner_half_left").hide();
		// alert('Gasi banner_half_left');
	}

	if ($("#banner_half_right").length > 0 && $("#banner_half_right").height() < 15) {
		$("#banner_half_right").hide();
		// alert('Gasi banner_half_right');
	}

	if ($("#banner_wide").length > 0 && $("#banner_wide").height() < 15) {
		$("#banner_wide").hide();
		// alert('Gasi banner_wide');
	}

	if ($("#banner_narrow").length > 0 && $("#banner_narrow").height() < 15) {
		$("#banner_narrow").hide();
		// alert('Gasi banner_narrow');
	}

	if ($("#banner_rmkat1").length > 0 && $("#banner_rmkat1").height() < 15) {
		$("#banner_rmkat1").hide();
		// alert('Gasi banner_rmkat1');
	}

	if ($("#banner_rmkat2").length > 0 && $("#banner_rmkat2").height() < 15) {
		$("#banner_rmkat2").hide();
		// alert('Gasi banner_rmkat2');
	}

	if ($("#banner_rmkat3").length > 0 && $("#banner_rmkat3").height() < 15) {
		$("#banner_rmkat3").hide();
		// alert('Gasi banner_rmkat3');
	}

	if ($("#banner_rmkat4").length > 0 && $("#banner_rmkat4").height() < 15) {
		$("#banner_rmkat4").hide();
		// alert('Gasi banner_rmkat4');
	}

	if ($("#banner_rmkat5").length > 0 && $("#banner_rmkat5").height() < 15) {
		$("#banner_rmkat5").hide();
		// alert('Gasi banner_rmkat5');
	}

	if ($("#banner_rmdet1").length > 0 && $("#banner_rmdet1").height() < 15) {
		$("#banner_rmdet1").hide();
		// alert('Gasi banner_rmdet1');
	}

	if ($("#banner_rmdet2").length > 0 && $("#banner_rmdet2").height() < 15) {
		$("#banner_rmdet2").hide();
		// alert('Gasi banner_rmdet2');
	}

	if ($("#banner_rmdet3").length > 0 && $("#banner_rmdet3").height() < 15) {
		$("#banner_rmdet3").hide();
		// alert('Gasi banner_rmdet3');
	}

	if ($("#banner_rmdet4").length > 0 && $("#banner_rmdet4").height() < 15) {
		$("#banner_rmdet4").hide();
		// alert('Gasi banner_rmdet4');
	}

	if ($("#banner_rmdet5").length > 0 && $("#banner_rmdet5").height() < 15) {
		$("#banner_rmdet5").hide();
		// alert('Gasi banner_rmdet5');
	}
}

function CreateBookmarkLink() {

	title = "Njuskalo.hr oglasnik";

	url = "http:://www.njuskalo.hr";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
		else if(window.opera && window.print) { // Opera Hotlist
			return true; }
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


