/*
The Hitchhiker's Guide to the Galaxy: "To summarize: It is a well-known fact
that those people who must want to rule people are, ipso facto, those least
suited to do it. To summarize the summary: Anyone capable of getting themselves
made President should by no means be allowed to do the job. To summarize the
summary of the summary: People are a problem." 
*/

function vplayer(file,w,h){
	if(document.getElementById('vplayer')){
		var flashvars = {videoFile:file, autoStart:"false", bufferSize:"3", feedBack:"false", videoInfo:""};
		var params = {allowScriptAccess:"always", allowFullScreen:"true", bgcolor:"#fff"};
		var attributes = {id:"vplayer", name:"vplayer"};
		swfobject.embedSWF("includes/videoPlayer.swf", "vplayer", w, h, "9.0.0", "includes/expressInstall.swf", flashvars, params, attributes);		
	}
}
  
function responseFromAS(response){
	document.getElementById('feedback').innerHTML = response;
	setTimeout("document.getElementById('feedback').innerHTML = ''", 5000);
}
 
function get_content_size() {
    var size = new Array();
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        size[0] = window.innerWidth;
        size[1] = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        size[0] = document.documentElement.clientWidth;
        size[1] = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        size[0] = document.body.clientWidth;
        size[1] = document.body.clientHeight;
    }
    return size;
}

function get_scroll_xy() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant 
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant 
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode 
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //return [scrOfX, scrOfY];
    return scrOfY;
}
 
var g = new gallery();

