/* profitiraj.hr javascript */


var prof={};


prof.inputs = function(){
	$('input[type=text],input[type=password],textarea').each(function(){
		$(this).focus(function(){
			if($(this).val()==$(this).attr('defaultValue')) $(this).val('');
		}).blur(function(){
			if($.trim($(this).val())=='') $(this).val($(this).attr('defaultValue'));
		});
	});
};




prof.dionice = new (function(){
	var handle = this;
	this.show = function(index){
		$('#diodabir a').each(function(i){
	 		(i==index) ? $(this).addClass('selected') : $(this).removeClass('selected');
		});
		$('#dionice table').each(function(i){
	 		(i==index) ? $(this).removeClass('inactiv') : $(this).addClass('inactiv');
		});	 
	};
	this.init = function(){ 
		$('#diodabir a').each(function(i){
			$(this).click(function(){handle.show(i);return false;});
		});
	};
	return this;
});


prof.dionice2 = function(){
	$("#odrast").click(function(){$("#dionice").removeClass();$("#dionice").addClass('rast');});
	$("#odpad").click(function(){$("#dionice").removeClass();$("#dionice").addClass('pad');});
	$("#odprom").click(function(){$("#dionice").removeClass();});	
};


/*
	function kreda(){
		var iznos = document.kreditna.iznos.value.replace(',','.');
		var kam = document.kreditna.kam.value.replace(',','.');
		var mje = document.kreditna.mje.value.replace(',','.');	
		var rata = iznos*(Math.pow(1+kam/100/12,mje)*(kam/100/12)/(Math.pow(1+kam/100/12,mje)-1));
		if(isNaN(rata)) document.kreditna.rata.value='Nepravilan unos!';
		else { document.kreditna.rata.value=Math.round(rata*100)/100; };
	}
*/


prof.onready = function(){
	prof.inputs();
	prof.dionice.init();
	prof.dionice2();
};


prof.init = function(){
	$(document).ready(this.onready);
};


prof.init();



// box krediti sa moj_bankar.hr
function moj_bankar_activate(i) {

	$('a.moj_bankar_tabbutton').removeClass('selected');
	$('a#moj_bankar_tabbutton_'+i).addClass('selected');

	$('table.moj_bankar_table').hide();
	$('table#moj_bankar_table_'+i).show();
}



//swither top 9 vijesti (3x3)
function top3_switch(i) {
    top9_current = i;
    $('.top3_switcher_link').removeClass('current');
    $('#top3_switcher_link_'+i).addClass('current');
    if (i==1) {
        $('#top3_featured_0').show('slow', function(){top9_select_this($(this));});
        $('#top3_featured_1').show('slow');
        $('#top3_featured_2').show('slow');
        $('#top3_featured_3').show('slow');
        $('#top3_featured_4').show('slow');
        $('#top3_featured_5').show('slow');
        $('#top3_featured_6').show('slow');
        $('#top3_featured_7').show('slow');
        $('#top3_featured_8').show('slow');
        
    }
    if (i==2) {
        $('#top3_featured_0').hide('slow');
        $('#top3_featured_1').hide('slow');
        $('#top3_featured_2').hide('slow');
        $('#top3_featured_3').show('slow', function(){top9_select_this($(this));});
        $('#top3_featured_4').show('slow');
        $('#top3_featured_5').show('slow');
        $('#top3_featured_6').show('slow');
        $('#top3_featured_7').show('slow');
        $('#top3_featured_8').show('slow');
    }
    if (i==3) {
        $('#top3_featured_0').hide('slow');
        $('#top3_featured_1').hide('slow');
        $('#top3_featured_2').hide('slow');
        $('#top3_featured_3').hide('slow');
        $('#top3_featured_4').hide('slow');
        $('#top3_featured_5').hide('slow');
        $('#top3_featured_6').show('slow', function(){top9_select_this($(this));});
        $('#top3_featured_7').show('slow');
        $('#top3_featured_8').show('slow');
    }
}

//rotacija top 9
var top9_automatic = true;
var top9_autodelay = 20;
var top9_autodelay_full = 5*9; // 9 sec
var top9_current = 1;
var top9_timestep = 200;
function top9_next() {
    setTimeout('top9_next()', top9_timestep);
    if (! top9_automatic) return;
    top9_autodelay -= 1;
    if (top9_autodelay < 1) {
        top9_autodelay = 0;
        top9_current += 1;
        if (top9_current > 3) {top9_current = 1;}
        top3_switch(top9_current);
        top9_automatic = true;
        top9_autodelay = top9_autodelay_full;
    }
    
}
function top9_select_this(that) {
    $("#top3 a.featured").removeClass("act");
    that.addClass("act");
}


