

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/* 
AnchorPosition.js
Author: Matt Kruse
Last modified: 10/11/02

DESCRIPTION: These functions find the position of an <A> tag in a document,
so other elements can be positioned relative to it.

COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the 
Macintosh platform.

FUNCTIONS:
getAnchorPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor. Position is relative to the PAGE.

getAnchorWindowPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.

NOTES:

1) For popping up separate browser windows, use getAnchorWindowPosition. 
   Otherwise, use getAnchorPosition

2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the 
   anchor tag correctly. Do not do <A></A> with no space.
*/ 

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}


// parrams array
// contentId - ID of content element
// expandedClass - class name of header element when expanded
// collapsedClass - class name of header element when collapsed
function lgktree_click(elId,params) {
	
	// Check if collapsed
	if ($(elId).className == params['expandedClass']) {

		$(elId).className = params['collapsedClass'];

		$(params['contentId']).style.display = '';
		Effect.BlindUp(params['contentId'],{
			duration: 0.3,
			afterFinish: function(ef) {
				//$(params['contentId']).className = 'lgktreeContentCollapsed';
			}
		});
			
	} else {
		$(elId).className = params['expandedClass'];

		Effect.BlindDown(params['contentId'],{
			duration: 0.5,
			afterFinish: function(ef) {
				$(params['contentId']).className = 'lgktreeContentExpanded';
			}
		});
	}
	
}


