jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(function(){

	$.preloadImages("/web/ids/images/baner-pristupnica-active.jpg");

	$("#news_box").tabs();
	Clock();
	$("a.lightbox").lightBox();
	$(".person_info h3").click(function(){
		$(this).next().slideToggle("slow");
	});
	$('.boxy').boxy({
		modal: true,
		closeText: '[x]'
	});
	$('.news_scroller .newsitems').hover(
	function(){
	$(this).trigger('stop');
	},
	function(){
	$(this).trigger('start');
	});
	
	$('#sidebar_box_pristupnica').mousedown(function(){
		$('#sidebar_box_pristupnica img').attr('src', '/web/ids/images/baner-pristupnica-active.jpg');
	}).mouseup(function(){
		$('#sidebar_box_pristupnica img').attr('src', '/web/ids/images/baner-pristupnica.jpg');
	});
	
	$("#pristupnica form").submit(function(){
		var ime = $("input#ime").val();  
		var ime_oca = $("input#ime_oca").val();  
		var datum_rodjenja = $("input#datum_rodjenja").val();  
		var jmbg = $("input#jmbg").val();  
		var adresa = $("input#adresa").val();  
		var telefon = $("input#telefon").val();  
		var fax = $("input#fax").val();  
		var from = $("input#from").val();  
		var stupanj_ss = $("input#stupanj_ss").val();  
		var zvanje = $("input#zvanje").val();  
		var tvrtka = $("input#tvrtka").val();  
		var radno_mjesto = $("input#radno_mjesto").val();  
		var telefon_radno_mjesto = $("input#telefon_radno_mjesto").val();  
		var fax_radno_mjesto = $("input#fax_radno_mjesto").val();  
		var jezici = $("input#jezici").val();  
		var posebni_interesi = $("textarea#posebni_interesi").text();  
		var ostalo = $("textarea#ostalo").text();  

		var dataString = 'ime='+ ime +
			'&ime_oca=' + ime_oca +
			'&datum_rodjenja=' + datum_rodjenja +
			'&jmbg=' + jmbg +
			'&adresa=' + adresa +
			'&telefon=' + telefon +
			'&fax=' + fax +
			'&from=' + from +
			'&stupanj_ss=' + stupanj_ss +
			'&zvanje=' + zvanje +
			'&tvrtka=' + tvrtka +
			'&radno_mjesto=' + radno_mjesto +
			'&telefon_radno_mjesto=' + telefon_radno_mjesto +
			'&fax_radno_mjesto=' + fax_radno_mjesto +
			'&jezici=' + jezici +
			'&posebni_interesi=' + posebni_interesi +
			'&ostalo=' + ostalo +
			'&_subject=' + 'Pristupnica' +
			'&_fromField=' + 'from' +
			'&_to=' + '82,86,-68,-37,-119,95,-23,-8,-124,-43,-57,-85,84,75,54,65,73,8,-32,94,82,-28,15,-27,-66,99,90,57,59,33,-3,-11' +
			'&_language=' + 'hr' +
			'&_mf=' + 'ime,from' +
			'&_type=' + 'general' +
			'&_responseFormat=' + 'json'; 
		$.ajax({  
			type: "POST",  
			url: "/mailtransport.jsp",  
			data: dataString,  
			success: function(response) {  
				var data = eval('(' + response + ')');
				if( data.status == true ) {
					Boxy.get($("#pristupnica")).hide();
					alert("Pristupnica poslana. Hvala.");
				} else {
					var message = "Greška!\n";
					for (var i=0;i<data.messages.length;i++) {
						message += data.messages[i] + "\n";
					}
					alert(message);
				}
			}
		});  
		return false;
	});
});

jQuery(function( $ ){
    $('div.news_scroller').serialScroll({
        target:'div.newsitems',
        items:'div.news-item', // Selector to the items ( relative to the matched elements, '#sections' in this case )
        //prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
        //next:'img.next',// Selector to the 'next' button (absolute too)
        axis:'y',// The default is 'y' scroll on both ways
        //navigation:'#navigation li a',
        duration:1500,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
        force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
        //queue:false,// We scroll on both axes, scroll both at the same time.
        //event:'click',// On which event to react (click is the default, you probably won't need to specify it)
        //stop:false,// Each click will stop any previous animations of the target. (false by default)
        //lock:true, // Ignore events if already animating (true by default)
        //start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )
        cycle:true,// Cycle endlessly ( constant velocity, true is the default )
        //step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
        //jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
        //lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
        interval:2000, // It's the number of milliseconds to automatically go to the next
        //constant:true, // constant speed
        onBefore:function( e, elem, $pane, $items, pos ){
            /**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
            //those arguments with a $ are jqueryfied, elem isn't.
            e.preventDefault();
            if( this.blur )
                this.blur();
        },
        onAfter:function( elem ){
        //'this' is the element being scrolled ($pane) not jqueryfied
        }
    });
    $('#traka_izbori').serialScroll({
		items:'td',
		duration:5000,
		force:true,
		axis:'x',
		easing:'linear',
		interval:5000,
		step:7
    });

});

function Clock() {
	if (!document.getElementById) return;
	theclock=document.getElementById("current-date");
	now = new Date();
	hours=now.getHours();
	mins=now.getMinutes();
	secs=now.getSeconds();
	month = now.getMonth() + 1;
	day = now.getDate();
	year = now.getYear();
	if (year < 2000) year = year + 1900;
	if (secs < 10) secs= "0" + secs;
	if (mins < 10) mins= "0" + mins;
	theclock.innerHTML = day + "." + month + "." + year + " " + hours + ":" + mins + ":" + secs;
	window.setTimeout("Clock();",500);
} 

