var image_folder = '';

function playerReady(thePlayer) {
    player = window.document[thePlayer.id];
    player.sendEvent('LOAD', lst);
}

function calendarRefresh(day) {
	  for(i=0;i<32;i++) {
		  (document.getElementById('d'+i)) ? document.getElementById('d'+i).style.display='none' : false; 
	  }
  	  document.getElementById('d'+day) ? document.getElementById('d'+day).style.display='block' : false; 
}


function setupCalendar(){

if($$('.calendar-previous a')[0]){
  $$('.calendar-previous a')[0].observe('click', function(evt){
    evt.stop()
    $('kalendar-dogadjanja').fade({from:1, to:0.5})
    new Ajax.Request($$('.calendar-previous a')[0].rel, {
      method: 'get',
      onSuccess: function(transport) {  
       $('kalendar-dogadjanja').update(transport.responseText)
       $('kalendar-dogadjanja').appear({from:0.5, to:1})
       setupCalendar();
      }
    });
  })
}

if($$('.calendar-next a')[0]){
  $$('.calendar-next a')[0].observe('click', function(evt){
    evt.stop();
    $('kalendar-dogadjanja').fade({from:1, to:0.5})
    new Ajax.Request($$('.calendar-next a')[0].rel, {
      method: 'get',
      onSuccess: function(transport) {  
       $('kalendar-dogadjanja').update(transport.responseText)
       $('kalendar-dogadjanja').appear({from:0.5, to:1})
       setupCalendar();
      }
    });
  })
}


  var last_day = $$('.events > div').find(function(el){
    return el.visible()
  });

  var ani = false;
  $$('table.calendar td a').each(function(el){
    el.observe('click', function(e){
        var event_target = window.event ? window.event.srcElement : e.target;
        if(event_target.nodeName.toLowerCase() != 'a') {
            event_target = $(event_target).up('a');
        }
        if(event_target.parentNode.className.indexOf('calendar-date') != -1) return;
      
      e.stop();

      new_day = $('d'+this.innerHTML);

	if (!new_day)
		if ($$("table.calendar td a strong.calendar-day-highlight") && $$("table.calendar td a strong.calendar-day-highlight")[0])
			new_day = $('d'+ $$('table.calendar td a strong.calendar-day-highlight')[0].innerHTML);

	if (!last_day)
		last_day = $('d0');

		
      if(new_day==last_day) return false;   

       start_ani = function(){ani=true;}
       stop_ani = function(){ani=false;}
   
      $$('.cal_focus').invoke('removeClassName', 'cal_focus')
      this.addClassName('cal_focus')
      
      if(last_day && new_day && !ani){
      start_ani();
        new Effect.Parallel([
          new Effect.BlindUp(last_day, { sync: true}), 
          new Effect.BlindDown(new_day, { sync: true}) 
        ], {
          afterFinish: stop_ani,
          beforeStart: start_ani,
          duration: 0.5
        });
        last_day = new_day
      }

      
    })
})

}


PAIRS = {
	'mouseover' : 'mouseout',
	'focus' : 'blur'
}



Element.addMethods({
	mark_on:function(el, o){
		 var e = $(el);		 
		 o = o || {};
		 o.event = o.event || 'mouseover';
		 o.classname = o.classname || 'mo_hover'
		 o.before = o.before || function(){};
		 o.after = o.after || function(){};
		 
		 e.observe(o.event, function(){
        	  o.before();
            this.addClassName(o.classname)
         });
		 
		 e.observe(PAIRS[o.event], function(){
            this.removeClassName(o.classname)
            o.e = this
            o.after();
         });
		 
		 return e;		
	},
    
    act_as_link: function(el, o){    
        var bL = $(el);
        o = o || {};
        o.hover = o.hover || 'bL_hover';
        var links = bL.select('a');
        var link = links.reject(function(e){
            return e.hasClassName(o.skip);
        })[0];
        
        
        // This is the reason we love prototype :-)
        bL.addClassName(o.normal || '').writeAttribute('title', link.title || null).select(o.hide).invoke('hide');
        
       
        _click = function(){
            window.location.href = link.href;
        };
        bL.act_as_hoverable({hover: o.hover})
		
        bL.observe('click', _click);
       
        links.each(function(x){
            x.act_as_hoverable();
            
        });
        return bL;
    },
    
    
    
     clear_on_focus: function(el, text){
        var e = $(el);
        if (e.defaultValue == null || e.defaultValue == '')             
            return false;
        e.observe('focus', function(){
            if(this.value == this.defaultValue) 
			 text ? this.value = text :  this.value = ''			
        })
        e.observe('blur', function(){
            if ((this.value == '') || (this.value == text) ) this.value = this.defaultValue;
        })
        return e;
    }

});