/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var logTooltip = Class.create({
    initialize: function(options){
        //logHistory.instances.push(this);
	//if (history.navigationMode) history.navigationMode = 'compatible';

        this.events = [];
        this.events_tooltips = [];
        this.tooltips = [];
        this.effects = [];
        this.executor = [];

        this.delay = 0.6;			// IN SECS
        this.eff_speed = 0.4;	// IN SECS
        this.tolerance = 15;	// IN PX
        //this.container = $(container);
        //this.container.update('');
        this.options = {};

        Object.extend(this.options, options || {});
	
        if (!this.options.delay) this.options.delay = this.delay;
        if (!this.options.tolerance) this.options.tolerance = this.tolerance;
    },
// ASSIGN DELEGATE TIMER TO HIDE THE TOOLTIP
    start: function(el_tooltip) {
	//alert('Start Timer - ' + el_tooltip + ' Delay ' + this.options.delay);
	this.stop(el_tooltip);
	this.executor[el_tooltip] = new PeriodicalExecuter(function() {
            this.delegate(el_tooltip); //start slidehow
        }.bind(this), this.options.delay);
    },
// STOP DELEGATE TIMER
    stop: function(el_tooltip) {
	//alert('Stop Timer - ' + el_tooltip);
	try {this.executor[el_tooltip].stop();} catch(e) {}
    },

// TOOLTIP IS NOW MADE INVISIBLE
    delegate: function(el_tooltip) {
	// HIDE ELEMENT
	this.stop(el_tooltip);

	try { this.effects[el_tooltip].cancel(); } catch (e) {}
	try { this.effects[el_tooltip] = new Effect.Fade(this.tooltips[el_tooltip], {duration: this.eff_speed});} catch (e) {}

	this.tooltips[el_tooltip].onmouseover = Prototype.emptyFunction;
	this.tooltips[el_tooltip].onmouseout = Prototype.emptyFunction;

	this.active_event = ""; this.active_tooltip = "";
    },

// BIND EVENTS AND TOOLTIPS
    add: function (el_event, el_tooltip) {
	this.events[el_event] = $(el_event);
	this.tooltips[el_tooltip] = $(el_tooltip);
	this.events_tooltips[el_event] = el_tooltip;

	this.events[el_event].onmouseover = this.mouseOver.bind(this, el_event);
	this.events[el_event].onmouseout = this.mouseOut.bind(this, el_event);
		
    },

    mouseOver: function (el_event) {
	// CHECK IF ELEMENTS ARE NOT EQUAL
    // STOP HIDING TIMER
		this.stop(this.events_tooltips[el_event]);
    // IF
		if (this.active_event != el_event) {
		// STOP TIMER IF ACTIVE
			this.stop(this.events_tooltips[this.active_event]);

		// TOOLTIP NAME - OLD & NEW
			var tt_old = this.events_tooltips[this.active_event];
			var tt_new = this.events_tooltips[el_event];

		// DISABLE OLD TOOLTIPS
			if (tt_old != tt_new) {

				if (tt_old) {
				// HIDE OLD TOOLTIP - EFFECT FADE
					try { this.effects[tt_old].cancel(); } catch (e) {}
					try { this.effects[tt_old] = new Effect.Fade(this.tooltips[tt_old], {duration: this.eff_speed});} catch (e) {}

					this.tooltips[tt_old].onmouseover = Prototype.emptyFunction;
					this.tooltips[tt_old].onmouseout = Prototype.emptyFunction;
				}
			
			} else {
			// MOVE NEW TOOLTIP - NO ANIMATION
				this.setPosition(el_event, tt_new);
			// SAME TOOLTIP ANIMATE MOVEMENT
				this.tooltips[tt_new].show();
			}

		// MOVE NEW TOOLTIP - NO ANIMATION
			this.setPosition(el_event, tt_new);

		// SHOW NEW TOOLTIP - EFFECT APPEAR
			try { this.effects[tt_new].cancel(); } catch (e) {}
			try { this.effects[tt_new] = new Effect.Appear(this.tooltips[tt_new], {duration: this.eff_speed});} catch (e) {}

		// SET ACTIVE EVENT AND TOOLTIP ELEMENT
			this.active_event = el_event;
			this.active_tooltip = tt_new;

		// BIND EVENTS
			this.tooltips[tt_new].onmouseover = this.mouseOverTooltip.bind(this, tt_new);
			this.tooltips[tt_new].onmouseout = this.mouseOutTooltip.bind(this, tt_new);
		} else {
			this.tooltips[this.events_tooltips[el_event]].show();
			this.active_event = el_event;
			this.active_tooltip = this.events_tooltips[el_event];
		}
    },

    mouseOut: function (el_event) {
	// START CHECKING POSITION ALLOW SOME TIME OUT
	this.start(this.events_tooltips[el_event]);
    },

    mouseOverTooltip: function (el_tooltip) {
	this.stop(el_tooltip);
	this.tooltips[el_tooltip].show();
    },

    mouseOutTooltip: function (el_tooltip) {
	this.start(el_tooltip);
    },

    setPosition: function(el_event, el_tooltip) {
	var o = this.events[el_event];
	oTop = o.offsetTop;
	while (o.offsetParent != null) {
	    oParent = o.offsetParent;
	    oTop += oParent.offsetTop;
	    o = oParent;
	}

	o = this.events[el_event];
	oLeft = o.offsetLeft;
	while (o.offsetParent != null) {
	    oParent = o.offsetParent;
	    oLeft += oParent.offsetLeft;
	    o = oParent;
	}

	this.tooltips[el_tooltip].absolutize();
	this.tooltips[el_tooltip].setStyle({
	    top: oTop + 'px',
	    left: (oLeft - this.tooltips[el_tooltip].getWidth()) + 'px'
	});

    }
});


/**
 * @author Nikola Ivanovic i Emil S. Dizajner Yea :P
 * @copyright 2009
 */

