eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('6 r=C B({4:{g:1l,a:\'15\',m:X,c:{d:[\'J\',\'H\'],A:B.1b}},18:5(3,4){2.10(4);2.q=$(3);2.q.T(\'R\').j(5(3){3.O({\'M\':2.p.t(2,3),\'1k\':2.w.t(2,3)})},2)},p:5(3){$1i(3.z);7(!3.1a(2.4.a)){3.17(2.4.a);6 9=3.v(\'9\');7(9){7(2.4.g)9.g({J:14});9.c(2.4.c)}3.F().j(5(G){G.s(2.4.a)},2)}},w:5(3){3.z=(5(){3.s(2.4.a);6 f=3.v(\'f\');7(f)f.Z()}).m(2.4.m,2)}});r.Y(C W);V.S({c:5(b){7(!2.k){2.k=2.Q(b.A);2.h=2.P.N(2,b.d);2.l={};U(6 i L 2.h)2.l[i]=0}7(b.d.x(\'H\')||b.d.x(\'K\')){2.E(\'D\',\'1j\');2.u(\'9\').j(5(3){3.E(\'D\',\'1h\')})}2.k.1g(2.l).1e(2.h)},u:5(y){6 n=[];6 8=2.o();19(8&&8!==1c){7(8.1d().16(y))n.1f(8);8=8.o()}I n},F:5(){6 e=2.o().13();e.12(e.11(2),1);I e}});',62,84,'||this|el|options|function|var|if|cur|ul|hoverClass|obj|animate|props|children|iframe|bgiframe|now||each|Fx|FxEmpty|delay|matched|getParent|over|element|Rokmoomenu|removeClass|bind|getParents|getElement|out|contains|expr|sfTimer|opts|Class|new|overflow|setStyle|getSiblings|ele|height|return|opacity|width|in|mouseover|apply|addEvents|getStyles|effects|li|extend|getElements|for|Element|Options|500|implement|remove|setOptions|indexOf|splice|getChildren|false|sfHover|test|addClass|initialize|while|hasClass|empty|document|getTag|start|push|set|visible|clear|hidden|mouseout|true'.split('|'),0,{}))