Event.observe(window,'load', function(){
	if (typeof today_day != 'undefined') calendarRefresh(today_day);

 if (window.attachEvent) {
    $$('span.btn').invoke('mark_on');
  }
   $$('#search input.txt').invoke('clear_on_focus');
   try{
     $$('#newsletter-footer input.txt:first-child')[0].clear_on_focus('@');
   }catch(e){}

   $$('.news_em .med-view').invoke('mark_on',{     
        classname:'nem_hover',
        before:function(){
          $$('.news_em .nem_hover').invoke('removeClassName',this.classname)
        },
        
        after: function(){
          if($$('.news_em .nem_hover').length == 0){
            this.e.addClassName(this.classname)  
          }
        }
   });
   
tabs = new Tabbr('the_tabs');
if($('the_tabs2')){

   tabs3 = new Tabbr('the_tabs2', {classes: 'r'});
   $$('#the_tabs2 .prev')[0].observe('click',function(e){
    Event.stop(e);
    tabs3.prev();
   })
   $$('#the_tabs2 .next')[0].observe('click',function(e){
    Event.stop(e);
    tabs3.next();
   })
 }

/* 
 v = $('vod')
 if(v){
     $$('#vod .sh')[0].observe('click', function(e){
       Event.stop(e);
      vodin = v.select('.vodic-in').first()
      if(!vodin.defaultHeight) vodin["defaultHeight"] = (vodin.getHeight() - 20) + 'px';

      vodin.collapsed = !vodin.collapsed;
      if(vodin.collapsed){
        v.toggleClassName('collapsed');
        vodin.morph({
          height: '8px'
        })
      }
      else{
        v.toggleClassName('collapsed');
        vodin.morph({
          height: vodin.defaultHeight 
        })
        
      }
     })
}
*/

 /*v = $('vod')
 if(v){
      vodin = v.select('.vodic-in').first()
      if(!vodin.defaultHeight) vodin["defaultHeight"] = (vodin.getHeight() - 20) + 'px';
    
     $$('#vod .sh')[0].observe('click', function(e){
       Event.stop(e);
      //vodin = v.select('.vodic-in').first()
      //if(!vodin.defaultHeight) vodin["defaultHeight"] = (vodin.getHeight() - 20) + 'px';

      vodin.collapsed = v.hasClassName('collapsed') //!vodin.collapsed;

      if(vodin.collapsed){
        v.toggleClassName('collapsed');
        vodin.morph({
          height: vodin.defaultHeight
        })
      }
      else{
        v.toggleClassName('collapsed');
        vodin.morph({
          height: '8px'
        })
        
      }
     })
     
    //var vodic_cont = $('vod').select('.vodic-in')[0];
      vodin.style.height = '8px';
      v.toggleClassName('collapsed');
     
}*/

mini_path = $$('.mini_path a')

$$('.mini_path').each(function(mp){
  mp.observe('mouseout', function(){
    this.select('a').invoke('removeClassName','active')
  })
})

mini_path.each(function(mpl){
  mpl.observe('mouseover', function(){    
    current = this.up(1);
    current_links = current.select('a').invoke('removeClassName','active')
    current_index = current_links.indexOf(this);

    for(var i=0; i<=current_index; i++){
      current_links[i].addClassName('active')
    }
        
  })
})


vcards = $$('.adresa_details .vcard')
vcard_last = vcards.first();
Try.these(
  function(){
    $('adresar_sektor_btn').observe('click',function(e){ 
      Event.stop(e);  
      if(vcard_last == (vcard_new = $($F('adresar_sektor')))) return;
      duration = 0.4;  
      if(vcard_last) vcard_last.blindUp({duration: duration});
      vcard_last = vcard_new.blindDown({duration: duration});
     })
     
     $('adresar_sektor').observe('change', function(e){
      Event.stop(e);  
      if(vcard_last == (vcard_new = $($F('adresar_sektor')))) return;
      duration = 0.4;  
      if(vcard_last) vcard_last.blindUp({duration: duration});
      vcard_last = vcard_new.blindDown({duration: duration});
     })
     
      if(vcard_last == (vcard_new = $($F('adresar_sektor')))) return;
      duration = 0.4;  
      if(vcard_last) vcard_last.blindUp({duration: duration});
      vcard_last = vcard_new.blindDown({duration: duration});
     
  }
)


function GoogleMaps() {
    if (GBrowserIsCompatible()) {
        
      map_cont = $("the_map")
      if(!map_cont) return;  
      var map = new GMap2(map_cont);
      

      map.setCenter(new GLatLng(44.221584, 17.589111), 7);

      mapcode = new GGeoXml('http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&output=nl&msid=117007154087032883415.0004645dbc834f8818363');

       GEvent.addListener(map,"addoverlay",function(overlay) {
        if (overlay.name && !overlay.Known) {          
          //if(console) console.log(overlay.id + ' :: '+overlay.name)
          link = overlay.id.replace('geoxml_', 'geolink_');
            $(link).observe('click', function(e){
               Event.stop(e)
               GEvent.trigger(overlay, "click");
            }).update(overlay.name).up().appear({queue:'end'});
            overlay.Known = true;
        }
      }); 

      map.addOverlay(mapcode);
    }
  }

try{
GoogleMaps();
}catch(e){}

if(flink=$$('#footer2 ul.horizontal li')[0]) flink.addClassName('first')

$$('table tr:nth-child(even)').invoke('addClassName','even')
$$('table tr > td:first-child', 'table tr > th:first-child').invoke('addClassName','first-child')



setupCalendar();

if(typeof form_validation == 'object') {
    form_validation.setup();
}



$$('.rich_image-extend').invoke('mark_on',{classname: 'rich_image-hover'})


var related = $('related-articles')

$$('a.related-articles').each(function(el){
  el.observe('click', function(e){
    new Effect.ScrollTo(related,{
      afterFinish: function(){
        related.down('.box-title').highlight({
          startcolor:'#c09cc7'
        });
      }
    });
    Event.stop(e);    
  })
})

})

  





var section_handler  = {
    container:  null,
    last: null,
    items: [],
    duration: 0.5,
    
    handle: function(container_id) {

        this.container = $(container_id);
        if(!this.container) return;
        
        this.container.addClassName('loaded');
        
        this.items = $(this.container).select('.section');
        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_section = this.items[i];
            var related_heading = $(current_section).select('h2')[0];
            var related_heading_text = related_heading.firstChild;
            var heading_a = document.createElement('a');
                heading_a.setAttribute('href', '#');
                heading_a.appendChild(related_heading_text);
                related_heading.appendChild(heading_a);
                Event.observe(heading_a, 'click', this.clickListener.bindAsEventListener(this), false);


            if(!$(current_section).hasClassName('expanded')) {
                var related_content = $(current_section).select('.section-content')[0];
		var related_section_items = $(current_section).select('.section-items')[0];
		
		if(related_section_items) {
		  related_section_items.style.display = 'none';
		} else {
		  related_content.style.display = 'none';
		}

                
            }
            
        }
    },
    
   clickListener: function(e) {
        if(window.event) {
            window.event.returnValue = false;
        } else {
            e.preventDefault();
        }

        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        
        this.toggle(eventTarget);
   },
   
   toggle: function(eventTarget) {
        var related_parent_section = $(eventTarget).up('div');
        var related_content = $(related_parent_section).select('.section-content')[0];
	
	if(related_content.parentNode.hasClassName('section-items')) {
	  related_content = related_content.parentNode;
	}
        
        if(related_parent_section.hasClassName('expanded')) {
            related_parent_section.removeClassName('expanded');
            new Effect.toggle(related_content,'blind',{duration: this.duration});
        } else {
            related_parent_section.addClassName('expanded');
            new Effect.toggle(related_content,'blind',{duration: this.duration});
        }
   }
}



var configurator_handler  = {

	container:  null,
    
    handle: function(container_id) {
        this.container = $(container_id);
        if(!this.container) return;
		
        var items = $(this.container).select('label input');
        var il = items.length;
        for(var i = 0; i < il; i++) {
            var current_item = items[i];
			Event.observe(current_item, 'click', this.clickListener.bindAsEventListener(this), false);
			//standard vs non standard
        }
    },
    
   clickListener: function(e) {


        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        
        this.recalculate(eventTarget);
   },
   
   recalculate: function(eventTarget) {
	    //current modem price
        var related_label = $(eventTarget).up('label');
		var related_value= $(related_label).select('strong')[0].cloneNode(true);
		$(related_value).select('span')[0].remove();
		var modem_value = parseInt(related_value.firstChild.nodeValue);
		
    	//package price
		var package_price = $('package-price').select('strong')[0].cloneNode(true);
		$(package_price).select('span')[0].remove();
		var package_value = parseInt(package_price.firstChild.nodeValue);


		//total pricing
		var current_total_price = $('total-pricing').select('strong')[0];
			current_total_price.remove();
		
		var new_total_price_span = document.createElement('span');
		new_total_price_span.appendChild(document.createTextNode('km'));
		
		var new_total_price_strong = document.createElement('strong');
			new_total_price_strong.appendChild(document.createTextNode(package_value + modem_value + ' '));
			new_total_price_strong.appendChild(new_total_price_span);			
		
		$('total-pricing').select('p')[0].appendChild(new_total_price_strong);

		//modem pricing
		var current_modem_price = $('modem-price').select('strong')[0];
			current_modem_price.remove();
			
//			<p id="modem-price">Cijena modema <strong>1 <span>KM</span></strong></p>
		
		var new_modem_price_span = document.createElement('span');
		    new_modem_price_span.appendChild(document.createTextNode('km'));
		
		var new_modem_price_strong = document.createElement('strong');
			new_modem_price_strong.appendChild(document.createTextNode( modem_value + ' '));
			new_modem_price_strong.appendChild(new_modem_price_span);			
		
		$('modem-price').appendChild(new_modem_price_strong);


   } 
}


