var s = screen,
	w = window,
    d = document,
    gebi = function() { return d.getElementById(arguments[0]); };
var pis = new Array();
var preload = new Function("var i = arguments.length; while (i--){ pis[i] = d.createElement('img'); pis[i].setAttribute('src',arguments[i]); };");
	preload('/favicon.ico','/favicon.png','/css/cssimg/footer.png','/css/cssimg/footer.gif');

var comment_preview = function() {
    if (!gebi('comment_form')) return;
    var labela = d.createElement('label');
	    labela.setAttribute('title', ' What your post will look like... ');
	    labela.appendChild(d.createTextNode('preview:'));

	var ime = d.createElement('a');
	    ime.setAttribute('href', '#');
	    ime.setAttribute('id', 'namePrev');
	    ime.appendChild(d.createTextNode('Somebody'));

	var p = d.createElement('p');

	var div1 = d.createElement('div');
	    div1.setAttribute('id', 'commPrev');
		div1.appendChild(d.createTextNode('You are '));
		div1.appendChild(ime);
		div1.appendChild(d.createTextNode(', and you are saying:'));
		div1.appendChild(p);

	var mjesto = gebi('comment_form').getElementsByTagName('textarea')[0].nextSibling.nextSibling; // dva BR-a!
	mjesto.parentNode.insertBefore(div1,mjesto.nextSibling);
	mjesto.parentNode.insertBefore(labela,mjesto.nextSibling);

	function update_author() {
		gebi('namePrev').firstChild.nodeValue = gebi('author').value.replace(/(\n|\r)/g, '<br />').replace(/(<br \/>){2,}/gi, '</p><p>');
	}
    function update_url() {
        gebi('namePrev').setAttribute('href', 'http://' + gebi('url').value.replace('http://', ''));
    }
    function update_comment() {
        gebi('commPrev').childNodes[3].innerHTML = gebi('comment').value.replace(/(\n|\r)/g, '<br />').replace(/(<br \/>){2,}/gi, '</p><p>');
    }

    if (gebi('author').value != '') { update_author(); }
    if (gebi('url').value != '') { update_url(); }
    if (gebi('comment').value != '') { update_comment(); }
    gebi('comment').onfocus = function() { update_author(); update_url(); update_comment(); }
    gebi('author').onblur = function() { update_author(); update_url(); }
    gebi('author').onchange = function() { update_author(); }
    gebi('url').onchange = function() { update_url(); }
    gebi('comment').onkeyup = function() { update_comment(); }
};

var show_hide_comment_policy = function() {
    if (!gebi('comment_notices')) return;

    var dt, dts = gebi('comment_notices').getElementsByTagName('dt'),
        dd, dds = gebi('comment_notices').getElementsByTagName('dd'),
        ct,
        j = dds.length,
        i = dts.length;

    while (j--) {
        dd = dds[j];
        dd.className = 'hidden';
    };

    while (i--) {
        dt = dts[i];
        dt.className = 'trigger';
        ct = dt.getElementsByTagName('a')[0];
        ct.appendChild(d.createTextNode(' [open]'));
        ct.onclick = function() {
            var dt = this.parentNode,
                dd = dt.nextSibling,
                tx = this.lastChild;
            while(dd.nodeType != 1) {
				dd = dd.nextSibling;
			};
			if (dt.nextSibling.nodeName.toLowerCase == 'dt') {
				return;
		    };
		    dd.className = dd.className == 'hidden' ? 'shown' : 'hidden';
            dt.className = dd.className == 'hidden' ? 'trigger' : 'trigger opened';
            tx.nodeValue = dd.className == 'hidden' ? ' [open]' : ' [close]';
            return false;
        };
    };
};

// SMOOTHSCROLL
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
    } else if (obj.attachEvent) {
		var r = obj.attachEvent('on'+evType, fn);
		return r;
	} else {
		return false;
    }
}

var ss_INTERVAL;
var ss_STEPS = 15;

function ss_fixAllLinks() {
	var allLinks = d.getElementsByTagName('a'),
	    i = allLinks.length;
	while (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.className != 'ic') && (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)
	{
	// checks with event model to use
	if (w.event)
		{
		// ie
		var target = w.event.srcElement;
		}
	else if (e)
		{
		// other
		var target = e.target;
		}
	else return;

	// strip off the hash
	var anchor = target.hash.substr(1);
	// grab all the anchors on the page
	var destinationLink = $(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 != d.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 (w.event)
		{
		w.event.cancelBubble = true;
		w.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();
		}
	}

function ss_scrollWindow(scramount, dest, anchor)
	{
	var wascypos = ss_getCurrentYPos();
	var isAbove = (wascypos < dest);
	w.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))
		{
		w.scrollTo(0,dest);
		clearInterval(ss_INTERVAL);
		location.hash = anchor;
		}
	}

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

w.onload = function() {
    if (!d.createTextNode || !d.getElementById) return;
    // ss_fixAllLinks();
	w.defaultStatus=' maratz.com | blog ';
}
w.onmouseout = function() {
	w.defaultStatus=' maratz.com | blog ';
}