var Rating = Class.create({
    initialize: function(container, message, options){
    	try {
    		Rating.instances.push(this);
	        this.value = false;
	        this.links = [];
	        this.container = $(container);
			this.container_id = container;
			this.message = $(message);
			this.message_id = message;
	        this.container.update('');
	        this.options = {
	            min: 1,
	            max: 5,
	            rated: false,
	            capture: true,
	            multiple: false,
	            classNames: {
	                off: 'rating_off',
	                half: 'rating_half',
	                on: 'rating_on',
	                selected: 'rating_selected',
	                selected_half: 'rating_selected_half'
	            },
				messages: {
	                rating1: 'Uopšte mi se ne sviđa',
	                rating2: 'Ne sviđa mi se',
	                rating3: 'Nije loš',
	                rating4: 'Sviđa mi se',
	                rating5: 'Veoma mi se sviđa'
	            },
	            updateUrl: false,
	            updateParameterName: 'value',
	            updateOptions : {},
	            afterChange: Prototype.emptyFunction
	        };
	        Object.extend(this.options, options || {});

	        this.container.observe('click', function(s) {
	            s.stop();
	            return false;
	        }.bind(this));
	        
	    // SET RATED VALUE
	        if(this.options.value){
	            this.value = this.options.value;
	            delete this.options.value;
	        }
	        
	    // CREATE ARRAY OF RATING  ELEMENTS
	        var range = $R(this.options.min, this.options.max);
	        range.each(function(i){
	        // PUT ALL ELEMENTS IN CONTAINER
	            var link = this.buildLink(i);
	            this.container.appendChild(link);
	            this.links.push(link);
	        }.bind(this));
					
	    // SET CURRENT VALUE
	        this.setValue(this.value || this.options.min - 1, false, true);
    	} catch (e) {alert(e);}
    },

    buildLink: function(rating){
        var link = $(document.createElement('a'));
        link.value = rating;

        if(!this.options.rated){
        // IF NOT RATED ALLOW TO RATE
            link.href = '';
            link.onmouseover = this.mouseOver.bind(this, link);
            link.onmouseout = this.mouseOut.bind(this, link);
            link.onclick = this.click.bindAsEventListener(this, link);
        }else{
        // IF RATED DISABLE TO RATE AND ANIMATE CONTROL
            link.style.cursor = 'default';
            link.observe('click', function(event){
                Event.stop(event);
                return false;
            }.bindAsEventListener(this));
        }
        link.addClassName(this.options.classNames.off);
        
        return link;
    },

    disable: function(){
        //alert("disable");
        this.links.each(function(link){
            link.onmouseover = Prototype.emptyFunction;
            link.onmouseout = Prototype.emptyFunction;
            link.onclick = Prototype.emptyFunction;
            link.observe('click',function(event){
                Event.stop(event);
                return false;
            }.bindAsEventListener(this));
            link.style.cursor = 'default';
        }.bind(this));
    },

    setValue: function(value, force_selected, prevent_callbacks){
        this.value = value;
        
        this.render(this.value, force_selected, false);
        if(!prevent_callbacks) {
            if(this.options.updateUrl){
                var params = {};
                params[this.options.updateParameterName] = this.value;
                new Ajax.Request(
                    this.options.updateUrl,
                    {
                        parameters : Object.extend(this.options.updateOptions, params),
                        onComplete: function(request) {
                            var json;
                            eval('json = ' + request.responseText);
							alert(this.container_id);
                        }
                    }
                );
            }
            //this.notify('afterChange', this.value);
            if (this.options['afterChange'] != Prototype.emptyFunction) {
                this.options['afterChange'](this.value);
            }
        }
        /*
        alert(json.percent);
        if (json.percent && !prevent_callbacks) {
            this.options.rated = true;
            this.setValue(json.percent, true, true);
        }
        */
    },
	
// DISPLAY RATED START
    render: function(rating, force_selected, display_messages){
	
		if (display_messages) {
			this.message.innerHTML = this.options.messages['rating' + rating];
		} else this.message.innerHTML = rating;
	
        this.links.each(function(link){
        // DISPLAY START TO THE CURRENT RATING
            if(link.value <= Math.ceil(rating)) {
                link.className = this.options.classNames[link.value <= rating ? 'on' : 'half'];
                if(this.options.rated || force_selected) {
                    link.addClassName(this.options.classNames[link.value <= rating ? 'selected' : 'selected_half']);}
            }else {
                link.className = this.options.classNames.off; }
        }.bind(this));
    },

    mouseOver: function(link){
        this.render(link.value, true, true);
    },
    mouseOut: function(link){
        this.render(this.value, false, false);
    },
    click: function(event, link){
        this.options.rated = true;
        this.setValue((link.value ? link.value : link), true);
        this.disable();
        if(!this.options.capture){
            Event.stop(event);
            return false;
        }
        return false;
    }
});
Object.extend(Rating,{
    instances: [],
    findByElementId: function(id){
        return Rating.instances.find(function(instance){
            return (instance.container.id && instance.container.id == id);
        });
    }
});