/*
var phonebook = {
        container:  null,
        duration: 0.9,
        
        handle: function(container_id) {
            this.container = $(container_id);
            if(!this.container) return;
           
            this.phonebook_a = $('top').select('.first a')[0];
            
            if($('top').select('a')[3]) {
                $('top').select('a')[3].removeAttribute('target');
            }
            Event.observe(this.phonebook_a, 'click', this.clickListener.bindAsEventListener(this), false);

            var close_a = $(this.container).select('a')[0];
            Event.observe(close_a, 'click', this.clickListener.bindAsEventListener(this), false);
            
            
            this.container.style.display = 'none';
            $(this.container).addClassName('collapsed');
        },
    
       clickListener: function(e) {
            if(window.event) {
                window.event.returnValue = false;
            } else {
                e.preventDefault();
            }
    
            var event = window.event ? window.event : e;
            var eventTarget = event.srcElement ? event.srcElement :  event.target;
            this.toggle(eventTarget);

            if(!$(webmail_handler.container).hasClassName('collapsed')) {
                $(webmail_handler).toggle();
            }
       },
       
       toggle: function(eventTarget) {
            $(this.phonebook_a).up('li').toggleClassName('selected');
            new Effect.toggle(this.container,'blind',{duration: this.duration});
            
            if($(this.container).hasClassName('collapsed')) {
                $(this.container).removeClassName('collapsed');
                if(window.opera) {
                    var o = this;
                    setTimeout(function(){o.container.style.overflow = 'hidden'}, 1000);                    
                }
            } else {
                $(this.container).addClassName('collapsed');
            }
       }
}
*/


/*var webmail_handler = {
        container:  null,
        duration: 0.9,
        
        handle: function(container_id) {
            this.container = $(container_id);
            if(!this.container) return;
           
            this.webmail_a = $('top').select('a')[1];
            Event.observe(this.webmail_a, 'click', this.clickListener.bindAsEventListener(this), false);

            var close_a = $(this.container).select('a')[0];
            Event.observe(close_a, 'click', this.clickListener.bindAsEventListener(this), false);
            
            this.container.style.display = 'none';
            $(this.container).addClassName('collapsed');
            
        },
    
       clickListener: function(e) {
            if(window.event) {
                window.event.returnValue = false;
            } else {
                e.preventDefault();
            }
    
            var event = window.event ? window.event : e;
            var eventTarget = event.srcElement ? event.srcElement :  event.target;
            this.toggle(eventTarget);

            if(!$(phonebook.container).hasClassName('collapsed')) {
                $(phonebook).toggle();
            }
            
       },
       
       toggle: function(eventTarget) {
            $(this.webmail_a).up('li').toggleClassName('selected');

            new Effect.toggle(this.container,'blind',{duration: this.duration});
            
            if($(this.container).hasClassName('collapsed')) {
                $(this.container).removeClassName('collapsed');
                if(window.opera) {
                    var o = this;
                    setTimeout(function(){o.container.style.overflow = 'hidden'}, 1000);                    
                }
            } else {
                $(this.container).addClassName('collapsed');
            }
       }
}
*/


