
// New window
data_win=0;
function popup(popupurl) {
 if(!data_win||!data_win.open||data_win.closed) data_win=window.open("","data_win");
 if(data_win && data_win.open && !data_win.closed) {
   data_win.location.href=popupurl;data_win.focus();}}
   
var resizing = null;
var ie6 = 0;
var mac = (navigator.userAgent.toLowerCase().indexOf("mac")>=0);

// Prototype getElementsByClassName
function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

var SmartLighBoxGlobal = null, SmartLightBoxF = null, SmartLightBoxS = null, SmartLightBoxB = null;

// Light Boxes
function ShowLightBox(mdobj){
        if(SmartLightBoxF==null){
                SmartLighBoxGlobal = document.getElementById('SmartLightBoxMargins');
                SmartLightBoxF = document.getElementById('SmartLightBoxFix');
                SmartLightBoxS = document.getElementById('SmartLightBoxScroll');
        }
        SmartLightBoxB = document.getElementById(mdobj);
        if(ie6){
                if(getElementsByClassName(SmartLightBoxB, "DIV", "SmartLightBoxContent").length>0){
                        modcont = getElementsByClassName(SmartLightBoxB, "DIV", "SmartLightBoxContent")[0];
                        if(modcont.style.height=='')
                                modcont.className = '';
                }
        }
        ResizeLightBox();
}

function HideLightBox(){
        SmartLightBoxB.style.display = 'none';
        SmartLightBoxS.style.display = SmartLightBoxF.style.display = 'none';
        SmartLightBoxB = null;
        window.onscroll = null;
}

function ResizeLightBox(){
        if(SmartLightBoxB==null)
                return;
        SmartLightBoxB.style.display = 'none';
        SmartLightBoxF.style.width = SmartLightBoxS.style.width = '1px';
        SmartLightBoxF.style.height = SmartLightBoxS.style.height = '1px';
        SmartLightBoxF.style.width = SmartLightBoxS.style.width = parseInt(document.documentElement.scrollWidth) + 'px';
        bodyH = parseInt(document.documentElement.scrollHeight);
        if(document.all)
                windowH = parseInt(document.documentElement.clientHeight);
        else
                windowH = window.innerHeight;
        fixH = Math.max(bodyH, windowH);
        SmartLightBoxF.style.display = SmartLightBoxS.style.display = 'block';
        SmartLightBoxB.style.marginTop = 0;
        SmartLightBoxB.style.display = 'block';
        lightboxH = parseInt(SmartLightBoxB.offsetHeight);
        SmartLightBoxF.style.height = SmartLightBoxS.style.height = Math.max(fixH,lightboxH) + 'px';
        if(fixH>lightboxH){
                mrg = Math.max(0, ((windowH - lightboxH)/2)) + parseInt(document.documentElement.scrollTop);
                if((mrg+lightboxH)>fixH)
                        mrg = (fixH - lightboxH);
                SmartLightBoxB.style.marginTop = mrg + 'px';
                window.onscroll = function(e){
                        if(document.all||(mac&&(e.target.tagName=="HTML"))||!mac)
                                ResizeLightBox();
                }
        }
        else if(windowH<lightboxH){
                document.documentElement.scrollTop = 0;
                window.onscroll = null;
        }
}

// Main Page Resize
window.onresize = function(){
        ResizeLightBox();
        if(resizing==null)
                resizing = window.setTimeout("ResizeLightBox();", 10);
}

// Recipient Add Button
function smart_form_add_recipient(data) {
   document.getElementById("smart_form_"+data+"_add_recipient").style.display="none";
   document.getElementById("smart_form_"+data+"_recipient_other").style.display="block";
   return false;
}

// Expandable Menu
$(document).ready(function () {
 $(".smart_open_header").bind ("click",function (ev) {
  if ($(this).is(".smart_block_expanded")) {
   $(this).removeClass("smart_block_expanded").addClass("smart_block_expandable");
   $(this).siblings("").slideUp();
   $(this).closest("h2").next().slideUp();
   $(this).closest("h3").next().slideUp();
  }
  else {
   $(this).removeClass("smart_block_expandable").addClass("smart_block_expanded");
   $(this).siblings("").slideDown();
   $(this).closest("h2").next().slideDown();
   $(this).closest("h3").next().slideDown();
  }
 return false;
 });
});

// Image Zoom
function smart_catalogue_zoom_image(obj) {
 id=obj.href.split("/").pop();
 x=parseInt(obj.parentNode.offsetLeft)+parseInt(obj.parentNode.offsetWidth);
 y=parseInt(obj.parentNode.offsetTop)-32;
 if(!x||!y||!document.getElementById(id)) return false;
 document.getElementById(id).style.position="absolute";
 document.getElementById(id).style.left=x+"px";
 document.getElementById(id).style.top=y+"px";
 document.getElementById(id).style.display="block";
 obj.onmouseout=function() {document.getElementById(id).style.display="none";};
 obj.onclick=function(){return false;};
  return false;
}

// Form values
function smart_form_ini() {
 if(!document.getElementById("smart_form_contact") && !document.getElementById("smart_form_booking")) return false;
 currentForm=(document.getElementById("smart_form_contact"))?document.getElementById("smart_form_contact"):document.getElementById("smart_form_booking");
 for(i=0;i<currentForm.elements.length;i++) {
  if(!currentForm.elements[i].tagName||(currentForm.elements[i].tagName.toLowerCase()!="textarea" && (!currentForm.elements[i].type||currentForm.elements[i].type.toLowerCase()!="text"))) continue;
  currentForm.elements[i].onfocus=function() {if(this.value==this.defaultValue) this.value="";};
  currentForm.elements[i].onblur=function() {if(!this.value) this.value=this.defaultValue;};
 }
}

