/*------------------------------------------------------------
	Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
	Web Site: http://txkang.com
	Script featured on Dynamic Drive (http://www.dynamicdrive.com)
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}


//____________________________________________________________________________
//                                                                            |
// SHOW/HIDE LAYER: skrije ali prikaže layer z določnemi #idjem				  |
//____________________________________________________________________________|
//

function hideLayer(whichLayer) {
if (document.getElementById) {
document.getElementById(whichLayer).style.visibility = "hidden";
}
else if (document.all) {
document.all[whichlayer].style.visibility = "hidden";
}
else if (document.layers) {
document.layers[whichLayer].visibility = "hidden";
}
}

function showLayer(whichLayer) {
if (document.getElementById) {
document.getElementById(whichLayer).style.visibility = "visible";
}
else if (document.all) {
document.all[whichlayer].style.visibility = "visible";
}
else if (document.layers) {
document.layers[whichLayer].visibility = "visible";
}
}

function handleClick(whichClick) {

if (whichClick == "hide it") {
//ta del se spreminja, sem daš id diva
hideLayer("galkobox");

}
else if (whichClick == "show it") {
//ta del se spreminja, sem daš id diva
showLayer("galkobox");
}
}


//____________________________________________________________________________
//                                                                            |
// NICE FORMS: doda :focus atribut tudi za IE, ... 							  |
// http://www.sitepoint.com/article/simple-tricks-usable-forms				  |
//____________________________________________________________________________|
//

function getLabelForId(id) {
    var label, labels = document.getElementsByTagName('label');
    for (var i = 0; (label = labels[i]); i++) {
        if (label.htmlFor == id) {
            return label;
        }
    }
    return false;
}
function checkEmail() {
    var email = document.getElementById('email');
    var label = getLabelForId('email');
    if (email.value.indexOf('@') == -1 || email == '') { // Naive check for non empty string with @ sign
        label.className = 'problem';
    } else {
        label.className = 'completed';
    }
}
function checkPhone() {
    var phone = document.getElementById('phone');
    var label = getLabelForId('phone');
    var digits = phone.value.replace(/[^0-9]/ig, '');
    if (!digits) {
        label.className = '';
        phone.value = '';
        return;
    }
    if (digits.length == 9) {
        phone.value = '(' + digits.substring(0, 3) + ') ' + 
            digits.substring(3, 6) + '-' + 
            digits.substring(6, 9);
        label.className = 'completed';
    } else {
        label.className = 'problem';
        phone.value = digits;
    }
}
function checkRequired(id) {
    var formfield = document.getElementById(id);
    var label = getLabelForId(id);
    if (formfield.value.length == 0) {
        label.className = 'problem';
    } else {
        label.className = 'completed';
    }
}

addEvent(window, 'load', function() {
    var input;
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; (input = inputs[i]); i++) {
        addEvent(input, 'focus', oninputfocus);
        addEvent(input, 'blur', oninputblur);
    }
    var textareas = document.getElementsByTagName('textarea');
    for (var i = 0; (textarea = textareas[i]); i++) {
        addEvent(textarea, 'focus', oninputfocus);
        addEvent(textarea, 'blur', oninputblur);
    }
});
function oninputfocus(e) {
    /* Cookie-cutter code to find the source of the event */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return;
    }
    /* End cookie-cutter code */
    source.style.border='1px solid #FF6600';
	source.style.background='#FFFFFF';
	
}
function oninputblur(e) {
    /* Cookie-cutter code to find the source of the event */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return;
    }
    /* End cookie-cutter code */
    source.style.border='1px solid #ccc';
	source.style.background='#F5F5F5';
}
function addEvent(obj, evType, fn){
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}

//____________________________________________________________________________
//                                                                            |
// NICE TITLE: spremeni html tage: title v div, ki se pojavi ko greš čez link |
// za izgled konfigururaš css: div.nicetitle, div.nicetitle p, ...			  |
//____________________________________________________________________________|
//

addEvent(window, "load", makeNiceTitles);

var XHTMLNS = "http://www.w3.org/1999/xhtml";
var CURRENT_NICE_TITLE;
var browser = new Browser();