var carousel = Class.create();
carousel.prototype=  {
    container: null,
    list: null,
    original_list_width: null,
    multiplied_list_width: null,
    items: [],
    prev_link: null,
    next_link: null,
    animating: null,
    current_slide: 0,
    slides_no: 0,
    last_photo_item: null,
    items_visible: 3,
    item_width: 200,
    si: null,
    update_interval: 50,
    carousel_width: 680,
    target_offset: 0,
    current_offset: 0,
    move_by_items_no: 1,
    speed: 20,
    move_offset: 100,
    easing: false,
    max_height: null,

    initialize: function(container_id) {
        
        this.container = $(container_id);
        if(!this.container) return;
        this.container_id = container_id;
        
        //if(this.container_id == 'section-2') {
            this.item_width = 228;
            this.carousel_width = 915;
            this.items_visible = 4;
        //} else {
          //  return;
        //}

	this.list = $(this.container).select('.section-content')[0];
	this.items = $(this.list).select('.section-grid');
	if(this.items.length <= this.items_visible) return;

        this.container.addClassName('loaded');
        
        
        var wrap_element = $(this.list).wrap()
            wrap_element.setAttribute('id', container_id + '-items');
            wrap_element.className += ' section-items';
        
        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_item_height = this.items[i].getHeight();
            if(current_item_height > this.max_height) {
                this.max_height = current_item_height;
            }
        }
        if(document.all) { this.max_height += 20; }
        
        wrap_element.style.height = this.max_height - 5 + 'px';

        for(var i = 0; i < il; i++) {
            this.items[i].style.height = this.max_height + 'px';
            this.items[i].style.minHeight = this.max_height + 'px';
        }        
        
        this.items[0].addClassName('first-child');
        this.slides_no = Math.ceil(this.items.length/this.items_visible);

        this.original_list_width = this.items.length * this.item_width;
        this.multiplied_list_width = this.slides_no * this.carousel_width;
        this.list.style.width = this.multiplied_list_width  +'px';

        this.createControls();
   },

   
   createControls: function() {
        if($(this.container).select('.controls')[0]) return;
        
        var ul = document.createElement('ul');
            ul.className = 'controls';

        var prev_li = document.createElement('li');
            prev_li.className = 'prev';

        var prev_a = document.createElement('a');
            prev_a.className = 'prev';            
            prev_a.setAttribute('href', '#');
            prev_a.style.padding = Math.ceil((this.max_height-65)/2)+'px ' + '0px '+Math.floor((this.max_height-65)/2)+'px';

            
        var prev_img = document.createElement('img');
            prev_img.setAttribute('alt', 'Natrag');
            prev_img.setAttribute('title', 'Natrag');
            
            //if(this.container_id == 'section-2') {
                prev_img.setAttribute('src', image_folder + '/arrows/service-arrow-prev-inactive.gif');
            //} 
                        
            prev_a.appendChild(prev_img);
            prev_li.appendChild(prev_a);
            ul.appendChild(prev_li);
            
        var next_li = document.createElement('li');
            next_li.className = 'next';

        var next_a = document.createElement('a');
            next_a.className = 'next';            
            next_a.setAttribute('href', '#');
            next_a.style.padding = Math.ceil((this.max_height-65)/2)+'px ' + '0px '+Math.floor((this.max_height-65)/2)+'px';
            
        var next_img = document.createElement('img');
            next_img.setAttribute('alt', 'Naprijed');
            next_img.setAttribute('title', 'Naprijed');

            //if(this.container_id == 'section-2') {
                next_img.setAttribute('src', image_folder + '/arrows/service-arrow-next.gif');
            //}            
                                    
            next_a.appendChild(next_img);
            next_li.appendChild(next_a);
            ul.appendChild(next_li);            
            
            this.container.appendChild(ul);
	    
	this.prev_link = prev_a;
	this.next_link = next_a;

        Event.observe(prev_a, 'click', this.clickListener.bindAsEventListener(this), false);
        Event.observe(next_a, 'click', this.clickListener.bindAsEventListener(this), false);
            
   },

   clickListener: function(e) {
        if(window.event) {
            window.event.returnValue = false;
        } else {
            e.preventDefault();
        }

        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        if(eventTarget.nodeName.toLowerCase() == 'img') {
            eventTarget = eventTarget.parentNode;
        }

        var direction = eventTarget.parentNode.className;
        if(!this.animating) {
            this.prepareScrolling(direction);
        }
   },
   

   prepareScrolling: function(direction) {

        if(direction == 'prev') {

                var requested_offset = this.current_offset - this.carousel_width;
               
                if(requested_offset < 0) {
                    requested_offset = 0;
                }
                this.target_offset = requested_offset;
                this.initMoving();
		
		
		//prev img
		if(requested_offset == 0) {
		    var prev_img = $(this.prev_link).select('img')[0];
		    var current_src = prev_img.getAttribute('src');
		    
		    if(current_src.indexOf('inactive') == -1) {
		      var new_src = current_src.replace('.gif', '-inactive.gif');
		      prev_img.setAttribute('src', new_src);
		    }
		}
		
		//next img
		var next_img = $(this.next_link).select('img')[0];
		var current_src = next_img.getAttribute('src');
		if(current_src.indexOf('inactive') != -1) {
		  var new_src = current_src.replace('-inactive.gif', '.gif');
		  next_img.setAttribute('src', new_src);
		}
		
		
		
        } else {

                var requested_offset = this.current_offset + this.carousel_width;
                var diff_items = (this.original_list_width-requested_offset)/this.item_width;
                //alert(requested_offset +':'+this.original_list_width)
	        var is_end = false;
                if(diff_items<4) {
                    requested_offset = this.original_list_width-this.carousel_width+3;
                }
		
		if(diff_items<=4) {
		    is_end = true;	      
		}

		//next img
		if(is_end) {
		    var next_img = $(this.next_link).select('img')[0];
		    var current_src = next_img.getAttribute('src');
		    
		    if(current_src.indexOf('inactive') == -1) {
		      var new_src = current_src.replace('.gif', '-inactive.gif');
		      next_img.setAttribute('src', new_src);
		    }
		}
		
		//prev img
		var prev_img = $(this.prev_link).select('img')[0];
		var current_src = prev_img.getAttribute('src');
		
		if(current_src.indexOf('inactive') != -1) {
		  var new_src = current_src.replace('-inactive.gif', '.gif');
		  prev_img.setAttribute('src', new_src);
		}
		    
                this.target_offset = requested_offset;
                this.initMoving();

        }
   },

   initMoving: function() {
         this.animating = true;
         var o = this;
         this.si = setInterval( function() {o.moveCalculation();}, this.update_interval);
   },
   
   getIndex: function(related_item) {
    
        var position = null;
        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_item = this.items[i];
            if(current_item == related_item) {
                position = i;
                break;
            }
        }
        return position+1;
   },

   moveCalculation: function () {
        var diff = this.target_offset - this.current_offset;

        if(diff > 0) {
            if(!this.easing) {
                var step = this.move_offset;
                if(diff < this.move_offset) {
                    step = diff;
                }
            } else {
                var step = Math.ceil(diff/this.speed);
            }
        } else {
            if(!this.easing) {
                var step = -this.move_offset;
                if(diff > step) {
                    step = diff;
                }
            } else {
                var step = Math.floor(diff/this.speed);
            }
        }

        if(step == 0) {
            clearInterval(this.si);
            this.animating = false;
            this.move_by_items_no = 1; 
        }

        this.current_offset += step;
        this.moveItems(step);
   },

   moveItems: function(current_step) {
    
        var item_to_move = this.list;
            if( item_to_move.style.left ) {
                var new_offset = parseInt(item_to_move.style.left) - current_step + 'px';
            } else {
                var new_offset = - current_step + 'px';
            }
            item_to_move.style.left = new_offset;
            item_to_move.style.position = 'relative';

   }

}


function init_services_scroller()  {
    var container = 'section-container';
    if(!container) return;
    
    var all_sections = $(container).select('.section');
    
    var il = all_sections.length;
    for(var i = 0; i < il; i++) {
        var current_section = all_sections[i];
        current_section.setAttribute('id', 'section-' + i);
        
        var has_section_details = $(current_section).select('.has-details').length;
        
        if(has_section_details && typeof carousel == "function") {
            var new_downloads_carousel = new carousel('section-'+i);
        }
        
    }
    
    
}



