function externalLinks() {
   
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   
   for (var i=0; i<anchors.length; i++) {
     var anchor = anchors[i];
     if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
   
   }   
}

function antispam_replace(email) {
	var modified = email.replace(/%20/g, " "); // za IE
	modified = modified.replace(/ AFNA /g, "@");
	modified = modified.replace(/ PIKA /g, ".");
	return modified;
}

function antispamEmails() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anc = anchors[i];
        if ((email = anc.getAttribute("href")) && anc.getAttribute("type") == "antispam") {
			var vsebina = anc.innerHTML;
            anc.href = antispam_replace(email);
            anc.innerHTML = antispam_replace(vsebina);
        }
    }
}

function generateTitles(){
	Cufon.replace('span.title');
	Cufon.replace('h1.replaceme');
	Cufon.replace('h2.replaceme');
	Cufon.replace('p.replaceme');
	Cufon.replace('a.replaceme');
}


function onBefore() {
	if(this.id != "s7" && this.id != "s5"){
		if($('.inviteFormHolder').css("display") == "none" ){
			$('.inviteFormHolder').fadeIn('slow');
		}
	} else {
		$('.inviteFormHolder').hide();
	}

}

//raztegnitev footerja
function expandFooter() {
	var wh = getWindowHeight();
	var bh = $('body').height();
	var fh = $('#footer').height();
	var neew = wh - bh + fh;
	if(neew > 125) {
		$('#footer').height(neew);
	}	
}
 
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}


jQuery(document).ready(function() {
	externalLinks();
	antispamEmails();
	generateTitles();
	expandFooter();
	
	jQuery('#lang').hide();
	jQuery('.selectedLanguage').mouseover(function (e) {	
        jQuery('#lang').show();
	});
	
	jQuery('#lang').mouseout(function (e) {
		jQuery('#lang').hide();
		
	 });
	
	jQuery('#lang').mouseover(function (e) {	
        jQuery('#lang').show();
	});
		
	$(document).ready(function() {
		 $('#switchedContent').cycle({
				fx: 'fade',
				prev: '#prev',
				next: '#next',
				timeout: 6500,
				before: onBefore,
				pager: '#nav',
				pagerAnchorBuilder: function(idx, slide) {	        	
		    	return '<li><a href="#" class="iconSwitch"></a></li>';
		        } 
			});
	});
	
	$("#content").mousedown(function(data){		
		if($("#loginBox").is(":visible")){
			toggleLoginBox();
			toggleSelectedButton();
		}
	});
	
});