$(document).ready(function(){
	
	tooltip(); // tooltip za predmete
	
	$('#obavijest_kategorija').wait(2000).fadeIn(2000);
	
	$('.ocjena').live('click', function() {
		var a = $(this).attr('name');
		alert(a.substr(1,1));
	});
	
	$('.ocjene').live('keyup focus blur',function () {
		this.value = this.value.replace(/[^0-5]/g,'');
	});
	
	$('.ocjene_l').live('keyup focus blur',function () {
		this.value = this.value.replace(/[^0-5]/g,'');
	});
	
	$(".box_open").fancybox({
			'titleShow'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'autoDimensions'	: false,
			'padding'			: 6,
			'overlayColor'		: '#000000',
			'width'				: 400,
			'height'			: 400
	});
	
	$(".gal_open").fancybox({
			'titleShow'			: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'autoDimensions'	: false,
			'padding'			: 6,
			'overlayColor'		: '#000000',
			'width'				: 400,
			'height'			: 400
	});
	
});

$.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};

	var ocjene = {};
	function get_ocjene()
	{
		$.each($('#f_podaci').serializeArray(), function(i, field) {
			ocjene[field.name] = field.value;
		});
		
		var html='';
		for (var key in ocjene) {
			
			if(key.substr(0,4) == 'oc_c' && ocjene[key])
				html +=	key+' : '+ocjene[key]+"\n\n";
		}
		
		//alert(html);
		
		//$('#test_div').innerHTML(html);
	}
	
	function reload_ocjene()
	{
		var html2='';
		for (var key in ocjene) {
			$('#'+key).val(ocjene[key]);
		}
	}
	
this.tooltip = function(){
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	
	$(".tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};