var gallery_scroller = Class.create();
gallery_scroller.prototype=  {
    container: null,
    list: null,
    original_list_width: null,
    multiplied_list_width: null,
    items: [],
    prev_link: null,
    next_link: null,
    animating: null,
    current_slide: 0,
    slides_no: 0,
    last_photo_item: null,
    items_visible: 4,
    item_width: 135,
    si: null,
    update_interval: 50,
    carousel_width: 680,
    target_offset: 0,
    current_offset: 0,
    move_by_items_no: 1,
    speed: 20,
    move_offset: 20,
    easing: false,

    initialize: function(container_id) {

        this.container = $(container_id);
        if(!this.container) return;
        this.container_id = container_id;
        
        if(this.container_id == 'gallery-browser') {
            this.item_width = 135;
            this.carousel_width = 530;
            this.items_visible = 4;
        } else if(this.container_id == 'test') {
            //this.item_width = 103;
            //this.carousel_width = 599;
            //this.items_visible = 6;
        } else {
            return;
        }
        
        this.container.addClassName('loaded');
        this.list = $(this.container).select('ul')[0];
        
        var wrap_element = $(this.list).wrap()
            wrap_element.setAttribute('id', container_id + '-items');
        
        this.items = $(this.list).select('li');
        this.items[0].addClassName('first-child');
        this.slides_no = Math.ceil(this.items.length/this.items_visible);

        this.original_list_width = this.items.length * this.item_width;
        this.multiplied_list_width = this.slides_no * (this.carousel_width+10);
        this.list.style.width = this.multiplied_list_width  +'px';

        //if(this.items.length <= this.items_visible) return;

        this.createControls();
   },

   
   createControls: function() {

        if($(this.container).select('.controls')[0]) return;
        
        var ul = document.createElement('ul');
            ul.className = 'controls';

        var prev_li = document.createElement('li');
            prev_li.className = 'prev';

        var prev_a = document.createElement('a');
            prev_a.className = 'prev';            
            prev_a.setAttribute('href', '#');
            
        var prev_img = document.createElement('img');
            prev_img.setAttribute('alt', 'Natrag');
            prev_img.setAttribute('title', 'Natrag');
            
            if(this.container_id == 'gallery-browser') {
                prev_img.setAttribute('src', image_folder + '/arrows/gallery-arrow-prev-inactive.gif');
            } else if(this.container_id == 'other-videos') {
                //prev_img.setAttribute('src', image_folder + '/interface/buttons/prev-orange-light.gif');
            }
                        
            prev_a.appendChild(prev_img);
            prev_li.appendChild(prev_a);
            ul.appendChild(prev_li);
            
        var next_li = document.createElement('li');
            next_li.className = 'next';

        var next_a = document.createElement('a');
            next_a.className = 'next';            
            next_a.setAttribute('href', '#');
            
        var next_img = document.createElement('img');
            next_img.setAttribute('alt', 'Naprijed');
            next_img.setAttribute('title', 'Naprijed');

            if(this.container_id == 'gallery-browser') {
                if(this.items.length <= this.items_visible) {
                    next_img.setAttribute('src', image_folder + '/arrows/gallery-arrow-next-inactive.gif');
                } else {
                    next_img.setAttribute('src', image_folder + '/arrows/gallery-arrow-next.gif');
                }
            } else if(this.container_id == 'test') {
                //next_img.setAttribute('src', image_folder + '/interface/arrows/gallery-next.gif');
            }
                                    
            next_a.appendChild(next_img);
            next_li.appendChild(next_a);
            ul.appendChild(next_li);            
            
            this.container.appendChild(ul);
            
            this.prev_link = prev_a;
            this.next_link = next_a;

        Event.observe(prev_a, 'click', this.clickListener.bindAsEventListener(this), false);
        Event.observe(next_a, 'click', this.clickListener.bindAsEventListener(this), false);
            
   },

   clickListener: function(e) {
        if(window.event) {
            window.event.returnValue = false;
        } else {
            e.preventDefault();
        }

        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        if(eventTarget.nodeName.toLowerCase() == 'img') {
            eventTarget = eventTarget.parentNode;
        }

        var direction = eventTarget.parentNode.className;
        if(!this.animating) {
            this.prepareScrolling(direction);
        }
   },
   

   prepareScrolling: function(direction) {

        if(direction == 'prev') {
                var requested_offset = this.current_offset - this.carousel_width - 10;
               
                if(requested_offset < 0) {
                    requested_offset = 0;
                }
                this.target_offset = requested_offset;
                this.initMoving();
                
        		//prev img
        		if(requested_offset == 0) {
        		    var prev_img = $(this.prev_link).select('img')[0];
        		    var current_src = prev_img.getAttribute('src');
        		    
        		    if(current_src.indexOf('inactive') == -1) {
        		      var new_src = current_src.replace('.gif', '-inactive.gif');
        		      prev_img.setAttribute('src', new_src);
        		    }
        		}
        		
        		//next img
        		var next_img = $(this.next_link).select('img')[0];
        		var current_src = next_img.getAttribute('src');

        		if(current_src.indexOf('inactive') != -1 && this.items.length > this.items_visible) {
        		  var new_src = current_src.replace('-inactive.gif', '.gif');
        		  next_img.setAttribute('src', new_src);
        		}                
                
        } else {
                var requested_offset = this.current_offset + this.carousel_width + 10;
                var diff_items = (this.original_list_width-requested_offset)/this.item_width;
                
                var is_end = false;
                
                if(diff_items<4) {
                    requested_offset = this.original_list_width-this.carousel_width - 10;
                }
                
        		if(diff_items<=4) {
        		    is_end = true;	      
        		}
                        
        		//next img
        		if(is_end) {
        		    var next_img = $(this.next_link).select('img')[0];
        		    var current_src = next_img.getAttribute('src');
        		    
        		    if(current_src.indexOf('inactive') == -1) {
        		      var new_src = current_src.replace('.gif', '-inactive.gif');
        		      next_img.setAttribute('src', new_src);
        		    }
        		}
        		
        		//prev img
        		var prev_img = $(this.prev_link).select('img')[0];
        		var current_src = prev_img.getAttribute('src');
        		
        		if(current_src.indexOf('inactive') != -1 && this.items.length > this.items_visible) {
        		  var new_src = current_src.replace('-inactive.gif', '.gif');
        		  prev_img.setAttribute('src', new_src);
        		}
                
		    
                this.target_offset = requested_offset;
                this.initMoving();
        }
   },

   initMoving: function() {
         this.animating = true;
         var o = this;
         this.si = setInterval( function() {o.moveCalculation();}, this.update_interval);
   },
   
   getIndex: function(related_item) {
    
        var position = null;
        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_item = this.items[i];
            if(current_item == related_item) {
                position = i;
                break;
            }
        }
        return position+1;
   },

   moveCalculation: function () {
        var diff = this.target_offset - this.current_offset;

        if(diff > 0) {
            if(!this.easing) {
                var step = this.move_offset;
                if(diff < this.move_offset) {
                    step = diff;
                }
            } else {
                var step = Math.ceil(diff/this.speed);
            }
        } else {
            if(!this.easing) {
                var step = -this.move_offset;
                if(diff > step) {
                    step = diff;
                }
            } else {
                var step = Math.floor(diff/this.speed);
            }
        }

        if(step == 0) {
            clearInterval(this.si);
            this.animating = false;
            this.move_by_items_no = 1; 
        }

        this.current_offset += step;
        this.moveItems(step);
   },

   moveItems: function(current_step) {

        var il = this.items.length;
        for( var i = 0 ; i < il; i++ ) {
            var item_to_move = this.items[i];
            if( item_to_move.style.left ) {
                var new_offset = parseInt(item_to_move.style.left) - current_step + 'px';
            } else {
                var new_offset = - current_step + 'px';
            }
            item_to_move.style.left = new_offset;
            item_to_move.style.position = 'relative';
        }
   }

}



