var _ppk_in_progress = false;

function komentari_controller_new( p_content_id, p_content_type )
{

    this._get_list_url = APP_REWRITE_BASE + 'index.php?cmd=ajax_content_komentari';
    this._submit_url   = APP_REWRITE_BASE + 'index.php?cmd=ajax_content_komentari&action=komentiraj';
    this._pohvali_url  = APP_REWRITE_BASE + 'index.php?cmd=ajax_content_komentari&action=pohvali';
    this._pokudi_url   = APP_REWRITE_BASE + 'index.php?cmd=ajax_content_komentari&action=pokudi';
    this._komentari_pokazi = APP_REWRITE_BASE + 'komentar/' + p_content_id +'/';

    this._current_page = 1;
    this._current_sort = 'kronoloski';
    this._content_id = p_content_id;
    this._content_type = p_content_type;
    var obj = this;

    this.set_cookie = function( name, value, expires, path, domain, secure )
    {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
        */
        if ( expires )
        {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) +
            ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
            ( ( path ) ? ";path=" + path : "" ) +
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ( ( secure ) ? ";secure" : "" );
    }
    
    this.get_cookie = function( name ) {

        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )  { return null; }
        if ( start == -1 ) return null;
        
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
    }
    
    this._set_initial_cookie = function (p_komentar_id) {
	var _cookie_name = 'VECERNJIkomentar'+p_komentar_id;
	var _cookie = this.get_cookie(_cookie_name);
	if (_cookie == null) {
	    this.set_cookie(_cookie_name, '0', false, '/');
	}
    }

    this.submit = function()
    {
		$('div#comment_float div#login_error').hide();
		$('div#comment_float div#login_sucess').hide();
		var _tekst = $( '#id_komentar_tekst' ).val();
		var _fb_publish = $( 'input#send_fb_comment').is(':checked') ? 1 : 0;

        if( _tekst != '' ){
            //$.get( _url );
			$.ajax({
				url: this._submit_url,
				type: 'POST',
				data: 'content_id=' + this._content_id + '&content_type=' + this._content_type + '&komentar_tekst=' + encodeURIComponent( _tekst ) +'&fb_comment='+_fb_publish,
				success: function(msg) {
				    if (msg == 'OK:') {
						window.location = obj._komentari_pokazi;
				    } else {
						var error = msg.substr(4);
						$('div#comment_float div#login_error span').html(error);
						$('div#comment_float div#login_error').show();
				    }
				}
			});
		}
    };

    this.pohvali = function( p_komentar_id )
    {
	$( '#span_komentar_ocjena_toolbar_' + p_komentar_id).fadeOut( 50 );

	if (!_ppk_in_progress) {

	    _ppk_in_progress = true;
	    this._set_initial_cookie(p_komentar_id);

	    var _url = this._pohvali_url + '&komentar_id=' + p_komentar_id;

	    $.get( _url, function( data ){
	        
	        if( data.substring(0,3) == 'OK:' ){

	            var _ocjena = parseInt( data.substring( 3, data.length ) );

	            $( '#span_komentar_ukupna_ocjena_' + p_komentar_id).text( _ocjena );
    
	        } else {
	            $( '#span_komentar_ocjena_toolbar_' + p_komentar_id).fadeIn( 50 );
		}
	        window.setTimeout('_ppk_in_progress = false;',50);
	    });
	}
    }

    this.pokudi = function( p_komentar_id )
    {
	$( '#span_komentar_ocjena_toolbar_' + p_komentar_id).fadeOut( 50 );

	if (!_ppk_in_progress) {

	    _ppk_in_progress = true;
	    this._set_initial_cookie(p_komentar_id);

	    var _url = this._pokudi_url + '&komentar_id=' + p_komentar_id;

	    $.get( _url, function( data ){
	        if( data.substring(0,3) == 'OK:' ){

	            var _ocjena = parseInt( data.substring( 3, data.length ) );

	            $( '#span_komentar_ukupna_ocjena_' + p_komentar_id).text( _ocjena );
	            //$( '#span_komentar_ocjena_toolbar_' + p_komentar_id).html('OCJENA:<br /><span class="komentar_ocjena">'+_ocjena+'</span>');
		} else {
	            $( '#span_komentar_ocjena_toolbar_' + p_komentar_id).fadeIn( 50 );
		}
	        window.setTimeout('_ppk_in_progress = false;',50);
	    });
	}
    }


    this.sort = function( p_sort )
    {
        this._current_sort = p_sort;
        this._current_page = 1;

        this.get_list();
    }

}


