/* ANTISPAM emaili */
function antispam_emails() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        if ((email = anchor.getAttribute("href")) && anchor.getAttribute("type") == "antispam") {
			var vsebina = anchor.innerHTML;
            // replacamo vsebino in link
            anchor.href = antispam_replace(email);
            anchor.innerHTML = antispam_replace(vsebina);
        }
    }
}
   
    // funkcija za replace [AFNA] in [PIKA]
    function antispam_replace(email) {
        var modified = email.replace(/%20/g, " "); // za IE
        modified = modified.replace(/ AFNA /g, "@");
        modified = modified.replace(/ PIKA /g, ".");
        return modified;
    }
    

/* Portfolio popup */
function popImage(src)  
{  
    var html = '<html><head>'+  
                 '<script type="text/javascript">function fitPic(){'+  
                 'var iHeight=(document.all)?49:51;var iWidth=(document.all)?11:8;'+  
                 'window.resizeTo(document.images[0].width+iWidth,document.images[0].height+iHeight);self.focus();}</script>'+  
                 '</head><body onclick="javascript:window.close();" style="margin:0;overflow:auto">'+  
                 '<img onload="fitPic()" src="'+src+'" border="0" /></body></html>';  
    win = window.open('','PopImg','width=200,height=200,location=no,resizable=no,scrollbars=no');  
    win.document.open();  
    win.document.write(html);  
    win.document.close(); 
};

var backgroundSet = false;
function show_top_background() {
	
	var documentHeight = jQuery(document).height();
	var mejnik = 1245 + 550; // spodnji + zgornji BG height
	
	if(documentHeight > mejnik && !backgroundSet) {
	
		jQuery("#bg_holder").css("background-image", "url('/wp-content/themes/morphix3.0/_img/bg_world_top.png')");
		backgroundSet = true; // da ga ne nastavimo 2x
	
	}
	
}

// da je footer vedno na dnu
function footerFix() {

	var footerClear = jQuery("#footer_clear");
	footerClear.css("padding-top", 0);
	
	var documentHeight = jQuery(document).height();
	var footer = jQuery("#footer");
	var footerBottom = parseInt(footer.offset().top) + parseInt(footer.height());
	var diff = 178;
	var marginTop = documentHeight - footerBottom - diff;
	
	// pomaknemo navzdol
	if(marginTop > 0) {
		
		footerClear.css("padding-top", marginTop + "px");
		
	}

}

function doOnLoad() {
	
	show_top_background();
	footerFix();
	
}

/* onLoad */
jQuery(document).ready(function() {

	doOnLoad();
	antispam_emails();
				
				
});

// po nalaganju slik poklicemo se 1x
onload = doOnLoad;

// pri resizanju okna treba ponovno popraviti footer
onresize = footerFix;