var photo_gallery = {
    container: null,
    last: null,
    items: [],
    photo_container_id: null,
    prev_height: 0,
    last_tooltip: null,

    handle: function(container_id, photo_container_id) {

        this.container = $(container_id);
        if(!this.container) return;

        this.photo_container_id = photo_container_id;
        this.items = $(this.container).select('li a');

        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_item = this.items[i];
            Event.observe(current_item, 'click',this.clickListener.bind(this));
            Event.observe(current_item, 'mouseover',this.mouseoverListener.bind(this));
            Event.observe(current_item, 'mouseout',this.mouseoutListener.bind(this));
        }
        this.last = $(this.container).select('li')[0];
        
        if(typeof image_id != 'undefined') {
            var related_a = $('photo-id-' + image_id).select('a')[0];
            this.toggle(related_a);
        }
    },

    clickListener: function(e){
        if(window.event){
            window.event.returnValue = false;
        } else{
            e.preventDefault();
        }
        var event_target = window.event ? window.event.srcElement : e.target;
        if(event_target.nodeName.toLowerCase()!='a') {
            event_target = $(event_target).up('a');
        }
        if(event_target) {
            this.toggle(event_target);
        }
    },   
    
    toggle: function(event_target) {
        
        var large_img_src = $(event_target).getAttribute('rel');
        var parent_li = $(event_target).up('li');
        //var photo_id = parent_li.getAttribute('id').replace('photo-id-', '');
        
        if(this.last == parent_li) return;

        $(parent_li).addClassName('active');
        if(this.last != null) {
            $(this.last).removeClassName('active');
        }
        
       
        var large_img = $(this.photo_container_id).select('img')[0]
        large_img.onload = function() {
            large_img.setAttribute('width', 'auto');
            large_img.setAttribute('height', 'auto');
        }

        
        large_img.setAttribute('src', large_img_src);

        
        var photo_description = $(this.photo_container_id).select('.description')[0];
        if(gallery_data[parent_li.getAttribute('id')].photo_desc) {
            if(!photo_description) {
                var desc_p = document.createElement('p');
                    desc_p.className += 'description';

                var desc_text = document.createTextNode('temp');
                    desc_p.appendChild(desc_text);
                    
                    $(this.photo_container_id).appendChild(desc_p);
                    var photo_description = desc_p;
            }
            photo_description.firstChild.nodeValue = gallery_data[parent_li.getAttribute('id')].photo_desc;
            large_img.setAttribute('alt', gallery_data[parent_li.getAttribute('id')].photo_desc);
            large_img.setAttribute('title', gallery_data[parent_li.getAttribute('id')].photo_desc);

        } else {
            if(photo_description) {
                $(photo_description).remove();
            }
            large_img.setAttribute('title', '');
            large_img.setAttribute('alt', '');
        }
        
                

        var photo_download = $(this.photo_container_id).select('.download')[0];
        if(gallery_data[parent_li.getAttribute('id')].download) {
            if(!photo_download) {
                var download_p = document.createElement('p');
                    download_p.className += 'download';
                var download_a = document.createElement('a');
                    download_a.setAttribute('href', '#');
                var download_text = document.createTextNode('Spremi sliku kvalitete za tisak');
                
                    download_a.appendChild(download_text);
                    download_p.appendChild(download_a);
                    
                    $(large_img).insert({after:download_p})
                    
                    var photo_download = download_p;
            }
            $(photo_download).select('a')[0].setAttribute('href', gallery_data[parent_li.getAttribute('id')].download);
            $(photo_download).select('a')[0].firstChild.nodeValue = 'Spremi sliku (kvaliteta za tisak) ' + gallery_data[parent_li.getAttribute('id')].size;

        } else {
            if(photo_download) {
                $(photo_download).remove();
            }
        }
        
        this.last = parent_li;
    },
    
    afterUpdate: function(current_h1, current_date) {
        //this.setPhotoHeight();
        //document.location = '#article-photo';
    },
    
    mouseoverListener: function(e){
        if(window.event){
            window.event.returnValue = false;
        } else{
            e.preventDefault();
        }
        var event_target = window.event ? window.event.srcElement : e.target;
        if(event_target.nodeName.toLowerCase()=='img') {
            event_target = event_target.parentNode;
        }
        
        var parent_li = $(event_target).up('li');
        
        var tooltip_container = $(parent_li).select('.tooltip_container')[0];
        if(!tooltip_container) {

            if(this.last_tooltip) {
                $(this.last_tooltip).remove();
            }

            if(gallery_data[parent_li.getAttribute('id')].photo_desc) {
                var tooltip_text = gallery_data[parent_li.getAttribute('id')].photo_desc;
                var tooltip_container = document.createElement('div');
                    tooltip_container.className += 'tooltip_container';
                    tooltip_container.appendChild(document.createTextNode(tooltip_text));
                    $(parent_li).select('a')[0].appendChild(tooltip_container);
                this.last_tooltip = tooltip_container;
            } else {
                this.last_tooltip = null;
            }
                
        }
        
            
            
        
    },

    mouseoutListener: function(e){
       
    }
    
}