function nc() {
	this.active_nav    = null;
	this.active_subnav = null;
    this.hide_interval = null;
    
    this.mn_out = function()
    {
		cont = this;
		this.hide_interval = window.setTimeout(function() {
			cont.reset();
		},750);
    }
    
    this.mn_in = function (item)
    {
		clearTimeout(this.hide_interval);
		$('ul#navigation li').removeClass('selected');
		$('ul#navigation li#nav_'+item).addClass('selected');
		$('ul.subnavigation').hide();
		$('ul#subnav_'+item).show();
    }
    
    this.sn_out = function()
    {
		cont = this;
		this.hide_interval = window.setTimeout(function() {
			cont.reset();
		},750);
    }
    
    this.sn_in = function() {
		clearTimeout(this.hide_interval);
    }
	
	this.init = function() {
		this.active_nav = $('ul#navigation li.selected');
		var id = this.active_nav.attr('id');
		if (id){
			this.active_subnav =  id.substring(4);
		} else {
			this.active_subnav = 'profil';
		}
	}
	
	
	this.reset = function() {
		//console.log('RESEEET');
		$('ul#navigation li').removeClass('selected');
		this.active_nav.addClass('selected');
		$('ul.subnavigation').hide();
		$('ul#subnav_'+this.active_subnav).show();
	}
	
	this.init();
}
    

$().ready(function()
{

    $('#login_float').jqm({
        trigger: '#login_trigger',
        overlay: 60,
        overlayClass: 'blackOverlay',
	onHide: function(hash) {
	    $('#login_float div#login_error').hide()
	    hash.o.remove();
	    $('#login_float').hide();
	}
    }).jqmAddTrigger($('#login_comment_trigger')).jqmAddTrigger($('#prijava_trigger')).jqmAddTrigger($('#login')); // kod clanka dodaje trigger :)


	$('#avatar_float').jqm({
		trigger: '#avatar_trigger',
		overlay: 60,
		overlayClass: 'blackOverlay'
	});

	$('#status_float').jqm({
		trigger: '#status_trigger',
		overlay: 60,
		overlayClass: 'blackOverlay'
	});

    $('#comment_float').jqm({
		trigger: '#comment_trigger',
		overlay: 60,
		overlayClass: 'blackOverlay'
    });

	$('#login_float_fb_connect').jqm({
        overlay: 60,
        overlayClass: 'blackOverlay'
	});

    $('#send_content_float').jqm({
		trigger: '#send_content_trigger',
		overlay: 60,
		overlayClass: 'blackOverlay',
		onHide: function(hash) {
		    $('#send_content_float form#frm_send_recommend').show();
		    $('#send_content_float div#send_sucess').hide();
		    $('#send_content_float div#send_error').hide();
		    hash.o.remove();
		    $('#send_content_float').hide();
		}
    }).jqmAddTrigger($('#send_content_trigger_2'));

    $('#ex3b').jqm({
        trigger: '#ex3bTrigger',
        overlay: 50
    });

    // login
    $('#ex3c').jqm({
        trigger: '#ex3cTrigger',
        overlay: 50
    });

    // posalji prijatelju
    $('#ex3d').jqm({
        trigger: '#ex3dTrigger',
        overlay: 50
    });

    $('input.jqmdX')
		.focus(
		    function(){ $(this).addClass('jqmdXFocus'); })
		.blur(
			function(){ $(this).removeClass('jqmdXFocus'); });
	}
);


function do_login() {
    var user  = $('#frm_login input#korisnicko_ime').val();
    var pass  = $('#frm_login input#lozinka').val();
    
    $.ajax({
		type: 'POST',
		url : APP_REWRITE_BASE + 'index.php?cmd=do_login&action=login',
		data : 'korisnicko_ime='+user+'&lozinka='+pass,
		success : function(raw_data) {
	
			var pattern = /^(ERR|OK):(.*?)$/i;
			var m = pattern.exec(raw_data);
			if (m.length == 3) {
				var data = m[1];
				var err  = m[2];
			} else {
				var data = '';
				var err  = raw_data;
			}
			
			if (data == 'OK')
			{
			    window.location.reload();
			} else
			{
			    $('#login_float div#login_error span').html(err);
			    $('#login_float div#login_error').show()
			}
		}
    });
}