function makeNiceTitles() {
    if (!document.createElement || !document.getElementsByTagName) return;
    // add namespace methods to HTML DOM; this makes the script work in both
    // HTML and XML contexts.
    if(!document.createElementNS)
    {
        document.createElementNS = function(ns,elt) {
            return document.createElement(elt);
        }
    }

    if( !document.links )
    {
        document.links = document.getElementsByTagName("a");
    }
    for (var ti=0;ti<document.links.length;ti++) {
        var lnk = document.links[ti];
        if (lnk.title) {
            lnk.setAttribute("nicetitle",lnk.title);
            lnk.removeAttribute("title");
            addEvent(lnk,"mouseover",showNiceTitle);
            addEvent(lnk,"mouseout",hideNiceTitle);
            addEvent(lnk,"focus",showNiceTitle);
            addEvent(lnk,"blur",hideNiceTitle);
        }
    }
    var instags = document.getElementsByTagName("ins");
    if (instags) {
    for (var ti=0;ti<instags.length;ti++) {
        var instag = instags[ti];
        if (instag.dateTime) {
            var strDate = instag.dateTime;
            var dtIns = new Date(strDate.substring(0,4),parseInt(strDate.substring(4,6)-1),strDate.substring(6,8),strDate.substring(9,11),strDate.substring(11,13),strDate.substring(13,15));
            instag.setAttribute("nicetitle","Added on "+dtIns.toString());
            addEvent(instag,"mouseover",showNiceTitle);
            addEvent(instag,"mouseout",hideNiceTitle);
            addEvent(instag,"focus",showNiceTitle);
            addEvent(instag,"blur",hideNiceTitle);
        }
    }
    }
}

function findPosition( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oLink.x, oLink.y ];
  }
}

function showNiceTitle(e) {
    if (CURRENT_NICE_TITLE) hideNiceTitle(CURRENT_NICE_TITLE);
    if (!document.getElementsByTagName) return;
    if (window.event && window.event.srcElement) {
        lnk = window.event.srcElement
    } else if (e && e.target) {
        lnk = e.target
    }
    if (!lnk) return;
    if (lnk.nodeType == 3) {
        // lnk is a textnode -- ascend parents until we hit a link
        lnk = getParent(lnk,"A");
    }
    if (!lnk) return;
    nicetitle = lnk.getAttribute("nicetitle");
    
    var d = document.createElementNS(XHTMLNS,"div");
    d.className = "nicetitle";
    tnt = document.createTextNode(nicetitle);
    pat = document.createElementNS(XHTMLNS,"p");
    pat.className = "titletext";
    pat.appendChild(tnt);
    d.appendChild(pat);
    if (lnk.href) {
        tnd = document.createTextNode(lnk.href);
        pad = document.createElementNS(XHTMLNS,"p");
        pad.className = "destination";
        pad.appendChild(tnd);
        d.appendChild(pad);
    }
    
    STD_WIDTH = 300;
    if (lnk.href) {
        h = lnk.href.length;
    } else { h = nicetitle.length; }
    if (nicetitle.length) {
      t = nicetitle.length;
    }
    h_pixels = h*6; t_pixels = t*10;
    
    if (h_pixels > STD_WIDTH) {
        w = h_pixels;
    } else if ((STD_WIDTH>t_pixels) && (t_pixels>h_pixels)) {
        w = t_pixels;
    } else if ((STD_WIDTH>t_pixels) && (h_pixels>t_pixels)) {
        w = h_pixels;
    } else {
        w = STD_WIDTH;
    }
        
    d.style.width = w + 'px';    

    /*
    mx = lnk.offsetLeft;
    my = lnk.offsetTop;
    */
    mpos = findPosition(lnk);
    mx = mpos[0];
    my = mpos[1];
    //xy = getMousePosition(e);
    //mx = xy[0]; my = xy[1];
    
    d.style.left = (mx+15) + 'px';
    d.style.top = (my+35) + 'px';
    if (window.innerWidth && ((mx+w) > window.innerWidth)) {
        d.style.left = (window.innerWidth - w - 25) + "px";
    }
    if (document.body.scrollWidth && ((mx+w) > document.body.scrollWidth)) {
        d.style.left = (document.body.scrollWidth - w - 25) + "px";
    }
    
    document.getElementsByTagName("body")[0].appendChild(d);
    
    CURRENT_NICE_TITLE = d;
}

function hideNiceTitle(e) {
    if (!document.getElementsByTagName) return;
    if (CURRENT_NICE_TITLE) {
        document.getElementsByTagName("body")[0].removeChild(CURRENT_NICE_TITLE);
        CURRENT_NICE_TITLE = null;
    }
}

// Add an eventListener to browsers that can do it somehow.
// Originally by the amazing Scott Andrew.
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}

function getMousePosition(event) {
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  return [x,y];
}