var availability = {
    container: null,
    submit_button: null,
    availability_form: null,
    success_container: null,
    error_container: null,
    form_container: null,
    not_nr_container: null,
    nr_length_container: null,
    
    handle: function() {
        this.container = $('check-availability');
        if(!this.container) return;
        
        this.submit_button = $(this.container).select('input.btn')[0];
        this.availability_form = $(this.container).select('form')[0];
        this.form_container = $('availability-form-container');
        Event.observe(this.submit_button, 'click', this.clickListener.bind(this));
        
    },
    
    clickListener: function(e) {
        if(window.event){
            window.event.returnValue = false;
        } else{
            e.preventDefault();
        }
        
        this.sendRequest();
    },
    
    sendRequest: function() {
		if (typeof availability_url != 'undefined')
		{
			var request_url = availability_url;
			new Ajax.Request(request_url, {onSuccess: this.handle_response.bind(this), parameters: Form.serialize(this.availability_form)} );
		}
    },
    
    handle_response: function(r) {
        
        if(r.responseText) {
            //var xml_doc = r.responseXML;
            //var is_success = xml_doc.getElementsByTagName('success')[0].firstChild.nodeValue;
            
            var related_input = $('phone-part-2');
            
            
            if(r.responseText.indexOf('>1<') != -1) {
                
                    if(related_input.value.length < 6) {
                        this.renderLengthError();
                    } else {
                        this.renderSuccess();
                    }
                
            } else if (r.responseText.indexOf('>-1<') != -1) {
                this.renderNotNumber();
            } else {
                
                    if(related_input.value.length < 6) {
                        this.renderLengthError();
                    } else {
                        this.renderError();
                    }
                
            }
        }
    } ,
    
    renderLengthError: function() {
        if(!this.nr_length_container) {
            this.nr_length_container = document.createElement('div');
            this.nr_length_container.setAttribute('id', 'availability-no-length-container');
            
            var heading = document.createElement('h2');
                heading.appendChild(document.createTextNode('Neispravan unos'));
    
            var p_msg = document.createElement('p');
                p_msg.appendChild(document.createTextNode('Telefonski broj mora sadrzavati 6 znamenki.'));

            var a_back = document.createElement('a');
                a_back.appendChild(document.createTextNode('Natrag'));        
                a_back.setAttribute('href', '#');
                Event.observe(a_back, 'click', this.backListener.bind(this));     

            this.nr_length_container.appendChild(heading);
            this.nr_length_container.appendChild(p_msg);
            this.nr_length_container.appendChild(a_back);
            
            $(this.container).select('.inner')[0].appendChild(this.nr_length_container);
        } else {
            this.nr_length_container.style.display = 'block';
        }
        
        this.form_container.style.display = 'none';
    },    

    renderNotNumber: function() {
        if(!this.not_nr_container) {
            this.not_nr_container = document.createElement('div');
            this.not_nr_container.setAttribute('id', 'availability-no-nr-container');
            
            var heading = document.createElement('h2');
                heading.appendChild(document.createTextNode('Neispravan unos'));
    
            var p_msg = document.createElement('p');
                p_msg.appendChild(document.createTextNode('Uneseni brojevi ne predstavljaju telefonski broj. Brojevi smiju sadrzavati samo znamenke 0-9, bez razmaka i znaka "-"'));

            var a_back = document.createElement('a');
                a_back.appendChild(document.createTextNode('Natrag'));        
                a_back.setAttribute('href', '#');
                Event.observe(a_back, 'click', this.backListener.bind(this));     

            this.not_nr_container.appendChild(heading);
            this.not_nr_container.appendChild(p_msg);
            this.not_nr_container.appendChild(a_back);
            
            $(this.container).select('.inner')[0].appendChild(this.not_nr_container);
        } else {
            this.not_nr_container.style.display = 'block';
        }
        
        this.form_container.style.display = 'none';
    },
        
    renderSuccess: function() {
        if(!this.success_container) {
            this.success_container = document.createElement('div');
            this.success_container.setAttribute('id', 'availability-success-container');
            
            var heading = document.createElement('h2');
                heading.appendChild(document.createTextNode('ADSL je dostupan'));
    
            var p_msg = document.createElement('p');
                p_msg.appendChild(document.createTextNode('ADSL je dostupan na navedenoj lokaciji.'));            

            var a_back = document.createElement('a');
                a_back.appendChild(document.createTextNode('Natrag'));        
                a_back.setAttribute('href', '#');
                Event.observe(a_back, 'click', this.backListener.bind(this));     

            this.success_container.appendChild(heading);
            this.success_container.appendChild(p_msg);
            this.success_container.appendChild(a_back);
            
            $(this.container).select('.inner')[0].appendChild(this.success_container);
        } else {
            this.success_container.style.display = 'block';
        }
        
        this.form_container.style.display = 'none';

    },
    
    renderError: function() {
        if(!this.error_container) {
            this.error_container = document.createElement('div');
            this.error_container.setAttribute('id', 'availability-error-container');
            
            var heading = document.createElement('h2');
                heading.appendChild(document.createTextNode('ADSL nije dostupan'));
    
            var p_msg = document.createElement('p');
                p_msg.appendChild(document.createTextNode('Nazalost ADSL nije dostupan na navedenoj lokaciji.'));            

            var a_back = document.createElement('a');
                a_back.appendChild(document.createTextNode('Natrag'));
                a_back.setAttribute('href', '#');
                Event.observe(a_back, 'click', this.backListener.bind(this)); 
                
            this.error_container.appendChild(heading);
            this.error_container.appendChild(p_msg);
            this.error_container.appendChild(a_back);
            
            $(this.container).select('.inner')[0].appendChild(this.error_container);
        } else {
            this.error_container.style.display = 'block';
        }
        
        this.form_container.style.display = 'none';
    },
    
    backListener: function(e) {
        if(window.event){
            window.event.returnValue = false;
        } else{
            e.preventDefault();
        }        
        
        if(this.error_container) {
            this.error_container.style.display = 'none';
        }
        if(this.success_container) {
            this.success_container.style.display = 'none';
        }       
        if(this.not_nr_container) {
            this.not_nr_container.style.display = 'none';
        }                
        if(this.nr_length_container) {
            this.nr_length_container.style.display = 'none';
        }                        
        
        this.form_container.style.display = 'block';
    }
    
}



var subnavigation_handler = {
    container: null,
    items: [],
    animating: false,
    
    handle: function() {
        this.container = $('body').select('.left-content .vertical_nav')[0];
        if(!this.container) return;
        this.items = $(this.container).immediateDescendants()
        var il = this.items.length; 
        
        for(var i = 0; i < il; i++) {
            var current_item = this.items[i];
                current_item.className += ' main-item';
            var current_a = $(current_item).select('a')[0];

            var subnav = $(current_item).select('ul')[0];
                
            if(subnav) {
                subnav.className += ' subnav-items';
                Event.observe(current_a, 'mouseover', this.mouseoverListener.bindAsEventListener(this), false);
                if(!current_item.hasClassName('active')) {
                    subnav.style.display = 'none';
                }
            }
        }
    },

   mouseoverListener: function(e) {
        if(window.event) {
            window.event.returnValue = false;
        } else {
            e.preventDefault();
        }
        if(this.animating) return;

        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;

        if(eventTarget.nodeName.toLowerCase() == 'li' && $(eventTarget).hasClassName('main-item')) {
            parent_li = eventTarget;
        } else {
            parent_li = $(eventTarget).up('.main-item');
        }
        
        var last =  $(this.container).select('.expanded')[0];
        if(last && last.up('li') == parent_li) {
            return;
        }
        
        this.animating = true;
        
        var current_subitems = $(parent_li).select('ul')[0];
        if(!$(current_subitems).hasClassName('expanded')) {
            current_subitems.addClassName('expanded');
        }
        
        $(current_subitems).show("slow");
        if(last) {
            $(last).hide("slow");
            last.removeClassName('expanded'); 
        }
        
        var o = this;
        setTimeout(function(){o.animating = false; }, 500);
        this.last_navitem = parent_li;
        
   }  
    
}



var vodic_handler = {
   
    handle: function() {
         v = $('vod')
         if(v){
              vodin = v.select('.vodic-in').first()
              if(!vodin.defaultHeight) vodin["defaultHeight"] = (vodin.getHeight() - 20) + 'px';
            
             $$('#vod .sh')[0].observe('click', function(e){
               Event.stop(e);
        
              vodin.collapsed = v.hasClassName('collapsed');
        
              if(vodin.collapsed){
                v.toggleClassName('collapsed');
                vodin.morph({height: vodin.defaultHeight})
              }
              else{
                v.toggleClassName('collapsed');
                vodin.morph({height: '8px'})
              }
              
             })//end of observe
             

             $$('#vod .vodic-in')[0].observe('click', function(e){

               var event = window.event ? window.event : e;
               var eventTarget = event.srcElement ? event.srcElement :  event.target;

               if(eventTarget.nodeName.toLowerCase() != 'a' && $(eventTarget).className.indexOf('br') == -1) {
                           Event.stop(e);
                    
                          vodin.collapsed = v.hasClassName('collapsed');
                    
                          if(vodin.collapsed){
                            v.toggleClassName('collapsed');
                            vodin.morph({height: vodin.defaultHeight})
                          }
                          else{
                            v.toggleClassName('collapsed');
                            vodin.morph({height: '8px'})
                          }
                                  
               }
               

              
             })//end of observe             
             
              vodin.style.height = '8px';
              v.toggleClassName('collapsed');        
        }
    }
}