/* unFocus.History, version2.0 (Beta 2) (2007/09/10)
Copyright: 2005-2007, Kevin Newman (http://www.unfocus.com/Projects/HistoryKeeper/)
License: http://www.gnu.org/licenses/lgpl.html */
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}('8 o={};o.Q=2(){h.j={};B(8 i=0;i<18.l;i++){h.j[18[i]]=[]}};o.Q.W={12:2(a,b){B(8 i=0;i<h.j[a].l;i++)4(h.j[a][i]==b)7;h.j[a].1Z(b)},1V:2(a,b){B(8 i=0;i<h.j[a].l;i++){4(h.j[a][i]==b){h.j.1S(i,1);7}}},p:2(a,b){B(8 i=0;i<h.j[a].l;i++)h.j[a][i](b)}};o.14=(2(){2 C(){8 c=h,E=1E,v,3;8 d=2(){7 1p.1k.23(1)};3=d();8 e=2(a){z.1p.1k=a};2 1f(){8 a=d();4(3!=a){3=a;c.p("n",a)}}4(O)v=O(1f,E);2 r(a){4(!1c(a)){8 b;4(/1b/.19(A.17)&&!z.16)b=6.w(\'<a G="\'+a+\'">\'+a+"</a>");u b=6.w("a");b.t("G",a);Z(b.D){V="U";1D="1A";1d=s()+"R";1v=1t()+"R"}6.k.L(b,6.k.P)}}2 1c(a){4(6.24(a).l>0)7 q}4(1i 1h.1g=="22"){2 s(){7 1h.1g}}u 4(6.N&&6.N.M){2 s(){7 6.N.M}}u 4(6.k){2 s(){7 6.k.M}}21(20(s).1X().1e(/1W/g,"1U").1e(/Y/g,"X"));c.1T=2(){7 3};2 9(a){4(3!=a){r(a);3=a;e(a);c.p("n",a)}7 q}c.9=2(a){r(3);c.9=9;7 c.9(a)};4(/1a\\/\\d+/.19(A.1n)&&A.1n.1o(/1a\\/(\\d+)/)[1]<1R){8 f=H.l,x={},m,y=15;2 S(){m=6.w("1O");m.13="1N";m.1M="1L";6.k.L(m,6.k.P)}e=2(a){x[f]=a;m.1K="#"+d();m.1J()};d=2(){7 x[f]};x[f]=3;2 T(a){4(3!=a){r(a);3=a;f=H.l+1;y=q;e(a);c.p("n",a);y=15}7 q}c.9=2(a){r(3);S();c.9=T;7 c.9(a)};2 10(){4(!y){8 a=H.l;4(a!=f){f=a;8 b=d();4(3!=b){3=b;c.p("n",b)}}}};1I(v);v=O(10,E)}u 4(1i 1H!="1G"&&z.1F&&!z.16&&A.17.1o(/1b (\\d\\.\\d)/)[1]>=5.5){8 g,F;2 11(){8 a="1C";g=6.w("1B");g.t("G",a);g.t("13",a);g.t("1P",\'1Q:;\');g.D.V="U";g.D.1d="-1z";6.k.L(g,6.k.P);F=1y[a];J(3,q)}2 J(a){Z(F.6){1x("1w/I");1u("<I><1q></1q><k 1s",\'1Y="1r.o.14.K(\\\'\'+a+\'\\\');">\',a+"</k></I>");25()}}2 1m(a){3=a;c.p("n",a)}c.K=2(){c.K=1m};2 1l(a){4(3!=a){3=a;J(a)}7 q};c.9=2(a){11();c.9=1l;7 c.9(a)};c.12("n",2(a){e(a)})}}C.W=1j o.Q("n");7 1j C()})();',62,130,'||function|_currentHash|if||document|return|var|addHistory||||||||this||_listeners|body|length|_form|historyChange|unFocus|notifyListeners|true|_createAnchor|getScrollY|setAttribute|else|_intervalID|createElement|_historyStates|_recentlyAdded|window|navigator|for|Keeper|style|_pollInterval|_historyFrameRef|name|history|html|_createHistoryHTML|_updateFromHistory|insertBefore|scrollTop|documentElement|setInterval|firstChild|EventManager|px|_createSafariSetHashForm|addHistorySafari|absolute|position|prototype|||with|_watchHistoryLength|_createHistoryFrame|addEventListener|id|History|false|opera|userAgent|arguments|test|WebKit|MSIE|_checkAnchorExists|top|replace|_watchHash|pageYOffset|self|typeof|new|hash|addHistoryIE|updateFromHistory|appVersion|match|location|head|parent|onl|getScrollX|write|left|text|open|frames|900px|block|iframe|unFocusHistoryFrame|display|200|print|undefined|ActiveXObject|clearInterval|submit|action|get|method|unFocusHistoryForm|form|src|javascript|420|splice|getCurrent|Left|removeEventListener|Top|toString|oad|push|String|eval|number|substring|getElementsByName|close'.split('|'),0,{}))