// Location Tabmenu Nav
smart_location_map_cur=false;
function smart_location_map_change(obj) {
 if(!smart_location_map_cur) smart_location_map_cur=document.getElementById("smart_location_map_street_a");
 smart_location_map_cur.setAttribute("class","");
 smart_location_map_cur.setAttribute("className","");
 document.getElementById(smart_location_map_cur.href.split("/").pop()).style.display="none";
 smart_location_map_cur=obj; 
 smart_location_map_cur.setAttribute("class","smart_location_tabmenu_actif");
 smart_location_map_cur.setAttribute("className","smart_location_tabmenu_actif");
 document.getElementById(smart_location_map_cur.href.split("/").pop()).style.display="block";
 return false;
}

// SlideShow
function smart_slideshow_view(ind) {
  if(smart_slideshow_timer) smart_slideshow_stop();
 if((!smart_slideshow_ind && !ind)||(smart_slideshow_ind && smart_slideshow_ind==ind)) return false;
 smart_slideshow_obj[smart_slideshow_ind].obj.setAttribute("class","");
 smart_slideshow_obj[smart_slideshow_ind].obj.setAttribute("className","");
 smart_slideshow_ind=ind;
 if(document.getElementById("smart_slideshow_viewer")) document.getElementById("smart_slideshow_viewer").src=smart_slideshow_obj[smart_slideshow_ind].src;
 if(document.getElementById("smart_slideshow_caption")) document.getElementById("smart_slideshow_caption").innerHTML=smart_slideshow_obj[smart_slideshow_ind].caption;
 if(document.getElementById("smart_slideshow_numbering")) document.getElementById("smart_slideshow_numbering").innerHTML=(smart_slideshow_ind+1)+"/"+smart_slideshow_obj.length;
 smart_slideshow_obj[smart_slideshow_ind].obj.setAttribute("class","smart_thumbnail_selected");
 smart_slideshow_obj[smart_slideshow_ind].obj.setAttribute("className","smart_thumbnail_selected");
 return false;
}

function smart_slideshow_move1() {
 if(!smart_slideshow_sW) smart_slideshow_sW=((smart_slideshow_obj.length-1)*111)+6;
 if(smart_slideshow_sW==Math.abs(parseInt(smart_slideshow_ul.offsetLeft))) {smart_slideshow_stop();return false;};
 smart_slideshow_ul.style.left=(parseInt(smart_slideshow_ul.style.left)-1)+"px";
}
function smart_slideshow_move0() {
 if(!parseInt(smart_slideshow_ul.offsetLeft)) {smart_slideshow_stop();return false;};
 smart_slideshow_ul.style.left=(parseInt(smart_slideshow_ul.style.left)+1)+"px";
}
function smart_slideshow_stop() {
 clearInterval(smart_slideshow_timer);smart_slideshow_timer=false;
}
smart_slideshow_timer=smart_slideshow_sW=smart_slideshow_ul=false;
function smart_slideshow_move(type,dir) {
 if(smart_slideshow_timer) {smart_slideshow_stop();smart_slideshow_ul.style.left=0;}; 
 if(type=="g") {
  ind=(dir)?smart_slideshow_ind+1:smart_slideshow_ind-1;
  if(ind<0||smart_slideshow_obj.length<=ind) return false;
  smart_slideshow_view(ind);return false;};
 for(i=0;i<document.getElementById("smart_slideshow_thumbnails").childNodes.length;i++) {
  if(!document.getElementById("smart_slideshow_thumbnails").childNodes[i].tagName||document.getElementById("smart_slideshow_thumbnails").childNodes[i].tagName.toLowerCase()!="ul") continue;
  if(!smart_slideshow_ul) {
   document.getElementById("smart_slideshow_thumbnails").childNodes[i].style.position="relative";
   document.getElementById("smart_slideshow_thumbnails").childNodes[i].style.left=0;
   smart_slideshow_ul=document.getElementById("smart_slideshow_thumbnails").childNodes[i];};
  smart_slideshow_timer=setInterval("smart_slideshow_move".concat(dir,"()"),20);
 };
}

smart_slideshow_obj=[];
smart_slideshow_ind=0;
function smart_slideshow_ini() {
 if(!document.getElementById("smart_slideshow_thumbnails")) return false;
 for(i=0;i<document.getElementById("smart_slideshow_thumbnails").childNodes.length;i++) {
  if(!document.getElementById("smart_slideshow_thumbnails").childNodes[i].tagName||document.getElementById("smart_slideshow_thumbnails").childNodes[i].tagName.toLowerCase()!="ul") continue;
  for(j=0;j<document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes.length;j++) {
   if(!document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].tagName||document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].tagName.toLowerCase()!="li") continue;
   for(k=0;k<document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes.length;k++) {
    if(!document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].tagName||(document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].tagName.toLowerCase()!="a" && document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].tagName.toLowerCase()!="span")) continue;   
    if(document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].tagName.toLowerCase()=="span") {
     smart_slideshow_obj[smart_slideshow_obj.length-1].caption=document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].innerHTML;
     continue;
    };
    K=smart_slideshow_obj.length;
    smart_slideshow_obj[K]={
     src:document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].getAttribute("href"),
     caption:"&nbsp;",
     obj:document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k]};
    document.getElementById("smart_slideshow_thumbnails").childNodes[i].childNodes[j].childNodes[k].onclick=new Function("smart_slideshow_view("+K+");return false;");
   };
  }; 
 };
}   


function ini() {
 smart_slideshow_ini();
 smart_form_ini();
 ie6 = (document.all&&(typeof document.body.style.maxHeight=="undefined")); // IE6 detection
}

window.onload=ini;