var netphone = {
    container: null,
    items: [],
    headings: [],
    last: null,
    
    handle: function()   {
        this.container = $('netphone-overview');
        if(!this.container) return;
        
        $(this.container).addClassName('loaded');
        
        this.items = $(this.container).select('.section');
        this.headings = $(this.container).select('h3');
        
        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_section = this.items[i];
                current_section.style.display = 'none';
                var h3 = $(current_section).select('h3')[0];
                var h3_text = h3.firstChild.nodeValue;
                var heading_a = document.createElement('a');
                    Event.observe(heading_a, 'click', this.clickListener.bindAsEventListener(this), false);
                    heading_a.setAttribute('href', '#');
                    heading_a.appendChild(document.createTextNode(h3_text));
                    h3.firstChild.nodeValue = '';
                    h3.appendChild(heading_a);
                    $(current_section).insert({before:h3})
        }
        
    },
    

    clickListener: function(e) {
        Event.stop(e);
        
        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        
        var heading_index = this.getIndex(eventTarget);
        this.toggle(heading_index);
    },
    
    toggle: function(position) {
        //this.items[position].style.display = 'block'
        new Effect.toggle(this.items[position],'blind',{duration: 0.5});
    },
    
   getIndex: function(eventTarget) {
        var related_item = eventTarget.parentNode;
    
        var position = null;
        var il = this.headings.length;
        for(var i = 0; i < il; i++) {
            var current_item = this.headings[i];
            if(current_item == related_item) {
                position = i;
                break;
            }
        }
        return position;
   }
    

}

var kontakt_form = {
    items: [],
    original: [],
    container: null,
    
    handle: function() {
        this.container = $('upit-tema');
        if(!this.container) return;
        
        this.items = $(this.container).select('option');
        var il = this.items.length;
        
        for(var i = 0; i < il; i++) {
            var current_item = this.items[i];
            this.original.push(current_item.getAttribute('value'));
        }
        
        Event.observe($('upit-status-0'), 'click', this.clickListener.bindAsEventListener(this), false);
        Event.observe($('upit-status-1'), 'click', this.clickListener.bindAsEventListener(this), false);
        Event.observe($('upit-status-2'), 'click', this.clickListener.bindAsEventListener(this), false);
    },
    
    clickListener: function(e) {
  
        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        
        this.toggle(eventTarget);
    },
    
    toggle: function(eventTarget) {
        var id_array = eventTarget.getAttribute('id').split('-');
        var kontakt_type = id_array[id_array.length-1]
        
        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            $(this.items[i]).remove();
        }
        this.items = [];
        
        var load_items = teme[kontakt_type];
        var jl = load_items.length;
        for(var j = 0; j < jl; j++) {
            var item_to_load = load_items[j];
            var item_to_load_value = this.original[item_to_load];
            var new_option = document.createElement('option');
                new_option.setAttribute('value', item_to_load_value);
                new_option.appendChild(document.createTextNode(item_to_load_value))
                this.container.appendChild(new_option);
        }
        this.items = $(this.container).select('option');
        
        
    }
}


Event.observe(window, 'load', function() {
  kontakt_form.handle();
});


var advanced_search_checkboxes = {
    container: null,
    items: [],
    
    handle: function() {
        if(!$('advanced-search-form-container')) return;
        this.container = $('advanced-search-form-container').select('form')[0];
        if(!this.container) return;

        this.items = $(this.container).select('#search-document-type input' ,'#search-category input');

        var il = this.items.length;
        for(var i = 0; i < il; i++) {
            var current_item = this.items[i];
            Event.observe(current_item, 'click', this.clickListener.bindAsEventListener(this), false);
        }
        
    },
    
    clickListener: function(e) {
  
        var event = window.event ? window.event : e;
        var eventTarget = event.srcElement ? event.srcElement :  event.target;
        
        this.toggle(eventTarget);
    },    

    toggle: function(eventTarget) {
        var related_fieldset = $(eventTarget).up('fieldset');
        var related_inputs = $(related_fieldset).select('input');
        
        if(eventTarget == related_inputs[0]) {
        var il = related_inputs.length;
            for(var i = 0; i < il; i++) {
                if(i == 0) continue;
                var current_item = related_inputs[i];
                current_item.checked = '';
            }            
        } else {
            related_inputs[0].checked = '';
        }
    }    
}


Event.observe(window, 'load', function() {
  advanced_search_checkboxes.handle();
});


function table_stripes() {
    $$('table tr:nth-child(even)').invoke('addClassName','even')
    $$('table tr > td:first-child', 'table tr > th:first-child').invoke('addClassName','first-child')
}





var form_validation = {
    container: null,
    items: [],
    
    setup: function() {
        
        var contact_form = $$('.kontakt-obrazac form')[0];
        if(contact_form) {
            Event.observe(contact_form, 'submit', this.contactFormListener.bindAsEventListener(this), false);
        }

        var password_form_container = $('forgotten-password-container');
        if(password_form_container) {
            password_form =  $(password_form_container).select('form')[0];
            if(password_form) {
                Event.observe(password_form, 'submit', this.passwordFormListener.bindAsEventListener(this), false);
            }        
        }
        
    },
    
    contactFormListener: function(e) {

        var username_field = document.getElementsByName('Ime i prezime')[0];
        var email_field = document.getElementsByName('MailSendFrom')[0];


        if(username_field.value.replace(/ /gi, '') == '') {
            Event.stop(e);
            alert('Molimo popunite polje "Ime i prezime"');
        }
        
        if(email_field.value.replace(/ /gi, '') == '') {
            Event.stop(e);
            alert('Molimo popunite polje "E-mail adresa"');
        }
    },
    
    passwordFormListener: function(e) {
        
        var username_field = document.getElementsByName('Ime i prezime /naziv tvrtke')[0];
        var email_field = document.getElementsByName('E-mail adresa')[0];
        if(username_field.value.replace(/ /gi, '') == '') {
            Event.stop(e);
            alert('Molimo popunite polje "Ime i prezime - naziv tvrtke"');
        }
        
        if(email_field.value.replace(/ /gi, '') == '') {
            Event.stop(e);
            alert('Molimo popunite polje "E-mail adresa"');
        }
    }    

}