var updater = null;		
var upload_identifier = null;
var Iframe = null;
var uploaderForm = null;
var callbackFunction = null;
var iframeContainerId = null;
var progressBarContainerId = null;
var progressBarContentUrl = null;
var iframeUploaderId = 'iframe_uploader';
var iframeCallback = '';//'index.php';
var request_num = 0;

function set_upload_identifier(ident){
	upload_identifier = ident;
}

function set_callback(clback){
	callbackFunction = clback;
}

function set_iframe_container(id){
	iframeContainerId = id;
}

function set_progress_bar_container(id){
	progressBarContainerId = id;
}

function set_progress_bar_url(url){
	progressBarContentUrl = url;
}
		
function createIframe(){
	var iframe_container = window.document.getElementById(iframeContainerId);	
	var callback;
	if(iframeCallback)
		callback = 'window.location=\'' + iframeCallback + '\'';
	else
		callback = '';
	
	if(Iframe==null && iframe_container){
//    Iframe = window.document.createElement('iframe');
//    Iframe.id = iframeUploaderId;
//    Iframe.name = iframeUploaderId;    
//    Iframe.onload = 'stopUploading();';          
//    Iframe.src = '';
//    Iframe.style.height = '100px';
//    Iframe.style.width = '100px';
//    Iframe.style.visibility = 'visible';    
//    iframe_container.appendChild(Iframe);    
		iframe_container.innerHTML = '<iframe id="'+iframeUploaderId+'" name="'+iframeUploaderId+'" onload="stopUploading();'+ callback +'" style="height:300px; width:500px; visibility:hidden;"></iframe>';
		Iframe = window.document.getElementById(iframeUploaderId);	
  }
}

function destroyIframe(){		
	var iframe_container = window.document.getElementById(iframeContainerId);	
	
	if(iframe_container)
		iframe_container.innerHTML = "";
	
	if(Iframe!=null){
		//iframe_container.removeChild(Iframe);
		Iframe=null;
	}
	
}


