function write_swf(filename,id,width,height,extra) {
	document.write('<object type="application/x-shockwave-flash" data="'+filename+(id!=null?'?cid='+id:'')+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+filename+(id!=null?'?cid='+id:'')+'" />');
	
	document.write('<param name="quality" value="autohigh" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="menu" value="false" />');
	

	for (i in extra) {
			document.write('<param name="'+extra[i][0]+'" value="'+extra[i][1]+'" />');
	}
	document.write('</object>');
}

/*
* PROTOTYPES for IE and other older browsers
*/
// in array function
function inArray(needle, haystack) {
	for (h in haystack) {
		if (haystack[h] == needle) {
			return true;
		}
	}
	return false;
}
// indexOf function
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++) {
      if (from in this && this[from] === elt)
	  return from;
    }
    return -1;
  };
} 

/* toggle font / line size */
/* set cookie */
//function setCookie(name, value, expires, path, domain, secure) {
function setCookie(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=/";
}

/* get cookie */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/* delete cookie */
function deleteCookie( name, path, domain ) {
	if ( getCookie(name) ) 
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var text_sizes		= [12, 14, 16];
var line_heights	= [1.4, 1.6, 1.8];

var def_text_size = 0;
var def_line_height = 0;

var current_lh = false;
var current_ts = false;

var first_page = false;

var content_placeholder = 'middleblock';

function change_line_height() {

	if (!current_lh)
	current_lh = getCookie('line_height');

	if (!current_lh) current_lh = def_line_height;
	current_lh ++;
	if (current_lh == line_heights.length) current_lh = 0;

	setCookie('line_height', current_lh, 365);
	if (first_page) {
		document.getElementById('push_news').style.lineHeight = line_heights[current_lh] + "em";
		document.getElementById('push_strokovnjak').style.lineHeight = line_heights[current_lh] + "em";
	} else {
		document.getElementById('middleblock').style.lineHeight = line_heights[current_lh] + "em";
	}
}

function change_text_size() {
	if (!current_ts)
		current_ts = getCookie('text_size');
	if (!current_ts) current_ts = def_text_size;
	current_ts ++;
	if (current_ts == text_sizes.length) current_ts = 0;
	setCookie('text_size', current_ts, 365);
	if (first_page) {
		document.getElementById('push_news').style.fontSize = text_sizes[current_ts] + "px";
		document.getElementById('push_strokovnjak').style.fontSize = text_sizes[current_ts] + "px";
	} else {
		document.getElementById('middleblock').style.fontSize = text_sizes[current_ts] + "px";
	}
}

/* returns the x,y coordinates of the current screen (for multi monitor setup) */
function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	} else {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}


/* generic window opener */
function openwin(uri,title,w,h){
	if(w){wwidth = w;}else{	wwidth = 380;}
	if(h){wheight = h; }else{ wheight = 380;}
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, title, "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=no, resizable=no, directories=no");
}


function change_bg(type, obj) {
	
	object = document.getElementById(obj);
	
	if (type == 'over') {
		object.style.backgroundPosition = 'bottom left';
	}
	
	if (type == 'out') {
		object.style.backgroundPosition = 'top left';
	}
}


function write_flash(filename, w, h, param, transparent) {
	document.write('<object align="middle" type="application/x-shockwave-flash" data="'+filename+'" Width="'+w+'" height="'+h+'">');
	document.write('<param name="movie" value="'+filename+'" />');
	document.write('<param name="FlashVars" value="'+param+'" />');
	if (transparent) {
		document.write('<param name="wmode" value="transparent" />');
	}
	document.write('</object>');
}

//gallery
var gal_index = 0;
function change_gal_image(mode) {
	if (mode == 'naprej') {
		gal_index ++;
		if (gal_index > gallery.length-1) {
			gal_index = 0;
		}
	} else {
		gal_index --;
		if (gal_index < 0) {
			gal_index = gallery.length-1;
		}
	}
	$('#big_image_src').attr('src', gallery[gal_index]);
	$('#gallery_nav_text').attr('innerHTML', gal_text[gal_index]);
	//$('#opengal').attr('href', gallery[gal_index]);
	$('.generic').attr('rel', gal_index+1);
	$('#gallery_nav_text').attr('rel', gal_index+1);
	//$('#gallery_tools span').html((gal_index+1)+' / '+ gallery.length);
}