function posalji_sadrzaj() {
	$.ajax({
	    type: 'POST',
	    url: APP_REWRITE_BASE + 'index.php?cmd=ajax_posalji_prijatelju&action=posalji',
	    //data: 'content_id='+p_clanak_id+'&content_type=1',
	    data: {
		   'content_id' : $('input#content_id').val(),
		   'content_type' : '1',
		   'source_mail' : $('input#source_mail').val(),
		   'dest_mail' : $('input#dest_mail').val(),
		   'zbroj' : $('input#zbroj').val(),
		   'seckey' : $('input#seckey').val()
		},
	    success: function(data) {
		$('input#zbroj').val('');
		if (data == 'OK:') {
		    $('#send_content_float form#frm_send_recommend').hide();
		    $('input#source_mail').val('');
		    $('input#dest_mail').val('');
		    $('#send_content_float div#send_sucess').show();
		} else {
		    $('#send_content_float div#send_error span').html(data.substring(4));
		    $('#send_content_float div#send_error').show();
		}
	    }
	});
}


    $(document).ready(function(){

		if( typeof $('#slider_special') != 'undefined' ){
	        $("#slider_special").easySlider({
				auto: true, 
				continuous: true,
				prevText: '',
				nextText:'',
				speed: 500,
				pause: 5000
	        });
		}
		
		if( typeof $('#slider_special_2') != 'undefined' ){
	        $("#slider_special_2").easySlider({
				auto: true, 
				continuous: true,
				prevId: 'prevBtn_2',
				nextId: 'nextBtn_2',
				prevText: '',
				nextText:'',
				speed: 500,
				pause: 5000
	        });
		}

		if( typeof $('#slider_galleries') != 'undefined' ){
			$("#slider_galleries").easySlider({
				auto: false, 
				continuous: false,
				prevId: 'prevBtnGalleries',
				nextId: 'nextBtnGalleries',
				prevText: '',
				nextText:'',
				speed: 1500,
				pause: 3000
			});
		}

	if( typeof $('#breaking_wrap') != 'undefined' ){
		$('#breaking_wrap').easySlider({
			auto: false,
			continuous: false,
			prevId: 'prevBreaking',
			nextId: 'nextBreaking',
			prevText: '',
			nextText:'',
			speed: 700
			//pause: 3000
		});
	}

	$("#slider_blogs").easySlider({
			auto: false, 
			continuous: false,
			prevId: 'prevBtnBlogs',
			nextId: 'nextBtnBlogs',
			orientation: 'vertical',
			vertical: true,
			prevText: '',
			nextText:'',
			speed: 1000,
			pause: 3000
        });
	
	if (document.getElementById('title_main_news')) {
	    var back_main_news = document.getElementById('title_main_news').offsetHeight;
	    back_main_news = back_main_news + "px";
	    document.getElementById('back_main_news').style.height = back_main_news;
	}
	
    });
    
    function showHarmonikaTab(tab) {
		$("ul#najcitanije, ul#najkomentiranije, ul#najnovije").hide();
		$("a#tab_najcitanije_new, a#tab_najkomentiranije_new, a#tab_najnovije_new").removeClass("selected");
		$("ul#"+tab).show();
		$("#tab_"+tab+"_new").addClass("selected");
    }

    function showStockHarmonikaTab(tab) {
		$("div#tecajna, div#burze").hide();
		$("a#tab_tecajna, a#tab_burze").removeClass("selected");
		$("div#"+tab).show();
		$("#tab_"+tab).addClass("selected");
    }

	function showBurzeTab(tab) {
		$("#stock_tables").children().hide();
		$("#stock_titles").children().removeClass("selected");
		$("div#"+tab).show();
		$("#tab_"+tab).addClass("selected");
    }

	function showTvTab(tab) {
		$("#tv_programi").children().hide();
		$("#tv_programi_tabs").children().removeClass("selected");
		$("div#"+tab).show();
		$("#tab_"+tab).addClass("selected");
    }

    function vecernji_fm_popup()
    {
        window.open ("http://media.vecernji-list.hr/vecernji.fm/player.html","mywindow","location=0,status=1,scrollbars=0,width=488,height=190");
    }