function stopUploading(){			
	//if it is already created we need to get the latest recorded upload status
	if( updater!=null ){
		
		updater.stop();
		updater=null;
		
		//getting the last information
		//new Ajax.Updater(progressBarContainerId, 'upload_progress_monitor.php?UPLOAD_IDENTIFIER='+upload_identifier, {
		new Ajax.Updater(progressBarContainerId, progressBarContentUrl, {		
		  method: 'get'  
		});
	}
	
	if(uploaderForm!=null)
		uploaderForm.attributes['target'].value="_self";

/*	
	var iframe_container = document.getElementById(iframeContainerId);
	var iframe = document.getElementById(iframeUploaderId);
	document.body.innerHTML = iframe.contentWindow.document.body.innerHTML;
*/
	destroyIframe();
		
}

function startUploading(uploader_form_id){
	uploaderForm = window.document.getElementById(uploader_form_id);	
	
	if(!uploaderForm){
		alert('Invalid form ID!');
		return false;
	}
			
	createIframe();
//	alert('IFrame created');
//	alert('IFrame uploader ID ' + iframeUploaderId);
	//alert(iframeUploaderId);
	uploaderForm.attributes['target'].value=iframeUploaderId;
	uploaderForm.submit();
//	alert('form sent created');
	//return;
	
	startProgressBar();		
	
	//alert('progres URL' + progressBarContentUrl);
	//alert('container ID = ' + progressBarContainerId);
	//alert('progress monitoring started');
}

function startProgressBarOld() {
				
	if(updater==null){
		//updater = new Ajax.PeriodicalUpdater(progressBarContainerId, 'upload_progress_monitor.php?UPLOAD_IDENTIFIER='+upload_identifier, {
		updater = new Ajax.PeriodicalUpdater(progressBarContainerId, progressBarContentUrl, {		
		  method: 'get', 
		  frequency: 2,
		  decay: 2
		});
	}
	else
		updater.start();//re-enabling updater if it is created
}

function startProgressBar() {
				
	//updater = new Ajax.Updater(progressBarContainerId, 'upload_progress_monitor.php?UPLOAD_IDENTIFIER='+upload_identifier, {
	request_num++;
	new Ajax.Request(progressBarContentUrl+'&'+request_num, {		
	  method: 'get', 
	  onSuccess: function(transport) {
//	  	alert(transport.responseText);
	  	if (transport && transport.responseText != '') {
	  		var el = document.getElementById(progressBarContainerId);
	  		el.innerHTML = transport.responseText;
	  		setTimeout("startProgressBar()",2000);
	  	}
	  }
	});
}

function onCompleteProgressBar(transport,params) {
	if (!transport || transport.responseText == '')
		updater.stop();
}



var compareLastScroll = {};
function compareInit(url,params) {
	if ($('compareProductsLayer')) {
		if (!url || url == '') url = 'compare.php?action=ajax_layer&subaction=add';
		new Ajax.Request(url,{
			method: 'get',
			onSuccess: function(transfer) {
				if (transfer.responseText != '') {
					$('compareProductsContent').innerHTML = transfer.responseText;
					/*
					if (!params || !params['noAppearEffect'])
						new Effect.Appear($('compareProductsLayer'), { duration: 1, from: 0.0, to: 1});

					if (params && params['AppearContent'])
						new Effect.Appear($('compareProductsContent'), { duration: 1, from: 0.0, to: 1});
					*/
					
					if (!params || !params['noAppearEffect']) {
						new Effect.Morph('compareProductsLayer', {
						  style: {marginLeft: '0px'}, // CSS Properties
						  duration: 0.8 // Core Effect properties
						});
					}


					/*
					Event.observe(window, 'scroll', function() {					
						if (!Prototype.Browser.IE) {
							var scr = document.viewport.getScrollOffsets();
							$('compareProductsLayer').style.bottom = '-'+scr['top']+'px';
							compareLastScroll = scr;
						}
					});
					*/
				} else {
					//$('compareProductsLayer').style.display = 'none';
				}
			}
		});
	}
}