var Site = {
  rootPath: '/',

  init: function() {
		// Site.fixMainMenu(); // N
    // Site.initRokMenu(); // Y
    Site.handleCategories(); // Y
    Site.handleCharsCounter(); // Y
    Site.handleCompareProducts(); // Y
    Site.handleNewWinOpen(); // Y
    var spinner = new Image();
    spinner.src = Site.rootPath +'client/css/images/spinner.gif';
  },
  
  fixMainMenu: function() {
		var mainMenuList = $E('ul', 'horiz-menu');
		var leftOffset = ((980 - mainMenuList.offsetWidth) / 2).toInt();
		$('horiz-menu').setStyle('left', leftOffset +'px');
	},
  
  initRokMenu: function() {
		new Rokmoomenu($E('ul.nav'), {
			bgiframe: false,
			delay: 500,
			animate: {
				props: ['height'], // ['opacity', 'width', 'height']
				opts: {
					duration: 700, // 400
					fps: 100,
					transition: Fx.Transitions.Bounce.easeOut // Quad.easeOut
				}
			}
		});
  },
  
  handleCategories: function() {
    
    // If category 'catalog', proceed
    if($('catalog_categories')) {
      var selectControls = $ES('select', 'catalog_categories');
      if(selectControls.length>0) selectControls.each(function(sc) {
        var currentBox = sc.getParent();
        sc.addEvent('change', function() {
          if(sc.getValue()!='') {
            // alert('Vrijednost je: '+ sc.getValue());
            // var el = new Element('div').setHTML('Vrijednost je: '+ sc.getValue());
            // el.inject(currentBox);
            var ajaxOptions = {method:'get', update:currentBox, onComplete:function(){Site.handleCategories();}};
            var link = $E('a.show-button', currentBox);
            if(link) {link.setStyle('visibility', 'hidden');}
            var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
            spinner.inject(currentBox);
            var category_type = ($('adverts-filter')) ? 'oglasnik' : 'katalog';
            new Ajax(Site.rootPath + category_type +'/update_categories/'+ sc.getValue() +'/', ajaxOptions).request();
          }
        });
      });
    }
  }, 
	
  handleCharsCounter: function() {
    if($('chars-counter')) {
      var currentBox = $('subcategory-chooser');
      $('category').addEvent('change', function() {
        var ajaxOptions = {method:'get', update:currentBox};
        var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
        spinner.inject(currentBox);
        new Ajax(Site.rootPath +'oglasnik/update_subcategories/'+ $('category').getValue() +'/', ajaxOptions).request();
      });
      
      var counter_field = $('chars-counter');
      var text_field = $('full_text');
      var max_length = 200;
      total_length = text_field.getValue().length;
      counter_field.setHTML(max_length - total_length);
      text_field.addEvent('blur',   function() {total_length = text_field.getValue().length;if(total_length>max_length) {text_field.value = text_field.getValue().substring(0, max_length);total_length = max_length;}counter_field.setHTML(max_length - total_length);});
      text_field.addEvent('focus',   function() {total_length = text_field.getValue().length;if(total_length>max_length) {text_field.value = text_field.getValue().substring(0, max_length);total_length = max_length;}counter_field.setHTML(max_length - total_length);});
      text_field.addEvent('keydown',   function() {total_length = text_field.getValue().length;if(total_length>max_length) {text_field.value = text_field.getValue().substring(0, max_length);total_length = max_length;}counter_field.setHTML(max_length - total_length);});
      text_field.addEvent('keyup',   function() {total_length = text_field.getValue().length;if(total_length>max_length) {text_field.value = text_field.getValue().substring(0, max_length);total_length = max_length;}counter_field.setHTML(max_length - total_length);});
    }
  },
	
	handleCompareProducts: function() {
    if($('compare-product-chooser')) {
			$('brand1').addEvent('change', function() {
        currentBox = $('model1');
				var ajaxOptions = {method:'get', update:'model1', onComplete:function(){
					$('model_1').addEvent('change', function() {
						var ajaxOptions = {method:'get', update:'compare-product-viewer-1'};
						var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
						spinner.inject($('compare-product-viewer-1'));
						new Ajax(Site.rootPath +'usporedba/show_model/'+ $('model_1').getValue() +'/', ajaxOptions).request();
					});
				}};
        var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
        spinner.inject(currentBox);
        new Ajax(Site.rootPath +'usporedba/update_model1/'+ $('brand1').getValue() +'/', ajaxOptions).request();
      });
			$('brand2').addEvent('change', function() {
        currentBox = $('model2');
				var ajaxOptions = {method:'get', update:'model2', onComplete:function(){
					$('model_2').addEvent('change', function() {
						var ajaxOptions = {method:'get', update:'compare-product-viewer-2'};
						var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
						spinner.inject($('compare-product-viewer-2'));
						new Ajax(Site.rootPath +'usporedba/show_model/'+ $('model_2').getValue() +'/', ajaxOptions).request();
					});
				}};
        var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
        spinner.inject(currentBox);
        new Ajax(Site.rootPath +'usporedba/update_model2/'+ $('brand2').getValue() +'/', ajaxOptions).request();
      });
		}
	}, 
  
  handleNewWinOpen: function() {
    var links = $$('a.newWin');
    if(links.length>0) links.each(function(link) {link.addEvent('click', function(e) {window.open(this, '');e = new Event(e).stop();})});
  }, 
  
  sfHover: function() {
		var isIE = !window.opera && navigator.userAgent.indexOf('MSIE') != -1;
		if(!isIE) return;
		var sfEls = document.getElementById("h-brand-nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
  
}

var Loader = {
  init: function() {
    Loader.handlePoll(); // N
    Loader.handleProductsHover(); // N
  },
  
  handlePoll: function() {
    if($('frmPoll')) {
      $('frmPoll').addEvent('submit', function(e) {
        e = new Event(e).stop();
        var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
        spinner.inject($('poll'));
        var ajaxOptions = {postBody:$('frmPoll'), update:'poll'};
        new Ajax(Site.rootPath +'homepage/poll/', ajaxOptions).request();
      });
    }
  }, 
  
	handleProductsHover: function() {
    var all_products = $ES('ul.products', 'middle-box');
    if(all_products.length>0) {all_products.each(function(products){
      var links = $ES('a.products-pic', products);
      if(links.length>0) {links.each(function(link) {
        link.addEvent('mouseover', function(e) {$('proizvodi-link-'+ link.getProperty('rel')).addClass('hover');});
        link.addEvent('mouseout', function(e) {$('proizvodi-link-'+ link.getProperty('rel')).removeClass('hover');});
        
      });}
    });}
  }
  
}

var mootabs = new Class({
	
	initialize: function(element, options) {
		this.options = Object.extend({
			width:				'300px',
			height:				'200px',
			changeTransition:	Fx.Transitions.Bounce.easeOut,
			duration:			1000,
			mouseOverClass:		'active',
			activateOnLoad:		'first',
			useAjax: 			false,
			ajaxUrl: 			'',
			ajaxOptions: 		{method:'get'},
			ajaxLoadingText: 	'Loading...'
		}, options || {});
		
		this.el = $(element);
		this.elid = element;
		
		this.el.setStyles({
			height: this.options.height,
			width: this.options.width
		});
		
		this.titles = $$('#' + this.elid + ' ul.mootabs_title li');
		this.panelHeight = this.el.getSize().size.y - (this.titles[0].getSize().size.y + 4);
		this.panels = $$('#' + this.elid + ' .mootabs_panel');

		// alert('panelHeight: '+ this.panelHeight + ', titles: '+ this.titles.length + ', panels: ' + this.panels.length);
		this.panels.setStyle('height', 'auto');
		
		this.titles.each(function(item) {
			item.addEvent('click', function(){
					item.removeClass(this.options.mouseOverClass);
					this.activate(item);
				}.bind(this)
			);
			
			item.addEvent('mouseover', function() {
				if(item != this.activeTitle)
				{
					item.addClass(this.options.mouseOverClass);
				}
			}.bind(this));
			
			item.addEvent('mouseout', function() {
				if(item != this.activeTitle)
				{
					item.removeClass(this.options.mouseOverClass);
				}
			}.bind(this));
		}.bind(this));
		
		
		if(this.options.activateOnLoad != 'none')
		{
			if(this.options.activateOnLoad == 'first')
			{
				this.activate(this.titles[0], true);
			}
			else
			{
				this.activate(this.options.activateOnLoad, true);	
			}
		}
	},
	
	activate: function(tab, skipAnim){
		if(! $defined(skipAnim))
		{
			skipAnim = false;
		}
		if($type(tab) == 'string') 
		{
			myTab = $$('#' + this.elid + ' ul li').filterByAttribute('title', '=', tab)[0];
			tab = myTab;
		}
		
		if($type(tab) == 'element')
		{
			var newTab = tab.getProperty('title');
			this.panels.removeClass('active');
			
			this.activePanel = this.panels.filterById(newTab)[0];
			
			this.activePanel.addClass('active');
			
			if(this.options.changeTransition != 'none' && skipAnim==false)
			{
				this.panels.filterById(newTab).setStyle('height', 0);
				var changeEffect = new Fx.Elements(this.panels.filterById(newTab), {duration: this.options.duration, transition: this.options.changeTransition});
				changeEffect.start({
					'0': {
						'height': [0, this.panelHeight]
					}
				});
			}
			
			this.titles.removeClass('active');
			
			tab.addClass('active');
			
			this.activeTitle = tab;
			
			if(this.options.useAjax)
			{
				this._getContent();
			}
		}
	},
	
	_getContent: function(){
		this.activePanel.setHTML(this.options.ajaxLoadingText);
		var newOptions = {update: this.activePanel.getProperty('id')};
		this.options.ajaxOptions = Object.extend(this.options.ajaxOptions, newOptions || {});
		var tabRequest = new Ajax(this.options.ajaxUrl + '?tab=' + this.activeTitle.getProperty('title'), this.options.ajaxOptions);
		tabRequest.request();
	},
	
	addTab: function(title, label, content){
		//the new title
		var newTitle = new Element('li', {
			'title': title
		});
		newTitle.appendText(label);
		this.titles.include(newTitle);
		$$('#' + this.elid + ' ul').adopt(newTitle);
		newTitle.addEvent('click', function() {
			this.activate(newTitle);
		}.bind(this));
		
		newTitle.addEvent('mouseover', function() {
			if(newTitle != this.activeTitle)
			{
				newTitle.addClass(this.options.mouseOverClass);
			}
		}.bind(this));
		newTitle.addEvent('mouseout', function() {
			if(newTitle != this.activeTitle)
			{
				newTitle.removeClass(this.options.mouseOverClass);
			}
		}.bind(this));
		//the new panel
		var newPanel = new Element('div', {
			'style': {'height': this.options.panelHeight},
			'id': title,
			'class': 'mootabs_panel'
		});
		if(!this.options.useAjax)
		{
			newPanel.setHTML(content);
		}
		this.panels.include(newPanel);
		this.el.adopt(newPanel);
	},
	
	removeTab: function(title){
		if(this.activeTitle.title == title)
		{
			this.activate(this.titles[0]);
		}
		$$('#' + this.elid + ' ul li').filterByAttribute('title', '=', title)[0].remove();
		
		$$('#' + this.elid + ' .mootabs_panel').filterById(title)[0].remove();
	},
	
	next: function(){
		var nextTab = this.activeTitle.getNext();
		if(!nextTab) {
			nextTab = this.titles[0];
		}
		this.activate(nextTab);
	},
	
	previous: function(){
		var previousTab = this.activeTitle.getPrevious();
		if(!previousTab) {
			previousTab = this.titles[this.titles.length - 1];
		}
		this.activate(previousTab);
	}
});

/**
 * Class: Marquee
 *
 * Element on page with ID 'marquee' becomes vertical marquee box.
 * 
 * @access    public
 * @author    Ivan Maros
 * @package   Metastudio.JSONLibrary
 * @since     22.10.2006
 * @todo      Should make all elements with className="verticalMarquee" a marquee.
 * @var       int slideSpeed Speed of slide in miliseconds.
 * @var       real numScreensOnEnd When all text passes, how many screens to delay.
 * @version   0.9a
 */
var Marquee = {
	slideSpeed: 30,
	numScreensOnEnd: 1, // Can be any number >= 1
	
	outerDiv: null,
	innerDiv: null,
	outerDivSize: null, // Can be 'width' or 'height'
	innerDivSize: null, // Can be 'width' or 'height'
	scrollPos: 0,
  pausePositions: null, 
	timeoutHandler: null,

	init: function() {
		if($('r-adverts')) {
      Marquee.buildMarqueeText();
      Marquee.setDivsSize();
      Marquee.startSlide();
    }
	},
	
	buildMarqueeText: function() {
		Marquee.outerDiv = $('r-adverts');
		Marquee.innerDiv = new Element('div').setStyle('background-color','transparent');
    Marquee.innerDiv.addEvent('mouseover', function() {Marquee.pauseSlide();});
    Marquee.innerDiv.addEvent('mouseout', function() {Marquee.startSlide();});
    Marquee.innerDiv.setHTML(Marquee.outerDiv.innerHTML);
		while(Marquee.outerDiv.firstChild) Marquee.outerDiv.removeChild(Marquee.outerDiv.firstChild);
		Marquee.outerDiv.appendChild(Marquee.innerDiv);
	},
	
	setDivsSize: function() {
		Marquee.outerDivSize = Marquee.outerDiv.offsetHeight;
		Marquee.innerDivSize = Marquee.innerDiv.offsetHeight;
		Marquee.scrollPos = Marquee.outerDivSize;
    var listBoxes = $ES('a', Marquee.outerDiv);
    
    Marquee.pausePositions = new Array();
    Marquee.pausePositions[0] = 0;
    var p = 0;
    listBoxes.each(function(box, counter) {
      p = p - box.offsetHeight;
      Marquee.pausePositions[counter+1] = p;
    });
    Marquee.pausePositions.pop();
	},

	startSlide: function() {
		if( (Marquee.scrollPos)<=((Marquee.outerDivSize - Marquee.numScreensOnEnd*Marquee.outerDivSize) - Marquee.innerDivSize) ) {
      Marquee.scrollPos = Marquee.outerDivSize;
		}
    
		Marquee.innerDiv.style.marginTop = Marquee.scrollPos +'px';
		// Marquee.innerDiv.style.marginLeft = Marquee.scrollPos +'px';
		Marquee.scrollPos--;
		
		Marquee.timeoutHandler = setTimeout( Marquee.startSlide, Marquee.slideSpeed );
    
    Marquee.pausePositions.each(function(position) {
      if(Marquee.scrollPos===position) {
      Marquee.pauseSlide();
      (function() {Marquee.startSlide();}).delay(3000);
      }
    });
	}, 
	
	pauseSlide: function() {
		clearTimeout(Marquee.timeoutHandler);
	}
	
}

// Image viewer
function popup(path, width, height) {
	if(width >= 468) height = parseInt(height) + 60;
	path = path.substr(path.indexOf('/repository'))
	var win = window.open(Site.rootPath + 'popup.php?path='+path+'&width='+width+'&height='+height, '', 'width='+width+',height='+height+',top='+(screen.height/2-(height/2))+',left='+(screen.width/2-(width/2)));
	
	//win.document.write('<html>\n<head>\n<title>Preglednik</title>\n</head>\n');
	//win.document.write('<body marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>\n');
	//
	//if( path.substring( (path.length-3),path.length )=='swf' ) {
	//	win.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH='+width+' HEIGHT='+height+'><PARAM NAME=movie VALUE="'+path+'"> <PARAM NAME=quality VALUE=high> <EMBED src="'+path+'" quality=high WIDTH='+width+' HEIGHT='+height+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=Shockwav eFlash"></EMBED> </OBJECT>');
	//} else {
	//	win.document.write('<a href="javascript:void(0);" onclick="window.close()" title="Kliknite za zatvaranje prozora"><img src="'+path+'" width="'+width+'" height="'+height+'" border="0" /></a>');
	//}
	//
	//win.document.write('</body>\n');
	//win.document.write('</html>\n');
	//win.document.close();
}

window.addEvent('domready', Site.init);
window.addEvent('load', init);
var tabsOptions = {width:'150px', height:'auto', changeTransition:'none', mouseOverClass:'over'};
if(document.location.href.indexOf(Site.rootPath + 'prodavaci') > -1) tabsOptions.activateOnLoad = 'Prodavači';
function init() {myTabs1 = new mootabs('usporedi-tabs', tabsOptions);}
window.addEvent('load', Loader.init);
window.addEvent('load', Marquee.init);
