﻿function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

$(document).ready(function() {
	$("a.top").click(function () {
			backToTop();
			return false;
	 });
});

$(document).ready(function() {
	$(".lang-mid ul li.lang-selected").click(function () {
	    $('.lang-mid ul li.lang-off').toggle();
	    return false;
	 });
});

$(document).ready(function() {
	$(".lang-mid ul").blur(function () {
	    $('.lang-mid ul li.lang-off').toggle();
	    return false;
	 });
});

$(document).ready(function() {
	$(".searchbox").focus(function () {
	  $(this).parent().css("background-position","0 -29px");
	});
	$(".searchbox").blur(function () {
	  $(this).parent().css("background-position","0 0");
	});
});

$(document).ready(function() {
	$('input.search-go').hover(function () {
        	this.src = '/WebResources/img/search-go-hover.gif';
    	}, function () {
        	this.src = '/WebResources/img/search-go.gif';
   	});

	$("div.news-item").hover(
		function () {
			$(this).addClass("selected-news");
		},
		function () {
			$(this).removeClass("selected-news");
		});
		
	$("div.news-item").click(function() {
		window.location = $(this).find("a:first").attr("href");
	});
	
});


$(function () {
    $('div#tabs ul.tabnav a').click(function () {
        $('div#tabs ul.tabnav a').removeClass('tab-selected');
        $(this).addClass('tab-selected');
        return true;
    });
});

$(document).ready(function() {
	$("div.news-big").hover(
		function () {
			$(this).find('h3').css("color","#c00b0f");
			$(this).find('p').css("color","#000000");
			$(this).find('a.comments').css("color","#696969");
			$(this).find('a.full-news').css("color","#233e85");
			$(this).find('a.full-news').css("background-position","bottom right");
		},
		function () {
			$(this).find('h3').css("color","#233e85");
			$(this).find('p').css("color","#666666");
			$(this).find('a.comments').css("color","#999999");
			$(this).find('a.full-news').css("color","#c20c0f");
			$(this).find('a.full-news').css("background-position","top right");
		});
});

$(document).ready(function() {
$('.ta').click(
function() {
if (this.value == this.defaultValue) {
this.value = '';
}
}
);
$('.ta').blur(
function() {
if (this.value == '') {
this.value = this.defaultValue;
}
}
);
});



$(document).ready(function() {

var state='show';

$('div.infobox-body').show(0);

state = readCookie('infobox-cookie');
	
if (state) {
	if (state.trim()=='show') {
		$('div.infobox-body').show(0);
	}
	if (state.trim()=='hide') {
		$('div.infobox-body').hide(0);
	}	
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	try {
		var ca = document.cookie.split(';');
	}catch (err) {
		return false;
	}
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	alert('brisem kolac');
	createCookie(name,"",-1);
}


$('a.infobox-open').click(function(){
	$('div.infobox-body').show(0);
	createCookie('infobox-cookie','show',7);
	return false;
})

$('a.infobox-close').click(function(){
	$('div.infobox-body').hide(0);
	createCookie('infobox-cookie','hide',7);
	return false;
})

});

function listbox_move(listID, direction) {

	var listbox = document.getElementById(listID);
	var selIndex = listbox.selectedIndex;

	if(-1 == selIndex) {
		alert("Изабери барем један садржај, који желиш померити!");
		return;
	}

	var increment = -1;
	if(direction == 'up')
		increment = -1;
	else
		increment = 1;

	if((selIndex + increment) < 0 ||
		(selIndex + increment) > (listbox.options.length-1)) {
		return;
	}

	var selValue = listbox.options[selIndex].value;
	var selText = listbox.options[selIndex].text;
	listbox.options[selIndex].value = listbox.options[selIndex + increment].value
	listbox.options[selIndex].text = listbox.options[selIndex + increment].text

	listbox.options[selIndex + increment].value = selValue;
	listbox.options[selIndex + increment].text = selText;

	listbox.selectedIndex = selIndex + increment;
}

function listbox_moveacross(sourceID, destID, direction) {
	var src = document.getElementById(sourceID);
	var dest = document.getElementById(destID);

	if(dest.length > 3 && direction=='right') {
		alert("Можете изабрати највише 4 садржаја!");
	}
	else {
		if (src.length==0 && direction=='left') {
			alert("Не постоји ни један одабрани садржај!");
		}
		else {
			
			for(var count=0; count < src.options.length; count++) {

				if(src.options[count].selected == true) {
					var option = src.options[count];
					var newOption = document.createElement("option");
					newOption.value = option.value;
					newOption.text = option.text;
					newOption.selected = true;
					try {
						 dest.add(newOption, null); //Standard
						 src.remove(count, null);
				 	}catch(error) {
						 dest.add(newOption); // IE only
						 src.remove(count);
				 	}
					count--;
				}
			}
		}
	}
}
