//ProfitirajTV
var profitirajtvplayer;
var profitirajtvplayer_error = false;
var profitirajtvplayer_play = false;
var profitirajtvplayer_reload = true;
var profitirajtvplayer_hover = false;
var profitirajtvplayer_visible = true;
var profitirajtvplayer_timeout = 10;

function profitirajtv_init(obj) {
    profitirajtvplayer = document.getElementById(obj['id']);
    $('#teve').hover(
        function(){
            profitirajtvplayer_hover = true;
        },
        function(){
            profitirajtvplayer_hover = false;
        }
    );
    $("#teve").mousemove(function(){
        profitirajtvplayer_timeout = 5 * 2;
        profitirajtvplayer_hover = true;
    });
    $('#profitirajtv_overlay').fadeIn("fast");
    profitirajtv_update_overlay();
}
function profitirajtv_update_overlay(){
    setTimeout("profitirajtv_update_overlay()", 1000);
	
    if (profitirajtvplayer_reload) {
        i = profitirajtvplayer.getConfig()['item'];
        $('#profitirajtv_overlay a').attr('href', '/videopost/' + profitirajtv_overlay[i]["slug"]);
        $('#profitirajtv_overlay a').text(profitirajtv_overlay[i]["title"]);
		//jQuery("#protprot").text(profitirajtv_overlay[i]["title"]);
    }

    if (profitirajtvplayer_error) {
        if (profitirajtvplayer_visible)
            $('#profitirajtv_overlay').fadeOut("fast");
        profitirajtvplayer_visible = false;
        return;
    }

    if (profitirajtvplayer_play && !profitirajtvplayer_hover) {
        if (profitirajtvplayer_visible)
            $('#profitirajtv_overlay').fadeOut("fast");
        profitirajtvplayer_visible = false;
        return;
    }

    if (profitirajtvplayer_play && profitirajtvplayer_hover) {
        profitirajtvplayer_timeout -= 1;
        if (profitirajtvplayer_timeout < 1) {
            if (profitirajtvplayer_visible)
               $('#profitirajtv_overlay').fadeOut("fast");
            profitirajtvplayer_visible = false;
            profitirajtvplayer_timeout = 0;
        } else {
            if (!profitirajtvplayer_visible)
               $('#profitirajtv_overlay').fadeIn("fast");
            profitirajtvplayer_visible = true;
        }
        return;
    }

    if (!profitirajtvplayer_play) {
        profitirajtvplayer_visible = true;
        if (profitirajtvplayer_visible)
           $('#profitirajtv_overlay').fadeIn("fast");
        return;
    }


}

//var doc_ready_fired = false;
$(document).ready(function() {


    // top3 carousell
    $("#top3 a.featured").mouseover(function(){
        top9_select_this($(this));
    });
    /*/ bottom naj
    $("#najnov").mouseover(function(){
            $("#naj h2").removeClass("act2");
            $("#naj div").removeClass("act2");
            $(this).addClass("act2");
            $("#najnov2").addClass("act2");
    });

    $("#najcit").mouseover(function(){
            $("#naj h2").removeClass("act2");
            $("#naj div").removeClass("act2");
            $(this).addClass("act2");
            $("#najcit2").addClass("act2");
    });

    $("#najkom").mouseover(function(){
            $("#naj h2").removeClass("act2");
            $("#naj div").removeClass("act2");
            $(this).addClass("act2");
            $("#najkom2").addClass("act2");
    });
    */

    //manja veca slova na fullu
    $("#cpovecaj").click(function(){$("#complete p").addClass("big");});$("#csmanji").click(function(){$("#complete p").removeClass("big");});


    /*$('#top3').hover(function(){ //mouseenter
        top9_automatic = false;
    }, function(){               //mouseleave
        top9_automatic = true;
        top9_autodelay = top9_autodelay_full;
    });*/
	

    $('.top3_switcher_link').each(function(){
        $(this).hover(function(){
            i = parseInt($(this).attr('id').substr($(this).attr('id').length-1,1));
            if (i != top9_current) {top3_switch(i);}
        });
    });
    top9_autodelay = top9_autodelay_full;
    top9_next();

    try {

        jwplayer("tv").setup({
            playlistfile: "/tv/playlist.php",
            skin : "/tv/profitiraj.zip",
            flashplayer: "/tv/player.swf",
            "playlist.position": "right",
            "controlbar.position" : "over",
            playerready: "profitirajtv_init",
            "playlist.thumbs": "false",
            "playlist.position" : "right",
            height: 285,
            width: 560,
            events: {
                onPlay : function() {
                    profitirajtvplayer_play = true;
                    profitirajtvplayer_error = false;
                    profitirajtvplayer_reload = true;
                },
                onPause : function() {
                    profitirajtvplayer_play = false;
                },
                onComplete : function() {
                    profitirajtvplayer_play = false;
                },
                onError : function() {
                    profitirajtvplayer_error = true;
                }
            }
        });
           
        
        
    } catch (err) {}



});
