// JavaScript Document

function flyElement(type,extend){
	var el=$(document.createElement(type));
	return Object.extend(el, (extend || {}));
	}
	
if (window.opener){
	window.DM_fullscreen = true;	
}
else { window.DM_fullscreen = false; }
	
Event._keyCode= function(event){
	if (!event) return false;
	if (event.keyCode){
		if (event.keyCode==10 && event.ctrlKey){
			return 13;
			}
		return event.keyCode;
		}
	else if (event.which){
		return event.which;
		}
	else return false;
	}
	
	
	
function hide_locationBar(e){
		el = Event.element(e);
		if (el != this || el.open==false){ return false; }
		Event.stopObserving(this, 'click', hide_locationBarListener);
		Event.stopObserving(this, 'click', show_locationBarListener);
		
		new Effect.Move(this, { y:-41, x:0,  mode:'relative', afterFinish: function(eff){
															Event.observe(eff.element, 'click', show_locationBarListener);
															eff.element.open=false;
															setCookie('locationBarOpen','false',1);
											}});
	}
function show_locationBar(e){
		el = Event.element(e);
		if (el != this || el.open==true){ return false; }
		Event.stopObserving(this, 'click', hide_locationBarListener);
		Event.stopObserving(this, 'click', show_locationBarListener);
		new Effect.Move(this, { y:41, x:0, mode:'relative', afterFinish: function(eff){
															Event.observe(eff.element, 'click', hide_locationBarListener);
															eff.element.open = true;
															setCookie('locationBarOpen','true',1);
											}});
		
		
	}



Event.observe(window, 'load', function(){
		
		
		
		
		var holder = new Element('DIV', { id: 'locationBar_holder', align:'center'});
		var center = new Element('CENTER');

		
		var inner_holder = new Element('DIV', { id: 'locationBar_inner_holder'});
			
		var back_button = new Element('A', { id: 'locationBar_back', href:'#nazaj' }).update('<img class="mouseover" src="/imgs/bgs/button_back_p.gif" alt="Nazaj" title="Nazaj" width="42" height="16" align="baseline" />&nbsp;');
		var fw_button = new Element('A', { id: 'locationBar_fw', href:'#naprej'}).update('&nbsp;<img class="mouseover" src="/imgs/bgs/button_fw_p.gif" alt="Naprej" title="Naprej" width="42" height="16" align="baseline" />&nbsp;');
		var print_button = new Element('A', { id: 'locationBar_print', href:'#printaj'}).update('&nbsp;<img class="mouseover" src="/imgs/bgs/print_button_light_p.gif" alt="Natisni trenutno stran" title="Natisni trenutno stran" align="baseline" />&nbsp;');
		var close_button = new Element('A', { id: 'locationBar_close', href:'#zapri'}).update('&nbsp;<img class="mouseover" src="/imgs/bgs/close_button_light_p.gif" alt="Zapri okno" title="Zapri okno" align="baseline" />&nbsp;');
		
		
		
		var location = new Element('INPUT', { id: 'locationBar_location', type: 'text', name:'URIlocation', value: window.location, title: "direktna povezava do trenutne strani" });
		var toggler = new Element('DIV', { id:'locationBar_toggler'});
		var right_buttons = new Element('DIV', { id: 'locationBar_right_holder'}).setStyle({ 'float': 'right', marginRight:'10px'});
		right_buttons.appendChild(print_button);
		if (window.DM_fullscreen){
		right_buttons.appendChild(close_button);
		}
		
		inner_holder.appendChild(right_buttons);
		inner_holder.appendChild(back_button);
		inner_holder.appendChild(fw_button);
		inner_holder.appendChild(location);
		
		
		center.appendChild(inner_holder);
		holder.appendChild(center);
		
		
		document.body.appendChild(holder);
		
		hide_locationBarListener = hide_locationBar.bindAsEventListener(inner_holder);
		show_locationBarListener = show_locationBar.bindAsEventListener(inner_holder);
		
		document.fire("UI:refresh");
		
		
		if (getCookie('locationBarOpen')=='true') {
			inner_holder.style.top="41px";
			inner_holder.style.position="relative";
			Event.observe(inner_holder, 'click', hide_locationBarListener);
			}
		else {
			Event.observe(inner_holder, 'click', show_locationBarListener);
		}
		back_button.onclick='return false;';
		fw_button.onclick='return false;';
		Event.observe(back_button, 'click', function(ev){ ev.stop(); history.back(); }.bindAsEventListener(window));
		Event.observe(fw_button, 'click', function(ev){ ev.stop(); history.forward(); }.bindAsEventListener(window));
		Event.observe(print_button, 'click', function(ev, location){ ev.stop(); window.location = this.value + '?action=print';  }.bindAsEventListener(location));
		Event.observe(close_button, 'click', function(ev){ ev.stop(); if (window.opener) { window.opener.location=window.location; } window.close(); }.bindAsEventListener(window));
		
		location.observe('change', function(el){ window.location = $('locationBar_location').value; });
		location.observe('keypress', function(ev){ 
								
								if (Event._keyCode(ev)==13){
									if (ev.ctrlKey && ev.shiftKey){
											window.open('http://www.' + this.value.replace(/^http:\/\/www.|http:\/\//,'') + '.com');
											}
									else if (ev.ctrlKey){
										var new_loc = 'http://www.' + this.value.replace(/^http:\/\/www.|http:\/\//,'') + '.com'; 
										}
									else if (ev.shiftKey) {
										var new_loc = 'http://www.' + this.value + '.si';
										}
									else {
										var new_loc = this.value;
										}
									window.location = new_loc;
									}
								}.bindAsEventListener(location));
		document.observe('Ajax:update', function(ev){  this.value= ev.memo.response.request.url; }.bind(location));;
				
	
									   
}); // END window load function observer