function fw3k_thumb_gallery( p_arr_entiteti, p_thumb_variation, p_thumbs_per_page, p_url_target, p_id_suff, p_app_rewrite_base, p_use_additional_overlay, p_use_hover_thumb )
{
    if(p_arr_entiteti.length == 0) return false;

    var SLIKA_ID = 0;
    var ENTITET_OPIS = 1;
    var URL = 2;

    this._arr_entiteti = p_arr_entiteti;

    this._current_page = 1;
    this._current_index = 0;

    this._total_pages = 1;
    this._thumbs_per_page = p_thumbs_per_page;

    this._id_suff = p_id_suff;

    this._url_target = p_url_target;
    this._thumb_variation = p_thumb_variation;

    this._fade_inout = true;

    this._app_rewrite_base = p_app_rewrite_base;

    this._use_additional_overlay = p_use_additional_overlay;

    this._use_hover_thumb = p_use_hover_thumb;
    
    this._init = function()
    {
        this._total_pages = Math.ceil( this._arr_entiteti.length / this._thumbs_per_page);
        this.show_thumbs();

        this.show( 0 );
    }

    this.show_thumbs = function()
    {
        var _obj_instance = this;
        var _thumb_variation = this._thumb_variation;
        var _id_suff = this._id_suff;

        var _app_rewrite_base = this._app_rewrite_base;

        for ( index = 0; index < this._thumbs_per_page; index++ ){

            var _current_abs_index = this._get_absolute_index( index, this );

            if( _current_abs_index <= this._arr_entiteti.length -1 ){

                var thumb_el = document.getElementById( 'galerija_thumb_' + (index + 1) + '_' + _id_suff );

                $('#galerija_thumb_' + (index + 1) + '_' + _id_suff).hide();

                var _index = parseInt( thumb_el.id.substr( 'galerija_thumb_'.length, thumb_el.id.length - 'galerija_thumb_'.length - _id_suff.length - 1 ) );
                var _abs_index = parseInt( _obj_instance._get_absolute_index( ( _index - 1 ), _obj_instance ) );
                var arr_entitet = _obj_instance._arr_entiteti[ _abs_index ];

                $('#galerija_spinner_' + (_index ) + '_' + _id_suff).show();                

                if( typeof( arr_entitet ) != 'undefined' ){
                    
                    var _url = arr_entitet[ URL ];

                    var _slika_id = arr_entitet[ SLIKA_ID ];
                    var _opis = arr_entitet[ ENTITET_OPIS ];

                    var _galerija_thumb_id = '#galerija_thumb_' + _index + '_' + _id_suff;
                    var _galerija_caption_id = '#galerija_caption_' + _index + '_' + _id_suff;

                    
                    _html_slika = '<a href="' + _url +'"><img src="' + _app_rewrite_base + 'fw3k/util_scripts/get_slika_varijacija.php?slika_id=' + _slika_id + '&amp;var_suff=' + _thumb_variation + '" onload="javascript:obj_gallery_' + _id_suff + '.hide_spinner(' + _index + ')" border="0" />';

                    if (this._use_additional_overlay) {
                        _html_slika += '<span class="photogallery_name_container"><div class="photogallery_overlay"></div><h4>' + _opis + '</h4></span>';
                    }
                    _html_slika += '</a>';
                    _html_caption = '<a href="' + _url +'">' + _opis + '</a>';

                    $( _galerija_thumb_id ).html( _html_slika );
                    $( _galerija_caption_id ).html( _html_caption );

                    
                    if (this._use_hover_thumb /*&& !($.browser.msie && $.browser.version=='6.0')*/) {
                    	this.set_img_hover(_galerija_thumb_id, _slika_id);
                    }

                    if( $.browser.opera ){
                        _obj_instance.hide_spinner(_index);
                    }
                }
            } else {
                // prikazi prazan thumb
                $( '#galerija_thumb_' + (index + 1) + '_' + this._id_suff ).html( '&nbsp;' );
                $( '#galerija_caption_' + (index + 1) + '_' + this._id_suff ).html( '&nbsp' );
            }
        }

    }

    this.set_img_hover = function (parent, slika_id)
    {
    	var _app_rewrite_base = this._app_rewrite_base;
    	
    	var parent_cont = $(parent);

    	var img_src = _app_rewrite_base + 'fw3k/util_scripts/get_slika_varijacija.php?slika_id=' + slika_id + '&var_suff=';
    	
    	var preload_img = new Image();
    	preload_img.src = img_src + '190x125';
    	
    	var a    = parent_cont.find('a');
    	var img  = a.find('img');
    	var span = a.find('span.photogallery_name_container');

    	var _img;
    	a.hover(function() {
    		img.css({
    			width: '190px',
    			height: '125px'
			}).attr('src', img_src +  '190x125');
    		parent_cont.css({'z-index': '1000'});
    		a.css({
    			position: 'absolute',
    			'z-index': '1000',
    			top: '-40px',
    			left: '-55px',
    			width: '190px',
    			height: '125px',
    			display: 'block'
    		});
    		a.addClass('frame');
    		span.css('display', 'block');
    	}, function() {
    		a.removeClass('frame');
    		img.css({
				width: '83px',
				height: '54px'
			});
    		img.attr('src', img_src  + '83x54');
    		span.css('display', 'none');
    		parent_cont.css({'z-index': '50'});
    		a.css({
    			position: 'relative',
    			'z-index': '50',
				top: '0',
    			left: '0',
    			width: '83px',
    			height: '54px'
    		});
		});
    }

    this.show = function( p_index )
    {
        // evenutalno promijeni klasu trenutno aktivnog thumba
    }

    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.hide_spinner = function( p_index )
    {
        //alert( 'pozvan' );
        var _galerija_thumb_id = '#galerija_thumb_' + p_index + '_' + this._id_suff;
        $( _galerija_thumb_id ).show();
        $( '#galerija_spinner_' + (p_index ) + '_' + this._id_suff ).hide();
    }

    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 );
        }
    }

    // index je zero based
    this._get_absolute_index = function( p_index, p_obj_instance )
    {
        return (p_obj_instance._current_page - 1) * p_obj_instance._thumbs_per_page + p_index;
    }

    if( typeof( this._app_rewrite_base ) == 'undefined' ){
        this._app_rewrite_base = '';
    }

    if( typeof( this._use_additional_overlay ) == 'undefined' ){
        this._use_additional_overlay = true;
    }

    if( typeof( this._use_hover_thumb ) == 'undefined' ){
        this._use_hover_thumb = false;
    }

    this._init();
}