function compareHideProducts() {
	new Effect.Morph('compareProductsLayer', {
	  style: {marginLeft: '-184px'}, // CSS Properties
	  duration: 0.8 // Core Effect properties
	});
}

function compareShowProducts() {
	new Effect.Morph('compareProductsLayer', {
	  style: {marginLeft: '0px'}, // CSS Properties
	  duration: 0.8 // Core Effect properties
	});
}

function compareAddProduct(product_id) {
	compareInit('compare.php?action=ajax_layer&subaction=add&product_id='+product_id,{
//		noAppearEffect: true,
		AppearContent: true
	});
}

function compareRemoveProduct(product_id) {
	compareInit('compare.php?action=ajax_layer&subaction=remove&product_id='+product_id,{
		noAppearEffect: true,
		AppearContent: true
	});
}

function compareEmptyProducts() {
	compareInit('compare.php?action=ajax_empty',{
		noAppearEffect: true,
		AppearContent: true
	});
}


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;


function setImage(lrg,img)
{
	document.getElementById("mainImage").src=lrg;
	document.getElementById("magnifier").href=img;
	largePhoto = img;
}
function openPhoto() {
	path =  document.getElementById("magnifier").href;
/*
	myLightWindow.activateWindow({
		href: path,
		title: ''
	});
*/
//	window.open(path,'large_photo','width=300,height=300');
	var img = new Image();
	Event.observe(img, 'load', function() {
		var width = img.width;
		var height = img.height;
		var dim = document.viewport.getDimensions();
		var scr = document.viewport.getScrollOffsets();
		$('popupBox').style.display = 'none';
		$('popupBoxContent').innerHTML = '';
		$('popupBox').style.left = ((dim['width']-width-20)/2+scr['left']) + 'px';
		$('popupBox').style.top = ((dim['height']-height-20)/2+scr['top']) + 'px';
		$('popupBox').style.width = $('popupBox').style.width = '0px';
//		$('popupBox').style.overflow = '';
//		$('popupBox').style.display = '';

		var imgOff = $('mainImage').cumulativeOffset();
		var imgDim = $('mainImage').getDimensions();

/*
		new Effect.Scale($('popupBox'), 100, {
			duration: 0.4,
			scaleContent: true,
			scaleFrom: 10,
			scaleFromCenter: true,
			scaleMode: {originalHeight: height+20, originalWidth: width+20},
			afterFinish: function(ef) {
				$('popupBoxContent').innerHTML = '<img src="'+path+'" />';

				Event.observe($('popupBox'), 'click', function() {
					$('popupBox').style.display = 'none';
					$('popupBoxContent').innerHTML = '';
				});

			}
		});
*/

		$('popupBox').style.width = $('mainImage').width + 'px';
		$('popupBox').style.height = $('mainImage').height + 'px';
		$('popupBox').style.top = imgOff.top + 'px';
		$('popupBox').style.left = imgOff.left + 'px';
		$('popupBox').style.display = '';
		new Effect.Parallel([
//				new Effect.Appear($('popupBox'), { duration: 0.5, from: 0.7, to: 1,sync: true }),
				new Effect.Scale($('popupBox'), 100, {
					duration: 0.5,
					scaleContent: true,
					scaleFrom: 100 * $('mainImage').width / (width+20),
					scaleMode: {originalHeight: height+35, originalWidth: width+20},
					sync: true
				}),
				new Effect.Move($('popupBox'), {
					duration: 0.5,
					x: ((dim['width']-width-20)/2+scr['left']),
					y: ((dim['height']-height-20)/2+scr['top']),
					mode: 'absolute',
					sync: true
				})
			],
			{
			duration: 0.5,
			afterFinish: function(ef) {
				$('popupBoxContent').innerHTML = '<img src="'+path+'" />';

				Event.observe($('popupBox'), 'click', function() {
					$('popupBox').style.display = 'none';
					$('popupBoxContent').innerHTML = '';
				});

			}
		});

	});
	img.src = path;

}
function openLargePhoto(src) {
	var img = document.getElementById('largeImage');

	img.src = 'images/spacer.gif';
  if (src)
		img.src = src;
	else
		img.src = largePhoto;

	var imgDiv = document.getElementById('largeImageDiv');
	imgDiv.style.display = '';
}
function closeLargePhoto() {
	var imgDiv = document.getElementById('largeImageDiv');
	imgDiv.style.display = 'none';
}
function rateProduct(pid,rate){
	$('rating').style.display = 'none';
	$('send').style.display = 'none';
	$('ratingLoad').style.display = '';

	pid= parseInt(pid);
	rate=parseInt(rate);

  new Ajax.Request('ajax_functions.php?action=product_rating&product_id='+pid+'&rate='+rate, {
                    asynchronous:true,
                    onComplete:function(request){
								var json;
								eval('json = ' + request.responseText);
								$('ratingLoad').style.display = 'none';
								$('ratingInfo').innerHTML= json[0].message;
								$('currentRating').style.width = json[0].precent;
								$('currentRatingMain').style.width = json[0].precent;
                     }
                    });

}