function gallery(){

	var obj = this;
	var img = null;
	this.wrapper = null;
	this.client = new Array();
	this.distance = new Array();

	this.init = function(o){

		this.wrapper = document.createElement("DIV");
		this.wrapper.id = "blob_wrapper";
		this.wrapper.style.position = "absolute";
		var ul = document.createElement("UL");
		ul.id = "blob_header";
		this.header = ul;
		
		var imgs = o.parentNode.parentNode.getElementsByTagName("IMG");
		for(i=0; i<imgs.length; i++){
			var li = document.createElement("LI");
			li.innerHTML = (i+1);
			li.id = imgs[i].src.replace(/thumbnails\//, "");
			li.onclick = function(){ obj.swap(this); };
			ul.appendChild(li);
		}
		
		var li = document.createElement("LI");
		li.className = "blob_killer";
		li.innerHTML = "x";
		li.title = "close me"
		li.onclick = function() { obj.kill(); };
		ul.appendChild(li);
	
		this.wrapper.appendChild(ul);
	};

	this.swap = function(o){

		if(!document.getElementById("blob_wrapper")){ this.init(o);}
		img = new Image();
		img.id = "blob";		
		img.src = (o.nodeName == "IMG") ? o.src.replace(/thumbnails\//, "") : o.id; //(this.flag) ? o.src.replace(/thumbnails\//, "") : o.id;
		this.wait();
	};

	this.wait = function(){
		if(img.complete){
			if(document.getElementById("blob")){ document.getElementById("blob").parentNode.removeChild(document.getElementById("blob")); }
			point = window.center({width:img.width,height:img.height})
			
			this.wrapper.style.top = point.y + "px";
			this.wrapper.style.left = point.x + "px";

			this.wrapper.appendChild(img);
			document.body.appendChild(this.wrapper);

			Drag.init(this.wrapper);
		
		}else{
			window.setTimeout('g.wait()', 500);
		}
	};

	this.kill = function(){
		if(document.getElementById("blob_wrapper")){ document.getElementById("blob_wrapper").parentNode.removeChild(document.getElementById("blob_wrapper")); }
	};

	return true;
}

window.size = function(){
	var w = 0;
	var h = 0;
	if(!window.innerWidth){ //IE
		if(!(document.documentElement.clientWidth == 0)){ //strict mode
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}else{ //quirks mode
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}else{ //w3c
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

window.center = function(){
	var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	if(!window.pageYOffset){ //IE
		if(!(document.documentElement.scrollTop == 0)){ //strict mode
			offsetY = document.documentElement.scrollTop;
			offsetX = document.documentElement.scrollLeft;
		}else{ //quirks mode
			offsetY = document.body.scrollTop;
			offsetX = document.body.scrollLeft;
		}
	}else{ //w3c
		offsetX = window.pageXOffset;
		offsetY = window.pageYOffset;
	}
	_x = ((this.size().width - hWnd.width) / 2) + offsetX;
	_y = ((this.size().height - hWnd.height) / 2) + offsetY;
	return{x:_x, y:_y};
}

var Drag={obj:null,init:function(o,oRoot,minX,maxX,minY,maxY,bSwapHorzRef,bSwapVertRef,fXMapper,fYMapper){o.onmousedown=Drag.start;o.hmode=bSwapHorzRef?false:true;o.vmode=bSwapVertRef?false:true;o.root=oRoot&&oRoot!=null?oRoot:o;if(o.hmode&&isNaN(parseInt(o.root.style.left)))o.root.style.left="0px";if(o.vmode&&isNaN(parseInt(o.root.style.top)))o.root.style.top="0px";if(!o.hmode&&isNaN(parseInt(o.root.style.right)))o.root.style.right="0px";if(!o.vmode&&isNaN(parseInt(o.root.style.bottom)))o.root.style.bottom="0px";o.minX=typeof minX!='undefined'?minX:null;o.minY=typeof minY!='undefined'?minY:null;o.maxX=typeof maxX!='undefined'?maxX:null;o.maxY=typeof maxY!='undefined'?maxY:null;o.xMapper=fXMapper?fXMapper:null;o.yMapper=fYMapper?fYMapper:null;o.root.onDragStart=new Function();o.root.onDragEnd=new Function();o.root.onDrag=new Function();},start:function(e){var o=Drag.obj=this;e=Drag.fixE(e);var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);o.root.onDragStart(x,y);o.lastMouseX=e.clientX;o.lastMouseY=e.clientY;if(o.hmode){if(o.minX!=null)o.minMouseX=e.clientX-x+o.minX;if(o.maxX!=null)o.maxMouseX=o.minMouseX+o.maxX-o.minX;}else{if(o.minX!=null)o.maxMouseX= -o.minX+e.clientX+x;if(o.maxX!=null)o.minMouseX= -o.maxX+e.clientX+x;}if(o.vmode){if(o.minY!=null)o.minMouseY=e.clientY-y+o.minY;if(o.maxY!=null)o.maxMouseY=o.minMouseY+o.maxY-o.minY;}else{if(o.minY!=null)o.maxMouseY= -o.minY+e.clientY+y;if(o.maxY!=null)o.minMouseY= -o.maxY+e.clientY+y;}document.onmousemove=Drag.drag;document.onmouseup=Drag.end;return false;},drag:function(e){e=Drag.fixE(e);var o=Drag.obj;var ey=e.clientY;var ex=e.clientX;var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);var nx,ny;if(o.minX!=null)ex=o.hmode?Math.max(ex,o.minMouseX):Math.min(ex,o.maxMouseX);if(o.maxX!=null)ex=o.hmode?Math.min(ex,o.maxMouseX):Math.max(ex,o.minMouseX);if(o.minY!=null)ey=o.vmode?Math.max(ey,o.minMouseY):Math.min(ey,o.maxMouseY);if(o.maxY!=null)ey=o.vmode?Math.min(ey,o.maxMouseY):Math.max(ey,o.minMouseY);nx=x+((ex-o.lastMouseX)*(o.hmode?1: -1));ny=y+((ey-o.lastMouseY)*(o.vmode?1: -1));if(o.xMapper)nx=o.xMapper(y);else if(o.yMapper)ny=o.yMapper(x);Drag.obj.root.style[o.hmode?"left":"right"]=nx+"px";Drag.obj.root.style[o.vmode?"top":"bottom"]=ny+"px";Drag.obj.lastMouseX=ex;Drag.obj.lastMouseY=ey;Drag.obj.root.onDrag(nx,ny);return false;},end:function(){document.onmousemove=null;document.onmouseup=null;Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode?"left":"right"]),parseInt(Drag.obj.root.style[Drag.obj.vmode?"top":"bottom"]));Drag.obj=null;},fixE:function(e){if(typeof e=='undefined')e=window.event;if(typeof e.layerX=='undefined')e.layerX=e.offsetX;if(typeof e.layerY=='undefined')e.layerY=e.offsetY;return e;}};
 
