

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 noSpam() {
    var a = document.getElementsByTagName("a");
    for (var i = a.length-1; i >= 0; i--) {
      if (a[i].className.search(/\bemail\b/) != -1) {
        var email = a[i].firstChild.data + "@" + a[i].lastChild.data;
        a[i].innerHTML = email;
        a[i].href = "mailto:" + email;
      }
    }
}

function openPopup(){
  window.open("","_popup","toolbars=0,location=0,width=750,height=550");
  return true;
}

// Init

window.onload = function()
{
    
    externalLinks();
    noSpam();
    if($('#main').height()+100 > 500) { 
    $('#underlay').height($('#main').height()+100);
    }
    
    
    $("*[goto]").click(function() {
      $(document).attr("location", "/"+$(this).attr("goto")); 
    });
   
    
};

$(document).ready(function(e) {
	 $("div.sl_gal").each(function() { 
	 
	 		var process = false, 
				gl = $(this), 
				step = 497; 
				csl = Math.ceil(gl.find("li").size() / 4), 
				start_pos= parseInt($("ul", gl).css("left")), 
				end_pos = parseInt($("ul", gl).css("left")) + -((csl*step)-step); 
			
			$("ul", gl).width(csl*step);
			
			function update_buttons() { 
					cur = parseInt($("ul", gl).css("left"));  
					if(cur+step<=start_pos) { gl.find(".pv").addClass("active");  } else { gl.find(".pv").removeClass("active");  }   
					if(cur-step>=end_pos) { gl.find(".nx").addClass("active");  } else { gl.find(".nx").removeClass("active");  }
			}
			
			update_buttons();

			
			gl.find(".pv").click(function() { 
				if($(this).hasClass("active") && process == false) { 
					process = true; $("ul", gl).animate({"left": (parseInt($("ul", gl).css("left"))+step) + "px" }, 300, function() { update_buttons(); process = false; });				
				} 				
			}); 
			
			gl.find(".nx").click(function() { 
				if($(this).hasClass("active") && process == false) { 
					process = true;	$("ul", gl).animate({"left": (parseInt($("ul", gl).css("left"))-step) + "px" }, 300, function() { update_buttons(); process = false; });				
				}
			});
 
	 });   	
}); 

