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()
{
	/** banner **/
	var winWidth = $(window).width();
	var maxHeight = $('#container').height();
	$('.wall_right').css('height',maxHeight);
	if( winWidth > 1000) {
		$('html').css('width', winWidth);
		$('html').css('overflow-x', 'hidden');
		$('.wall_right').css('display','block');
	} else {
		$('html').css('width', 1000);
		$('html').css('overflow-x', 'scroll');
		$('.wall_right').css('display','none');
	}
}
);

$(window).bind('resize', function() {
	var winWidth = $(window).width();
	if( winWidth > 1000) {
		$('html').css('width', winWidth);
		$('html').css('overflow-x', 'hidden');
		$('.wall_right').css('display','block');
	} else {
		$('html').css('width', 1000);
		$('html').css('overflow-x', 'scroll');
		$('.wall_right').css('display','none');
	}
});


$().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'
    });
	
	$('#ispravi_greske_float').jqm({
		trigger: '.ispravi_greske_trigger',
		overlay: 60,
		overlayClass: 'blackOverlay'
    });

	$('#pravila_komentiranja_float').jqm({
		trigger: '.pravila_komentiranja_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( $('#tabs_wrap').length != 0 ){
    		$('#tabs_wrap .tabs_nav a').click(function(){
			
				if( $(this).attr('rel')!='external' ) {
					$('#tabs_wrap .tabs_nav li').removeClass('active');		
					$(this).closest('li').addClass('active');
					$('#tabs_wrap .tabs_content').removeClass('active');
					$('#'+$(this).attr('rel')).addClass('active').show();
					
				}			
			});
			
			
			if(window.location.hash!=''){
				var tabsWrapSlide = parseFloat(window.location.hash.replace('#slide_',''));
				$('#tabs_wrap .tabs_nav li:eq('+tabsWrapSlide+') a').trigger('click');
			} 
			
    	}
    	

		if( typeof $('#slider_special') != 'undefined' ){
	        $("#slider_special").easySlider({
				auto: true,
				continuous: true,
				prevText: '',
				nextText:'',
				speed: 500,
				pause: 15000
	        });
		}

		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: 15000
	        });
		}
		
		if( typeof $('#slider_special_3') != 'undefined' ){
	        $("#slider_special_3").easySlider({
				auto: true,
				continuous: true,
				prevText: '',
				nextText:'',
				prevId: 'prevBtn_2',
				nextId: 'nextBtn_2',
				speed: 500,
				pause: 15000
	        });
		}
		
		if( typeof $('#slider_special_4') != 'undefined' ){
	        $("#slider_special_4").easySlider({
				auto: false,
				continuous: true,
				prevText: '',
				nextText:'',
				prevId: 'prevBtn_4',
				nextId: 'nextBtn_4',
				speed: 500,
				pause: 15000
	        });
		}
		
		if( typeof $('#slider_special_5') != 'undefined' ){
	        $("#slider_special_5").easySlider({
				auto: true,
				continuous: true,
				prevText: '',
				nextText:'',
				prevId: 'prevBtn_5',
				nextId: 'nextBtn_5',
				speed: 500,
				pause: 15000
	        });
		}
		

		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");
}

/* NEWS TICKER OBJECT  */
var _3k_newsTicker = {
	timer : 40,
	interval: null,
	movement: null,
	wrapper: '#decision_ticker',
	stripWidth: 0,
	init: function() {
		if (!_3k_newsTicker.interval) {
			$(_3k_newsTicker.wrapper+' .scroller').mouseover(function(){
				_3k_newsTicker.stopScroll();
			}).mouseout(function(){
				_3k_newsTicker.startScroll();
			});
			$(_3k_newsTicker.wrapper+' li').each(function(i){
				_3k_newsTicker.stripWidth += jQuery(this, i).outerWidth(true);
			});
			$(_3k_newsTicker.wrapper+' ul').width(_3k_newsTicker.stripWidth*2).append( $(_3k_newsTicker.wrapper+' ul').html() );
			$(_3k_newsTicker.wrapper+' ul')[0].style.left = '0px';
			_3k_newsTicker.startScroll();
		}
	},
	scrollFunc: function() {
		movement = -1;
		var listLeft = parseFloat($(_3k_newsTicker.wrapper+' ul')[0].style.left);
		if( (-_3k_newsTicker.stripWidth>listLeft) || (0<listLeft) ){
			listLeft = 0;
		}
		$(_3k_newsTicker.wrapper+' ul')[0].style.left = (listLeft+movement)+"px";
	},
	startScroll: function() {
		if (!this.interval) {
			this.interval = setInterval('_3k_newsTicker.scrollFunc()', this.timer);
		}
	},
	stopScroll: function() {
		if (this.interval) {
			clearInterval(this.interval);
			this.interval = false;
		}
	}
};