function loadCompareList(cid) {
	$('compareProducts').style.display = '';
	$('compare_list_loading').style.display = '';
	$('compareProducts').scrollTo();

	var qs = 'product_id={DMY}{PRODUCT_ID}';
	qs += '&' + $("product_view_form").serialize();
  new Ajax.Request('proizvod.asp?action=ajax_compare_list&'+qs, {
                    asynchronous:true,
                    onComplete:function(request){
											$("compareProductsContent").innerHTML = request.responseText;
											$('compare_list_loading').style.display = 'none';
                     }
                    });

}

function viewFormSubmit(prodId, pageLink) {

		//var f = document.forms.view_form;
		var f = $("product_view_form")

		f.attributes['action'].value = pageLink;
		if (f.elements['product_id'])
			f.elements['product_id'].value = prodId;
		f.submit();
		return false;
}

function changeProductImage(image_id) {

	clearTimeout(autoTimeout);
	if (image_id != '' && productImages['byImageId'][image_id]) {
		setImage(productImages['byImageId'][image_id]['src'],productImages['byImageId'][image_id]['largeSrc']);

		var imgId;
		var el;
		try {
		if (current_image_id > 0) {
			imgId = "thumb"+current_image_id;
			el = $(imgId);
			if (el) {
				el.style.border = '1px solid #FFFFFF;';
			}
		}
		} catch(err) {}

		try {
		current_image_id = image_id;
		if (current_image_id > 0) {
			imgId = "thumb"+current_image_id;
			el = $(imgId);
			if (el) {
				el.style.border = '1px solid #888888;';
			}
		}
		} catch(err) {}
	}

}

function startAutoChangeProductImage() {
	clearTimeout(autoTimeout);
	if (productImages['byImageNum'].length > 1)
		autoTimeout = setTimeout("autoChangeProductImage()",5000);
}

function autoChangeProductImage() {
	clearTimeout(autoTimeout);
	var nextNum = (1+productImages['byImageId'][current_image_id]['num'])%productImages['byImageNum'].length;
	var nextImageId = productImages['byImageNum'][nextNum];
	changeProductImage(nextImageId);
	autoTimeout = setTimeout("autoChangeProductImage()",5000);
}

function productRate(value) {
	var updateOptions = {
		product_id: startup_options.product_id,
		rating: value
	}
	new Ajax.Request('product.php?action=ajax_product_rating', {
		parameters : Object.extend(updateOptions, {}),
		onComplete: function(request) {
			var json;
			eval('json = ' + request.responseText);
			prod_rate.setValue(json.percent, true, true);
			$('rating_value').innerHTML = json.message;
		}
	});
}

var current_image_id = '';
var productImages = new Object();
productImages['byImageId'] = new Object();
productImages['byImageNum'] = new Array();
var autoTimeout;