// Determine browser and version.

function Browser() {
// blah, browser detect, but mouse-position stuff doesn't work any other way
  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

//_____________________________________________________________________
//                                                        			   |
// LINK FADER: spreminja barvo linkom  s počasnim prehodom 			   |
// Link fading script v1.0 by Alex Griffioen @ www.justdesign.nl, 2005 |
// Feel free to use, but please leave this comment in :)			   |
// Email your improvements to: griffioen@justdesign.nl				   |
//_____________________________________________________________________|
//

//ta del se spreminja, tukaj določiš class in barvi, za a tag
var aColor = new Array();
aColor.push(new Array("linkSivaCrna", "#000000", "#999999"));
aColor.push(new Array("linkLesenaCrna", "#000000", "#D1C58F"));
aColor.push(new Array("ime classa", "#končna barva", "#začetna barva"));

// koda;
var delay		= 1;	// Fade delay in miliseconds
var stepIn		= 20;	// Steps to fade in
var stepOut		= 20;	// Steps to fade out
var aElement	= new Array();
var aInterval	= new Array();
var aLoop		= new Array("R", "G", "B");

function init() {
	var aAnchor = document.getElementsByTagName("a");
	for(var i = 0; i < aColor.length; i++) {
		var className	= aColor[i][0];
		var aRgbOver	= getRgb(aColor[i][1]);
		var aRgbOut		= getRgb(aColor[i][2]);

		for(var j = 0; j < aAnchor.length; j++) {
			if(aAnchor[j].className == className) {
				aAnchor[j].style.color	= aColor[i][2];
				aAnchor[j].setAttribute("linkId", j);
				aAnchor[j].setAttribute("colorOver", aColor[i][1]);
				aAnchor[j].setAttribute("colorOut", aColor[i][2]);
				
				for(var k = 0; k < 3; k++) {
					aAnchor[j].setAttribute("colorOver" + aLoop[k], aRgbOver[aLoop[k]]);
					aAnchor[j].setAttribute("colorOut" + aLoop[k], aRgbOut[aLoop[k]]);
					aAnchor[j].setAttribute("changeIn" + aLoop[k], Math.floor((aRgbOver[aLoop[k]] - aRgbOut[aLoop[k]]) / stepIn));
					aAnchor[j].setAttribute("changeOut" + aLoop[k], Math.floor((aRgbOut[aLoop[k]] - aRgbOver[aLoop[k]]) / stepOut));
				}
				
				aAnchor[j].onmouseover	= linkOver;
				aAnchor[j].onmouseout	= linkOut;
			}
			aInterval.push(null);
		}
	}
}

function getHexFromCssRgb(rgb) {
	var reHex		= new RegExp("^rgb\\(([0-9]{1,3}), ([0-9]{1,3}), ([0-9]{1,3})\\)$", "i");
	var aValue		= reHex.exec(rgb);
	return "#" + getHex(aValue[1]) + getHex(aValue[2]) + getHex(aValue[3]);
}

function getRgb(hex) {
	var reHex		= new RegExp("^#([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})$", "i");
	var aValue		= reHex.exec(hex);
	var aRgb		= new Array(3);
	aRgb["R"]		= parseInt(aValue[1], 16);
	aRgb["G"]		= parseInt(aValue[2], 16);
	aRgb["B"]		= parseInt(aValue[3], 16);
	return aRgb;
}

function getHex(rgbValue) {
	rgbValue		= parseInt(rgbValue);
	var hexValue	= new String("0" + rgbValue.toString(16));
	hexValue		= hexValue.substring(hexValue.length - 2, hexValue.length);
	return hexValue.toUpperCase();
}

function linkOver() {
	var linkId	= this.getAttribute("linkId");
	if(aInterval[linkId] != null) window.clearInterval(aInterval[linkId]);
	aInterval[linkId] = window.setInterval("fade(" + linkId + ", " + this.getAttribute("changeInR") + ", " + this.getAttribute("changeInG") + ", " + this.getAttribute("changeInB") + ")", delay);
}

function linkOut() {
	var linkId	= this.getAttribute("linkId");
	if(aInterval[linkId] != null) window.clearInterval(aInterval[linkId]);
	aInterval[linkId] = window.setInterval("fade(" + linkId + ", " + this.getAttribute("changeOutR") + ", " + this.getAttribute("changeOutG") + ", " + this.getAttribute("changeOutB") + ")", delay);
}

function fade(linkId, changeR, changeG, changeB) {
	var element	= document.getElementsByTagName("a")[linkId];
	var color	= (element.style.color.indexOf("#") == -1) ? getHexFromCssRgb(element.style.color) : element.style.color;
	var aRgb	= getRgb(color);
	var hex		= "#";
		
	for(i = 0; i < 3; i++) {
		var change			= eval("change" + aLoop[i]);
		var newValue		= aRgb[aLoop[i]] + change;
		var colorOverValue	= element.getAttribute("colorOver" + aLoop[i]);
		var colorOutValue	= element.getAttribute("colorOut" + aLoop[i]);
	
		if(change > 0) {
			var toValue		= Math.max(colorOverValue, colorOutValue);
			var newValue	= (newValue > toValue) ? toValue : newValue;
		} else {
			var toValue		= Math.min(colorOverValue, colorOutValue);
			var newValue	= (newValue < toValue) ? toValue : newValue;
		}
		hex += getHex(newValue);
	}
	element.style.color = hex;

	if(hex == element.getAttribute("colorOver") || hex == element.getAttribute("colorOut")) {
		window.clearInterval(aInterval[linkId]);
		aInterval[linkId] = null;
	}
}

//__________________________________________________________________________
//                                                                          |
// SMOOTH SCROLLING: za 'smooth' scrolanje med linki z anchor tagom 		|
// http://www.sitepoint.com/article/scroll-smoothly-javascript				|
//__________________________________________________________________________|
//

// set vars
var ss_INTERVAL;
var ss_STEPS = 15;

function ss_fixAllLinks()
	{
	// grab all the links
	var allLinks = document.getElementsByTagName('a');
	
	// loop through all the links
	for (var i=0; i<allLinks.length; i++)
		{
		var lnk = allLinks[i];
		
		// check to see if there's a hash, and if the current url completely matches the one in the link
		if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search))
			{
			addEvent(lnk, 'click', smoothScroll);
			}
		}
	}