var _3k_newsTicker_02 = {
	timer : 40,
	interval: null,
	movement: null,
	wrapper: '#news_ticker',
	stripWidth: 0,
	init: function() {
		if (!_3k_newsTicker_02.interval) {
			$(_3k_newsTicker_02.wrapper+' .scroller').mouseover(function(){
				_3k_newsTicker_02.stopScroll();
			}).mouseout(function(){
				_3k_newsTicker_02.startScroll();
			});
			$(_3k_newsTicker_02.wrapper+' li').each(function(i){
				_3k_newsTicker_02.stripWidth += jQuery(this, i).outerWidth(true);
			});
			$(_3k_newsTicker_02.wrapper+' ul').width(_3k_newsTicker_02.stripWidth*2).append( $(_3k_newsTicker_02.wrapper+' ul').html() );
			$(_3k_newsTicker_02.wrapper+' ul')[0].style.left = '0px';
			_3k_newsTicker_02.startScroll();
		}
	},
	scrollFunc: function() {
		movement = -1;
		var listLeft = parseFloat($(_3k_newsTicker_02.wrapper+' ul')[0].style.left);
		if( (-_3k_newsTicker_02.stripWidth>listLeft) || (0<listLeft) ){
			listLeft = 0;
		}
		$(_3k_newsTicker_02.wrapper+' ul')[0].style.left = (listLeft+movement)+"px";
	},
	startScroll: function() {
		if (!this.interval) {
			this.interval = setInterval('_3k_newsTicker_02.scrollFunc()', this.timer);
		}
	},
	stopScroll: function() {
		if (this.interval) {
			clearInterval(this.interval);
			this.interval = false;
		}
	}
};