function linked_columns_height() {
    var elm1 = document.getElementById("linked_news_column");
    var elm2 = document.getElementById("about_topic_column");

    if (elm1 != null && elm2 != null ) {

        var colHeight = new Array(2);
        colHeight[0] = elm1.offsetHeight + 35;
        colHeight[1] = elm2.offsetHeight + 35;

        if (colHeight[0] > colHeight[1]) {
            elm1.style.height = colHeight[0] + "px";
            elm2.style.height = colHeight[0] + "px";
        } else {
            elm1.style.height = colHeight[1] + "px";
            elm2.style.height = colHeight[1] + "px";
        }
    }
}

function vecernji_fm_popup()
{
    window.open ("http://media.vecernji-list.hr/vecernji.fm/player.html","mywindow","location=0,status=1,scrollbars=0,width=488,height=190");
}

function main_picture_caption_height() {
    /*var el1 = document.getElementById("main_canvas_caption_picture");
    var el2 = document.getElementById("main_canvas_caption_overlay");
    
    if(  el1 != null && el2 != null ){
        colLength = new Array(1);
        colLength[0] = el1.offsetHeight + 10;
        el2.style.height = colLength[0] + "px";
    }*/
    
    var galerije = $('div.clanak_gallery');
    galerije.each(function(i) {
        var g = galerije[i];
        var divz = g.getElementsByTagName('div');
        var h = divz[1].offsetHeight + 10;
        divz[0].style.height = h + "px";
    });
}

