// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// $('.selector').datepicker('option', 'monthNamesShort', ['Jan','Feb','Mar','Apr','Maj','Jun','Jul','Aug','Sep','Okt','Nov','Dec']);
// 
// $('.selector').datepicker('option', 'monthNames', ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre']);
function scrollTo(url, speed, easing, redirect){
	url = url || "#";
	speed = speed || "fast";
	easing = easing || null;
	redirect = (redirect === true || redirect == null) ? true : false;
	if(url){
		if(url.indexOf("#") != -1){
			var aParts = url.split("#",2);
			var anchor = $("a[name='"+aParts[1]+"']");
			if(anchor){
				if($(document).height()-anchor.offset().top >= $(window).height()
					|| anchor.offset().top > $(window).height()
					|| $(document).width()-anchor.offset().left >= $(window).width()
					|| anchor.offset().left > $(window).width()){
							$('html, body').animate({
								scrollTop: anchor.offset().top,
								scrollLeft: anchor.offset().left
							}, speed, easing, function(){
										if(redirect){
											window.location = url
										}
									});
				}
				return false;
			}
		}
	}
}
//<![CDATA[//>
sfHover = function() {
	if (!document.getElementsByTagName) return false;
	var sfEls = document.getElementById("menu").getElementsByTagName("li");

	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//<!]]>

function checkAll(name)
{
    boxes = document.getElementsByName(name)
    for (i = 0; i < boxes.length; i++)
        boxes[i].checked = true ;
}

function uncheckAll(name)
{
    boxes = document.getElementsByName(name)
    for (i = 0; i < boxes.length; i++)
        boxes[i].checked = false ;
}
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 startGallery() {
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );
};

window.onload = externalLinks;