function fw3k_anketa_controller( p_anketa_id, p_app_rewrite_base, p_answer_count )
{

    this._anketa_id = p_anketa_id;
    this._app_rewrite_base = p_app_rewrite_base;
    this._url = p_app_rewrite_base + (window.location.href.indexOf('/sport/')>-1 ? 'sport/' : '') +'index.php?cmd=show_anketa&anketa_id=' + p_anketa_id;
    this._window_parameters = 'width=640, height=480, scrollbars=yes';
    this.additional_parameters = '';
	this._answer_count = parseInt( p_answer_count );

    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.glasaj = function()
    {
        var _input_name = 'anketa_' + this._anketa_id;

        var _cookie = 'VECERNJI_aodg_'+this._anketa_id;
        var _cookie_val = this.get_cookie(_cookie);
        if (_cookie_val == null) {
            this.set_cookie(_cookie, 0, false, '/');
        }

        var _odgovor_id = $( "input[@name='" + _input_name + "']:checked" ).val();

        if( typeof( _odgovor_id ) != 'undefined' ){
            if( typeof( document.getElementById( 'float_anketa' ) ) != 'undefined' ){
                $( '#float_overlay' ).show();
                $( '#float_spinner' ).show();
                $( '#float_anketa' ).hide();

                $( '#float_anketa' ).load( this._url + '&action=odgovori&odgovor_id=' + _odgovor_id + this.additional_parameters, '', function()
                {
                    $( '#float_overlay' ).show();
					$( '#float_spinner' ).hide();
                    $( '#float_anketa' ).show();
                }
                );

            } else {
                var obj_win = window.open( this._url + '&action=odgovori&odgovor_id=' + _odgovor_id + this.additional_parameters, 'obj_win', this._window_parameters );
            }
        }
    };

	this.ocjeni = function()
	{
        var _form_name = 'forma_anketa_' + this._anketa_id;

        var _cookie = 'VECERNJI_aodg_'+this._anketa_id;
        var _cookie_val = this.get_cookie(_cookie);
        if (_cookie_val == null) {
            this.set_cookie(_cookie, 0, false, '/');
        }

		var $form = $('#'+_form_name);
		var inputs = $( '#'+_form_name+' input:radio:checked' )
		var select_count =  inputs.length;

		// imamo sve odgovore
		if ( ( select_count > 0 ) && ( select_count == this._answer_count ) )
		{
			// kreiranje querystringa sa odgovorima
			var arr = [];
			$.each(inputs, function(idx,value)
				{
					odgovor_id = $(value).attr('rel');
					var odg = 'o['+odgovor_id+']='+$(value).val();
					arr.push( odg );

				}
			);

			var odg_qstr = arr.join('&');

			var _url = this._url + '&action=ocjeni&'+odg_qstr;

			if( typeof( document.getElementById( 'float_anketa' ) ) != 'undefined' )
			{
                $( '#float_overlay' ).show();
                $( '#float_spinner' ).show();
                $( '#float_anketa' ).hide();

                $( '#float_anketa' ).load(_url, null, function()
					{
					    $( '#float_overlay' ).show();
						$( '#float_spinner' ).hide();
					    $( '#float_anketa' ).show();
					}
                );

			} else {
                var obj_win = window.open( _url, 'obj_win', this._window_parameters );
			}
		}
		
		else
		{
			alert( "Morate odgovoriti na sva pitanja!" );
		}


	}
	
	this.captcha_glasaj = function() {
		var _input_name= 'anketa_' + this._anketa_id;

        var _cookie = 'VECERNJI_aodg_'+this._anketa_id;
        var _cookie_val = this.get_cookie(_cookie);
        if (_cookie_val == null) {
            this.set_cookie(_cookie, 0, false, '/');
        }

        var _odgovor_id   = $( "form#captcha input[@name='" + _input_name + "']:checked" ).val();
		var _captcha_hash = $( "form#captcha #captcha_hash").val();
		var _captcha_str  = escape($( "form#captcha #captcha").val());

        if( typeof( _odgovor_id ) != 'undefined' ){
            if( typeof( document.getElementById( 'float_anketa' ) ) != 'undefined' ){
                $( '#float_overlay' ).show();
                $( '#float_spinner' ).show();
                $( '#float_anketa' ).hide();

                $( '#float_anketa' ).load( this._url + '&action=odgovori&captcha=true&captcha_str=' + _captcha_str + '&captcha_hash=' + _captcha_hash + '&odgovor_id=' + _odgovor_id + this.additional_parameters, '', function()
                {
					$( '#float_overlay' ).show();
					$( '#float_spinner' ).hide();
                    $( '#float_anketa' ).show();
                }
                );

            } else {
                var obj_win = window.open( this._url + '&action=odgovori&odgovor_id=' + _odgovor_id + this.additional_parameters, 'obj_win', this._window_parameters );
            }
        }
	}

    this.rezultati = function()
    {
        if( typeof( document.getElementById( 'float_anketa' ) ) != 'undefined' ){
            $( '#float_overlay' ).show();
            $( '#float_spinner' ).show();
            $( '#float_anketa' ).hide();
            $( '#float_anketa' ).load( this._url + this.additional_parameters, '', function()
            {
                $( '#float_spinner' ).hide();
                $( '#float_anketa' ).show();
            }
            );

        } else {
            var obj_win = window.open( this._url + this.additional_parameters, 'obj_win', this._window_parameters );
        }
    };

    fw3k_anketa_controller.close = function()
    {
        $( '#float_overlay' ).hide();
        $( '#float_anketa' ).hide();
    }

}



