﻿var selectedName;
var locPath; //Path localizzata per le immagini dell'accordion

function rollover(name, filename)
{
  var fullpath = '../App_Themes/Valvitalia/' + filename;
  document.getElementById(name).src = fullpath;
  
  
  if(filename.indexOf('_on') > -1)
    document.getElementById(name).style.zIndex  = 1000;
  else
    document.getElementById(name).style.zIndex  = 0;
}

function clearAll(){
    divs = document.getElementsByTagName('div');
    
    for(i=0;i<divs.length;i++){
       
        if(divs[i].id.indexOf(imgPrefix)==0)
        {
             //alert(divs[i].id.indexOf(imgPrefix));
            divs[i].style.visibility = 'hidden';
        }
    }
}

function rollover2(name, filename)
{
  var fullpath = '../App_Themes/Valvitalia/' + filename;
  if ($CMSPageLanguage =='IT')
    var fullpath = '../App_Themes/IT_Valvitalia/' + filename;
  document.images[name].src = fullpath;
}

function showdiv(name)
{
    clearAll();
    hidediv();
    selectedName = name;
    document.getElementById(name + "_div").style.visibility = 'visible';
    
    if(selectedName!=null && document.getElementById(selectedName + "_link")!= null)
        document.getElementById(name + "_link").className = 'sel';
}
function hidediv()
{
    if(document.getElementById(selectedName + "_div") != null)
        document.getElementById( selectedName + "_div").style.visibility = 'hidden';
    if(document.getElementById(selectedName + "_link") != null)
        removeClass(document.getElementById(selectedName + "_link"),'sel');
    selectedName = null;
}
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

var map = null;
var geocoder = null;
function loadMap(adr) {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("GoogleMapDiv"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(45.06142692732455, 9.410187005996704), 10, G_NORMAL_MAP);	
        geocoder = new GClientGeocoder();
        }
        
     if(adr!=null)
        showAddress(adr);
}

function showAddress(address) {
    if(address=="INDIA")
        address = "Coimbatore - 641 697, India";
    if(address=="CHINA")
        address = "Cina Jiangsu Nanjing Pu Kou Qu Wu Jiang Lu";
    if(address=="HEADQUARTER")
        address = "Via Tortona, 69 27055 Rivanazzano (PV) Italy";
    if(address=="VITAS")
        address ="Via Soastene, 24 36041 Brendola (VI) Italy"
    if(address=="VSD")
        address ="Via Campolongo, 97 35020 Due Carrare (PD) Italy" 
    if(address=="TECNOFORGE")
        address ="Via Emilia Pavese, 38 29015 Castelsangiovanni (PC) Italy"
    if(address=="ARAB")
        address ="Al Jubail, Ad Dammam, Eastern Province 32253, Arabia Saudita"
    if(address=="EMIRATES")
        address ="Mussafah Industrial Area Abu Dhabi"
    if(address=="BROADY")
        address ="English Street Hull,East Yorkshire, HU3 2DU United Kingdo"
    if(address=="CANADA")
        address ="6486 Roper Road, Edmonton, T6B2N7 -  Canada"

        
    if (geocoder) {
        geocoder.getLatLng(
        address,function(point) {
           if (!point) {
              alert(address + " not found");}
           else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              
              if (address.toLowerCase().indexOf("castelgiovanni")>-1)
              {
                marker.openInfoWindowHtml("<div style=\"margin-top:5px;color:#333333;font-size:12px;text-align:left;\"><span style=\"font-weight:bold;\">Tecnoforge FITTINGS & FLANGES division<br />Castelsangiovanni Plant<br /></span><span style=\"color:#666666;font-size:11px;\">" + address + "</span>");
              }
              if (address.toLowerCase().indexOf("arena po")>-1)
              {
                marker.openInfoWindowHtml("<div style=\"margin-top:5px;color:#333333;font-size:12px;text-align:left;\"><span style=\"font-weight:bold;\">Tecnoforge FITTINGS & FLANGES division<br />Arena Po<br /></span><span style=\"color:#666666;font-size:11px;\">" + address + "</span>");
              }
         }});
   }
}