function smoothScroll(e)
	{
	var target;
	// checks with event model to use
	if (window.event)
		{
		// ie
		target = window.event.srcElement;
		}
	else if (e)
		{
		// other
		target = e.target;
		}
	else return;
	
	// strip off the hash
	var anchor = target.hash.substr(1);
	// grab all the anchors on the page
	var destinationLink = document.getElementById(anchor);
	// if none found, exit
	if (!destinationLink) return true;
	
	// find position of destination link
	var destx = destinationLink.offsetLeft; 
	var desty = destinationLink.offsetTop;
	var thisNode = destinationLink;
	// loop up through offsetParent until we hit the document body, as IE requires
	while (thisNode.offsetParent && (thisNode.offsetParent != document.body))
		{
		thisNode = thisNode.offsetParent;
		destx += thisNode.offsetLeft;
		desty += thisNode.offsetTop;
		}
	
	// clear the interval timer (why here?)
	clearInterval(ss_INTERVAL);
	
	// get current y-position
	var cypos = ss_getCurrentYPos();
	
	// calculate the step sizes
	var ss_stepsize = parseInt((desty-cypos)/ss_STEPS);
	
	// run the scroll
	ss_INTERVAL = setInterval('ss_scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
	
	// stop the browser handling the event as normal and opening the link
	// kills the bubble
	if (window.event)
		{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		}
	if (e && e.preventDefault && e.stopPropagation)
		{
		// hmmm, safari gets inside here, but then fails to stop the event, and so a 'jump' rather than a 'scroll' takes place. I can't figure it out...
		e.preventDefault();
		e.stopPropagation();
		}
	return true;
	}

function ss_scrollWindow(scramount, dest, anchor)
	{
	var wascypos = ss_getCurrentYPos();
	var isAbove = (wascypos < dest);
	window.scrollTo(0,wascypos + scramount);
	var iscypos = ss_getCurrentYPos();
	var isAboveNow = (iscypos < dest);
	// if finished cancel timer and jump anchor so url is correct
	if ((isAbove != isAboveNow) || (wascypos == iscypos))
		{
		window.scrollTo(0,dest);
		clearInterval(ss_INTERVAL);
		location.hash = anchor;
		}
	}

function ss_getCurrentYPos()
	{
	// ie5 and ie5.5
	if (document.body && document.body.scrollTop)
	return document.body.scrollTop;
	// ie6
	if (document.documentElement && document.documentElement.scrollTop)
	return document.documentElement.scrollTop;
	// netscape etc
	if (window.pageYOffset)
	return window.pageYOffset;
	return 0;
	}