function fbs_click()
{
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function GetThis(T, C, U, L)
{
	var targetUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?' + 't=' + encodeURIComponent(T) + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
	window.open(targetUrl);
}

function CroportalAdd(URL, TITLE, ABSTRACT, CATEGORY)
{
	var targetUrl = 'http://www.croportal.net/submit?url=' + encodeURIComponent(URL) + '&title=' + encodeURIComponent(TITLE) + '&abstract=' + encodeURIComponent(ABSTRACT) + '&category=' + encodeURIComponent(CATEGORY);
	window.open(targetUrl);
}

function TwitterAdd(URL)
{
	var targetUrl = 'http://twitter.com/home?status=Trenutno citam ' + encodeURIComponent(URL);
	window.open(targetUrl);
}

function DiggAdd(URL)
{
	var targetUrl = 'http://digg.com/submit?phase=2&url=http://' + encodeURIComponent(URL);
	window.open(targetUrl);
}

function load_multimedia(mmid)
{
    $('#google_map_overlay').hide();
    $('#clanak_mm_box').hide();
    $('#clanak_mm_spinner').show();
    var url = APP_REWRITE_BASE + 'index.php?cmd=ajax_load_multimedia&id='+mmid;
    $('#clanak_mm_box').html('');
    $.get(url, null, function(data){
        //alert(data);
        $('#clanak_mm_box').html(data);
        if (($('#clanak_mm_box img').length == 0) || ($.browser.opera)){
            $('#clanak_mm_spinner').hide();
            $('#clanak_mm_box').show();
        } else {
            $('#clanak_mm_box img').bind('load',function(){
                $('#clanak_mm_spinner').hide();
                $('#clanak_mm_box').show();
            });
        }
    });
}

function show_map_div() {
    $('#clanak_mm_spinner').hide();
    $('#clanak_mm_box').hide();
    $('#google_map_overlay').show();
    if (!gmap_controller._map_loaded) {
	gmap_controller.init_map();
    }
/*
    map.checkResize();
    map.setCenter(point,5);
*/
}


$().ready(function(){
        $("#clanak_m-slika_box").easySlider({
			auto: false, 
			continuous: false,
			prevId: 'prevBtnClanakGallery',
			nextId: 'nextBtnClanakGallery',
			prevText: '',
			nextText:'',
			speed: 700,
			pause: 3000
        });
        $('a[rel=lightbox]').fancybox({
           'overlayOpacity' : 0.6,
           'overlayColor'   : '#000000',
           'opacity'        : false,
           'centerOnScroll' : true,
           // inside, outside, over
           'titlePosition'  : 'over'
        }
        );
});

function show_full_image(p_id){
    $('a#lb_'+p_id).click();
}


function ocjena_controller( p_content_id )
{

    this._ocjeni_url = APP_REWRITE_BASE + 'index.php?cmd=ajax_clanak_ocjeni&action=ocjeni';

    this._content_id = p_content_id;

    this.ocjeni = function( p_ocjena)
    {
        var _url = this._ocjeni_url + '&content_id=' + this._content_id + '&ocjena=' + p_ocjena;

        $( '#clanak_ocjena').hide();
        $( '#clanak_ocjena_spinner').show();
        
        $( '#clanak_ocjena').load( _url , function(data)
        {
            $( '#clanak_ocjena_spinner').hide();
            $( '#clanak_ocjena').show();
        });
    }
}


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function mapController(p_arr_data, p_instance_name, p_rewrite_base, p_map_div) {
        
	this.arr_poi = p_arr_data; // array sa POI {poins of interest odnosno lokacijama ... [latitude,longitude,naslov,{url na clanak}]
    this._instance_name = p_instance_name; // ime objekta koji drzi sve
    this._rewrite_base = p_rewrite_base;
	this._map_div = p_map_div;
	this._map_loaded = false;
    
	var obj = this;
    this.map = null; //objekt mape
    
	this._lat_min =   90.0;
	this._lat_max =  -90.0;
	this._lng_min =  180.0;
	this._lng_max = -180.0;
        
	this.init_map = function() {
		if (!this._map_loaded) {
			this.map = new GMap2(document.getElementById(this._map_div));
			this.map.setCenter(new GLatLng(0,0),0);
			this.map.setUIToDefault();
			$.each(this.arr_poi, function(i,item){
				
				obj._lat_min = Math.min(obj._lat_min, parseFloat(item[0]));
				obj._lat_max = Math.max(obj._lat_max, parseFloat(item[0]));

				obj._lng_min = Math.min(obj._lng_min, parseFloat(item[1]));
				obj._lng_max = Math.max(obj._lng_max, parseFloat(item[1]));
				
				obj.map.addOverlay(obj._createMarker(i));
			});
			
			var bounds = new GLatLngBounds(new GLatLng(this._lat_min, this._lng_min) , new GLatLng(this._lat_max, this._lng_max));
			this.map.setCenter(bounds.getCenter(), this.map.getBoundsZoomLevel(bounds)-1);
			this._map_loaded = true;
		}
	}
	
	this._createMarker = function(i) {
		var point = new GLatLng(this.arr_poi[i][0],this.arr_poi[i][1]);
		var marker = new GMarker(point);
		GEvent.addListener(marker, 'click', function(){
			obj.showInfo(i);
		});
		return marker;
	}
	
	this.showInfo = function(i) {
		var html  = this.arr_poi[i][2];
		var point = new GLatLng(this.arr_poi[i][0],this.arr_poi[i][1]);
		this.map.openInfoWindowHtml(point, html);
	}
        
}  