/* SLIDER ACCORDION */
var slider = function() {
    var array = []; var speed = 5; var timer = 5;
    return {
        init: function(t, c) {
            var s, ds, l, i, y;
            s = document.getElementById(t);
            ds = s.getElementsByTagName('div'); l = ds.length; i = y = 0;
            for (i = 0; i < l; i++) {
                var d, did; d = ds[i]; did = d.id;
                if (did.indexOf("header") != -1) {
                    y++; d.onclick = new Function("slider.process(this)");
                } else if (did.indexOf("content") != -1) {
                    array.push(did.replace('-content', '')); d.maxh = d.offsetHeight;
                    if (c != y) { d.style.height = '0px'; d.style.display = 'none' }
                    else { d.style.display = 'block' }
                }
            }
        },
        process: function(d) {
            var cl, i; cl = array.length; i = 0;
            for (i; i < cl; i++) {
                var s, h, c, cd, img;
                s = array[i]; h = document.getElementById(s + '-header');
                img = document.getElementById(s + '-img');
                c = s + '-content'; cd = document.getElementById(c); clearInterval(cd.timer);
                if (h == d && cd.style.display == 'none') {
                    cd.style.display = 'block'; this.islide(c, 1);

                    if ($CMSPageLanguage == 'IT')
                        locPath = '../App_Themes/IT_Valvitalia/';
                    else
                        locPath = '../App_Themes/Valvitalia/';

                    if (img.addEventListener) {
                        img.setAttribute("onmouseover", "rollover2('" + img.getAttribute("name") + "', 'close_on.png')");
                        img.setAttribute("onmouseout", "rollover2('" + img.getAttribute("name") + "', 'close.png')");
                    } else {
                        img.onmouseover = function() { this.src = locPath + 'close_on.png'; };
                        img.onmouseout = function() { this.src = locPath + 'close.png'; };
                    }
                    img.src = locPath + 'close.png';
                }
                else if (cd.style.display == 'block') {
                    this.islide(c, -1);
                    if (img.addEventListener) {
                        img.setAttribute("onmouseover", "rollover2('" + img.getAttribute("name") + "', 'readmore_on.png')");
                        img.setAttribute("onmouseout", "rollover2('" + img.getAttribute("name") + "', 'readmore.png')");
                    } else {
                        img.onmouseover = function() { this.src = locPath + 'readmore_on.png'; };
                        img.onmouseout = function() { this.src = locPath + 'readmore.png'; };
                    }
                    img.src = locPath + 'readmore.png';
                }
            }
        },
        islide: function(i, d) { var c, m; c = document.getElementById(i); m = c.maxh; c.direction = d; c.timer = setInterval("slider.slide('" + i + "')", timer) },
        slide: function(i) {
            var c, m, h, dist; c = document.getElementById(i); m = c.maxh; h = c.offsetHeight;
            dist = (c.direction == 1) ? Math.round((m - h) / speed) : Math.round(h / speed);
            if (dist <= 1) { dist = 1 }
            c.style.height = h + (dist * c.direction) + 'px';
            c.style.opacity = h / c.maxh;
            //   c.style.filter='alpha(opacity=1.00.)';

            if (h < 2 && c.direction != 1) {
                c.style.display = 'none';
                clearInterval(c.timer);
            }
            else if (h > (m - 2) && c.direction == 1) {
                clearInterval(c.timer)
            }
        }
    };
} ();

// IPAD
function writeFlash(movieLocation,flashwidth,flashheight,noflashsrc,noflashurl,myidname) {
	if (myidname) { document.write('<div id="'+myidname+'">'); }
	if ((noflashsrc) && ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) )) {
		if (noflashurl || noflashurl!="") { document.write('<a href="'+noflashurl+'" >');}
		if (noflashsrc) { document.write('<img src="'+noflashsrc+'" style="border:0px" />');}
		if (noflashurl || noflashurl!="") { document.write('</a>');}
	} else {
		document.write('<object type="application/x-shockwave-flash" width="'+flashwidth+'" height="'+flashheight+'" data="'+movieLocation+'"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+movieLocation+'" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="wmode" value="transparent" /></object>');
	}

	if (myidname) { document.write('</div>'); }
}