/**********************************************/
/* first page news ticker */

var newsitems = Array();
var scroll_index = 0;
var scroll_height = 26;
var s, newsitems;
var scroll_timeout = 1;
var pause_timeout = 4000; 
var newslink_nav1; //Gumb za več o novici
var newslink; // Link na ta gumb

function setup_scroller() {
	

	
	if ((s = document.getElementById('scroller')) != null) {
	
		newsitems = s.getElementsByTagName('DIV');
			
		if (newsitems.length > 0) {
			for (i=0; i<newsitems.length; i++) {
				newsitems[i].style.top = i * scroll_height + "px";
				newsitems[i].style.display = 'block';
			}
			if (newsitems.length > 1) {
				setTimeout(scroll, scroll_timeout);
			}
		}
	
	}
}

function pause() {
	setTimeout(scroll, pause_timeout);
}

function scroll() {
	do_pause = false;
	newslink_nav1 = document.getElementById('newsbar_nav1'); // gumb za Več... o novici
	
	for (i=0; i<newsitems.length; i++) {
		
		current_top = parseInt(newsitems[i].style.top);
		
		if (current_top < -scroll_height) {
			newsitems[i].style.top = ((newsitems.length-1) * scroll_height) + "px";
			current_top =  ((newsitems.length-1) * scroll_height);
		}
		
		newsitems[i].style.top = (current_top - 1) + "px";
		newslink = document.getElementById('novica' + i).href; // Link za gumb več o novici
		
		if (current_top == 0) {
			do_pause = true;
			newslink_nav1.href = newslink;	// Gumbu za več o novici dodamo link na posamezno novico 
		}

	}
	
	if (do_pause == true) {
		pause();
	} else {
		setTimeout(scroll, scroll_timeout);
	}
	
}

$(document).ready(function(){
	setup_scroller();
});

/***********************************/



//popover forms

function open_popover(adress) {
	
	if (typeof($('#pop_overlay')[0]) == 'undefined') {
		
		var overlay  = '<div id="pop_overlay"></div>';
		$("body").append(overlay);
		
		// applying style
		$("#pop_overlay").css({
			opacity: 0.7
		});
		
		$("#pop_overlay").css({ height:$(document).height() });
		
		$("#pop_overlay").bind('click', function() {
			$('#pop_frame, #pop_overlay, #pop_close').fadeOut('fast', function() {
				$(window).unbind('scroll', pop_position);
			})
		});
	}
	
	
	
	if (typeof($('#pop_frame')[0]) == 'undefined') {
			var pop_frame = '<iframe id="pop_frame" src="" width="960" height="480" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe>';
			$("body").append(pop_frame);
			
			var frame_left = ($(document).width()/2) - (560/2);
			if (typeof document.body.style.maxHeight != "undefined") {
				var frame_top = 50;
			} else {
				var frame_top = $(document).scrollTop() + Math.round(($(window).height() - 480)/2);
			}

			$('#pop_frame').css({
				position: 'absolute',
				left: frame_left,
				top: frame_top
			});
			
			if (typeof($('#pop_close')[0]) == 'undefined') {
				$("body").append('<div id="pop_close"><a href="#" onclick="return false;"></a></div>');
				
				$('#pop_close').css({
					position: 'absolute',
					left: frame_left + 533,
					top: frame_top - 17
				});
				
				$("#pop_close").bind('click', function() {
					$('#pop_frame, #pop_overlay, #pop_close').fadeOut('fast', function() {
						$(window).unbind('scroll', pop_position);
					});
					return false;
				});
			}
			
			
	}
	
	
	
	// opening sequence
	$("#pop_overlay").fadeIn('normal', function() {
			$('#pop_frame')[0].src=adress;
			$('#pop_frame, #pop_close').fadeIn('normal');
			
			// IE 7 hack
			// Ce ni IE6, pozicioniraj
			if (typeof document.body.style.maxHeight != "undefined") {
				$('#pop_frame').css({ position: 'fixed' });
				$('#pop_close').css({ position: 'fixed' });
			} else {
				$(window).bind('scroll', pop_position);
			}
	});


}

