// Abilitazione effetti
var enableEffects = false

// Variabili per determinare il player
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;

var lastElement;

// Va' all'indice
function toIndex(){
    window.location="/";
}

function openpresentazione() {
    dimx=1034;
    dimy=775;
    dimx+=10;
    dimy+=10;
    var xMax = screen.width;
    var yMax = screen.height;
    var xOffset = /*(xMax / 2) - (dimx / 2)*/ 20;
    var yOffset = /*(yMax  / 2) - (dimy / 2)*/ 20;
    opzioni="scrollbars=yes,toolbar=no,width="+dimx+",height="+dimy+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",scrollbars=no,status=no,menubar=no";
    fin=window.open("/docs/presentazione-sinfon-style","",opzioni);
}

// Apertura di uno screenshot
function openscreenshot(url, w, h) {
   w += 4;
   h += 4;
   var l = Math.floor((screen.width-w) / 2);
   var t = Math.floor((screen.height-h) / 2);
      window.open("/php/foto.php?url=/images/screenshots/big/" + url,"","width=" + w
          + ",height=" + h + ",top=" + t + ",left=" + l);
}

function getFlashCode(name) {
    alert('a')
	return;
}

function showFlash(flashMovieName) {
        $('hdiv-homepage-video').innerHTML = getFlashCode(flashMovieName)
}

// Un menù viene cliccato!
function doLink(e) {
    Event.stop(e);
    lastElement = Event.element(e);
    if (lastElement.href.indexOf('?') > 0) {
        flashMovieName = lastElement.href.replace(/.*\?/i, "")
        showFlash(flashMovieName)

	    // Potrebbe essere uno strong...
	    if (!lastElement.href) {
	        lastElement = $(lastElement).up();
	        if (!lastElement.href) {
	            lastElement = $(lastElement).up();
	            if (!lastElement.href) {
	                lastElement = $(lastElement).up();
	            }
	        }
	    }

	    var links = $$('#left-panel ul li a');
	    for (var i = 0; i < links.length; i++) {
	        if (links[i] == lastElement) {
	            links[i].addClassName('current');
	        } else {
	            links[i].removeClassName('current');
	        }
	    }
	    if (enableEffects) {
	        var effect = new Effect.Opacity('right-panel', { duration: 0.2,
	            from: 1,
	            to: 0.5,
	            afterFinish: ajaxAfter });
	    } else {
	        ajaxAfter();
	    }
	}
}

function ajaxAfter() {
    Element.update('right-panel', '<em>Caricamento in corso...</em>')
    var updater = new Ajax.Updater($('right-panel'),
            lastElement.href + '&ajax', {evalScripts: true, onComplete: showAfterAjax});
}

function showAfterAjax() {
    if (enableEffects) {
        new Effect.Opacity('right-panel', {from: 0.5, to: 1, duration: 0.2});
    }
}

// Flash Plugin Detect
function detectFP() {
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion,
        requiredMinorVersion, requiredRevision);
    if (!hasReqestedVersion) {
        var alternateContent = '<p><small>Questo sito richiede <strong>Adobe Flash Player</strong></small></p><a href=http://www.adobe.com/go/getflash/>'
            + '<img style="margin-right: 20px;" src="/images/getPlayer.gif" title="Scarica Adobe Flash Player"'
            + ' alt="Scarica Adobe Flash Player"/></a>';
        if ($('getFP')) Element.update('getFP', alternateContent);
    }
}

function getFlashCode(name) {
    return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1000" height="400" id="loader" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent"/><param name="movie" value="/flash/videohome/' + name + '.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#0d0d0f" /><embed src="/flash/videohome/' + name + '.swf" quality="high" bgcolor="#0d0d0f" width="1000" height="400" name="loader" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
}

function showFlash(flashMovieName) {
        $('hdiv-homepage-video').innerHTML = getFlashCode(flashMovieName)
}

function doLinkVideo(e) {
    Event.stop(e)
    var videos = $$('#pb-productslider .pb-productimage a')
    lastElement = Event.element(e)
    if (lastElement.href.indexOf('?') > 0) {
        flashMovieName = lastElement.href.replace(/.*\?/i, "")
        showFlash(flashMovieName)
    }
}

function detectSlogan() {
	if ($('header-slogan')) {
		$('header-slogan').appear({ duration: 1.2 })
	}
}

// Binding degli eventi.
function bindEvents(e) {
	var videos = $$('#pb-productslider .pb-productimage a')
	for (var i = 0; i < videos.length; i++) {
		if (videos[i].href.match(/video.*/) || videos[i].href.match(/corporate/)) {
    	    Event.observe(videos[i], 'click', doLinkVideo);
		}
    }
    var links = $$('#left-panel ul li a.ajax');
    for (var i = 0; i < links.length; i++) {
        Event.observe(links[i], 'click', doLink);
    }
    detectFP();
    detectSlogan();
    if ($('form-feedback')) initFeedbackForm()




if ($("pb-productslidertrack")) {
if ($('productbrowser')) {
		 		$('productbrowser').style.overflow = 'hidden'; //Overflow auto fix for IE8
		 	}
			AC.ProductBrowser.init({
				categories: [
					{ id: 'pb-cat1', offset: 0 },
		 			{ id: 'pb-cat2', offset: 0.304 },
					{ id: 'pb-cat3', offset: 0.609 },
					{ id: 'pb-cat4', offset: 1.000 }
				],
				imageOverlap: 0,
				sliderCentering: 218,
				initialCategory: 0,
				arrowScrollAmount: 0.38,
				iPhoneCategories: [
					{ id: 'pb-cat1', offset: 0.0 },
					{ id: 'pb-cat2', offset: 0.304 },
					{ id: 'pb-cat3', offset: 0.5 },
					{ id: 'pb-cat4', offset: 1 }
				],
				iPhoneScrollAmount: 0.295,
				iPhoneContainerWidth: 840
			});

}
}

function brochure() {
    dimx=950;
    dimy=750;
    dimx+=10;
    dimy+=10;
    var xMax = screen.width;
    var yMax = screen.height;
    var xOffset = (xMax / 2) - (dimx / 2);
    var yOffset = (yMax  / 2) - (dimy / 2);
    opzioni="scrollbars=no,toolbar=no,width="+dimx+",height="+dimy+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",scrollbars=no,status=no,menubar=no";
    fin=window.open("/docs/brochure","",opzioni);
}


// Fine del caricamento della pagina.
Event.observe(window, 'load', bindEvents);