var s = new oSlider();

function oSlider(){
	var obj = this;
	this.targ = null;
	this.l_interval = null;
	this.e_interval = null;
	this.children = new Array();
	this.thumbs = new Array();
	this.current = 0;

	this.init = function(){
		var children = document.getElementById("rotator").childNodes;
		var thumbs = document.getElementById("ctrl").childNodes;
		for(var i=0; i<children.length; i++){
			if(children[i].nodeType == 1 && children[i].nodeName == "DIV") {
				this.children.push(children[i]);
				this.thumbs.push(thumbs[i]);
				children[i].onmouseover = function() {obj.stop()};
				children[i].onmouseout = function() {obj.loop()};
			}
		}
		this.l_interval = setTimeout(function() { obj.loop(); },5000 );
	};

	this.stop = function(){
		clearInterval(this.l_interval);
	};

	this.loop = function(){

		clearInterval(this.e_interval);
		this.l_interval = setTimeout(function() { obj.loop(); },5000 );

		tmp = this.current;

		this.children[this.current].style.visibility = "hidden";
		this.children[this.current].style.display = "none";

		this.thumbs[this.current].className = "off";
		if(this.current == this.children.length-1){
			this.current = 0;
		}else{
			this.current++;
		}
		this.thumbs[this.current].className = "on";
			
		//fade(this.children[this.current]);			
		//for(var i=0; i<11; i++){
		//	this.e_interval = setTimeout(bind(obj,"fade",[i]), 100*i );
		//}
		//this.children[this.current].style.removeAttribute('filter');
				
		this.children[this.current].style.visibility = "visible";
		this.children[this.current].style.display = "block";
		
		
	};

	this.slide = function(){
		
	};

	this.fade = function(value){
		this.children[this.current].style.opacity = value/10;
		this.children[this.current].style.filter = "alpha(opacity=" + value*10 + ")";
	};

	return true;
}

function bind(obj, fun, args) {
	return function() {
	if (obj === true)
		obj = this;
		var f = typeof fun === "string" ? obj[fun] : fun;
		return f.apply(obj, Array.prototype.slice.call(args || []).concat(Array.prototype.slice.call(arguments)));
	};
}