function pop_position() {
	
	var frame_left = ($(document).width()/2) - (560/2);
	if (typeof document.body.style.maxHeight != "undefined") {
		var frame_top = 50;
	} else {
		var frame_top = $(document).scrollTop() + Math.round(($(window).height() - 480)/2);
	}
	
	$('#pop_frame').css({
		position: 'absolute',
		left: frame_left,
		top: frame_top,
		zIndex: 100
	});
}

/************** SIMULATOR popover forms *************/

function open_simulator_popover(adress) {
	
	
	if (typeof($('#pop_simulator_overlay')[0]) == 'undefined') {
		
		var overlay  = '<div id="pop_simulator_overlay"></div>';
		$("body").append(overlay);
		
		// applying style
		$("#pop_simulator_overlay").css({
			opacity: 0.7,
			zIndex: 100
		});
		
		$("#pop_simulator_overlay").css({ height:$(document).height() });
		
		$("#pop_simulator_overlay").bind('click', function() {
			$('#pop_simulator_frame, #pop_simulator_overlay, #pop_simulator_close').fadeOut('fast', function() {
				$(window).unbind('scroll', pop_simulator_position);
			})
		});
	}
	
	
	
	if (typeof($('#pop_simulator_frame')[0]) == 'undefined') {
			var pop_simulator_frame = '<iframe id="pop_simulator_frame" src="" width="960" height="580" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>';
			$("body").append(pop_simulator_frame);
			
			var frame_left = ($(document).width()/2) - (960/2);
			if (typeof document.body.style.maxHeight != "undefined") {
				var frame_top = 75;
			} else {
				var frame_top = $(document).scrollTop() + Math.round(($(window).height() - 580)/2);
			}

			$('#pop_simulator_frame').css({
				position: 'absolute',
				left: frame_left,
				top: frame_top
			});
			
			if (typeof($('#pop_simulator_close')[0]) == 'undefined') {
				$("body").append('<div id="pop_simulator_close"><a href="#" onclick="return false;"></a></div>');
				
				$('#pop_simulator_close').css({
					position: 'absolute',
					left: frame_left + 939,
					top: frame_top + 7
				});
				
				$("#pop_simulator_close").bind('click', function() {
					$('#pop_simulator_frame, #pop_simulator_overlay, #pop_simulator_close').fadeOut('fast', function() {
						$(window).unbind('scroll', pop_simulator_position);
					});
					return false;
				});
			}
			
			
	}
	
		
	// opening sequence
	$("#pop_simulator_overlay").fadeIn('normal', function() {
			$('#pop_simulator_frame')[0].src=adress;
			$('#pop_simulator_frame, #pop_simulator_close').fadeIn('normal');
			
			// IE 7 hack
			// Ce ni IE6, pozicioniraj
			if (typeof document.body.style.maxHeight != "undefined") {
				$('#pop_simulator_frame').css({ position: 'fixed' });
				$('#pop_simulator_close').css({ position: 'fixed' });
			} else {
				$(window).bind('scroll', pop_simulator_position);
			}
	});
	
	
}

function pop_simulator_position() {
	
	var frame_left = ($(document).width()/2) - (960/2);
	if (typeof document.body.style.maxHeight != "undefined") {
		var frame_top = 75;
	} else {
		var frame_top = $(document).scrollTop() + Math.round(($(window).height() - 580)/2);
	}
	
	$('#pop_simulator_frame').css({
		position: 'absolute',
		left: frame_left,
		top: frame_top,
		zIndex: 100
	});
}

/*********** END SIMULATOR*********/

	