function removeFilter(element) {
	if(element.style.filter && element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}

function to_array(pseudo_array) {
    var result = [];
    for (var i = 0; i < pseudo_array.length; i++) {
        result.push(pseudo_array[i]);
    }
    return result;
}

if (!Function.prototype.bind) {
    Function.prototype.bind = function(object) {
        var method = this;
        var old_arguments = to_array(arguments).slice(1);
        return function() {
            var new_arguments = to_array(arguments);
            return method.apply(object, old_arguments.concat(new_arguments));
        };
    }
}

Array.prototype.in_array=function(obj){
	var len=this.length;
	for(var i=0;i<=len;i++){
		if(this[i]==obj)
			return true;
		}
	return false;
}

Array.prototype.index_array=function(obj){
	var len=this.length;for(var i=0;i<=len;i++){
	if(this[i]==obj)
		return i;
	}
}

function menu(){

	var menu = document.getElementById('menu').getElementsByTagName('UL')[0].getElementsByTagName('A');	

	var link = [
		'index.html',
		'about.html',
		'nasa-putovanja-i-avanture.html',
		'setnja-zagrebom-s-turistickim-vodicem.html',
		'services.html',
		'analize-media.html',
		'osnovne-analize.html',
		'slozene-analize.html',
		'sponzorske-analize.html',
		'specificne-analize.html',
		'monitoring-oglasavanja.html',
		'analize-oglasavanja.html',
		'kopije-oglasa.html',
		'istrazivanje-trzista.html',
		'vrste-istrazivanja.html',
		'metodologija.html',
		'eye-tracking-tehnologija.html',
		'intelligence-puzzle.html',
		'informacije-koje-prikupljamo.html',
		'sastavni-elementi-usluge.html',
		'glossary-a.html',
		'glossary-b.html',
		'glossary-c.html',
		'glossary-d.html',
		'glossary-e.html',
		'glossary-f.html',
		'glossary-g.html',
		'glossary-h.html',
		'glossary-i.html',
		'glossary-j.html',
		'glossary-k.html',
		'glossary-l.html',
		'glossary-m.html',
		'glossary-n.html',
		'glossary-o.html',
		'glossary-p.html',
		'glossary-q.html',
		'glossary-r.html',
		'glossary-s.html',
		'glossary-t.html',
		'glossary-u.html',
		'glossary-v.html',
		'glossary-w.html',
		'glossary-z.html',
		'contact.php'
	]
	
	var file = location.pathname.substr(location.pathname.lastIndexOf('/') + 1);

	switch(link.index_array(file)){
		case 0:
			menu[0].style.background = 'url(images/menu_hover.jpg) no-repeat 0 0';
			menu[0].style.color = '#f0f0f0';
			menu[0].style.width = 102 + 'px'
			break;
		case 1: case 2: case 3:
			menu[1].style.background = 'url(images/menu_hover.jpg) no-repeat 0 0';
			menu[1].style.color = '#f0f0f0';
			menu[1].style.width = 102 + 'px'
			break;
		case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41: case 42: case 43:
			menu[2].style.background = 'url(images/menu_hover.jpg) no-repeat 0 0';
			menu[2].style.color = '#f0f0f0';
			menu[2].style.width = 102 + 'px'
			break;
		case 44:
			menu[3].style.background = 'url(images/menu_hover.jpg) no-repeat 0 0';
			menu[3].style.color = '#f0f0f0';
			menu[3].style.width = 102 + 'px'
			break;
		default:
			break;
	}
};

function switch_tab(tab,flag,type){
	if(flag!=null){
		var header=tab.parentNode.getElementsByTagName('LI');
		for(var i=0;i<header.length;i++){
			if(header[i].className==('tab_h_active_'+type)){
				header[i].className=('tab_h_inactive_'+type);
			}
			if(header[i]==tab){
				header[i].className=('tab_h_active_'+type);
				var handler=i;
			}
		}
		var index=0;
		var content=tab.parentNode.parentNode.childNodes;
		for(var i=0;i<content.length;i++){
			if(content[i].nodeName=='DIV'){
				if(content[i].className==('tab_c_active_'+type)){
					content[i].className=('tab_c_inactive_'+type)
				}
				if(index==handler){
					content[i].className=('tab_c_active_'+type)
				}
				index++
			}
		}
	}else{
		var tabs=document.getElementById(tab).parentNode.getElementsByTagName('LI');
		for(var i=0;i<tabs.length;i++){
			if(tabs[i].className=='tab_h_active_a'){
				tabs[i].className='tab_h_inactive_a';
				document.getElementById(tabs[i].id.replace(/h/,'c')).className='tab_c_inactive_a';
			}
			if(tabs[i].id==tab){tabs[i].className='tab_h_active_a';
				document.getElementById(tabs[i].id.replace(/h/,'c')).className='tab_c_active_a';
			}
		}
	}
};

