function position2VerticalCenter(element) {
	var b = document.getElementById(element);
	if (document.body.clientHeight && b.clientHeight != document.body.clientHeight) {
		var diff = parseInt((document.body.clientHeight - b.clientHeight)/2 - 20);
		b.style.marginTop = (diff > 0 ? diff : 0) + 'px';
	} else if (window.innerHeight) {
		var diff = parseInt((window.innerHeight - b.clientHeight)/2);
		b.style.marginTop = (diff > 0 ? diff : 0) + 'px';
	}
	
	setBackground();
	positionImageAndLogo();
}

/*
function setBackground() {
        var w = screen.width;
        img = 'bgr-1600.jpg';

        if (w < 1025) {
                img = 'bgr-1024.jpg';
        } else if (w < 1281) {
                img = 'bgr-1280.jpg';
        }

        document.body.style.backgroundImage = 'url(images/home/' + img + ')';
        document.body.style.backgroundRepeat = 'no-repeat';

        var h = '';
        if (window.innerHeignt) {
                h = window.innerHeight;
        } else if (document.documentElement.clientHeight) {
                h = document.documentElement.clientHeight;
        } else {
                h = screen.height;
        }

    document.body.style.height = h + 'px';
}*/

function setBackground() {
        var w = screen.width;
        img = 'vase.jpg';

		var h = '';
        if (window.innerHeignt) {
                h = window.innerHeight;
        } else if (document.documentElement.clientHeight) {
                h = document.documentElement.clientHeight;
        } else {
                h = screen.height;
        }
        
        var imgH = 458;
        
		var x = 0; var y = 0;
        if (w < 1025) {
			x = 177; y = h - imgH - 20;
        } else if (w < 1281) {
  			x = 304; y = h - imgH - 50;
        } else {
			x = 464; y = h - imgH - 80;
        }
        
        if (y < 10) y = 10;
        
        document.body.style.backgroundImage = 'url(images/home/' + img + ')';
        document.body.style.backgroundRepeat = 'no-repeat';

        document.body.style.backgroundPosition = x + 'px ' + y + 'px';

       	document.body.style.height = h + 'px';
}
function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}

			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
	
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/*function positionImageAndLogo() {
	
	var w = screen.width;
	
	if (w < 1025) {
		document.getElementById('logo').style.left = '120px';
		document.getElementById('logo').style.top = '450px';
		document.getElementById('images').style.left = '120px';
		document.getElementById('images').style.top = '480px';
	} else if (w < 1281) {
		document.getElementById('logo').style.left = '240px';
		document.getElementById('logo').style.top = '500px';
		document.getElementById('images').style.left = '240px';
		document.getElementById('images').style.top = '530px';
    }
}*/


function positionImageAndLogo() {
	
	var pos = document.body.style.backgroundPosition.split(' ');
	
	var x = pos[0].substr(0, pos[0].length - 2);
	var y = pos[1].substr(0, pos[1].length - 2);

	var imgX = 285;
	document.getElementById('logo').style.left = (x*1 + imgX*1 + 20) + 'px';
	document.getElementById('logo').style.top = (y*1 + 45) + 'px';

	document.getElementById('images').style.left = (x*1 + imgX*1 + 20) + 'px';
	document.getElementById('images').style.top = (y*1 + 70) + 'px';

	var w = screen.width;

	
/*	if (w < 1025) {
		document.getElementById('logo').style.left = '120px';
		document.getElementById('logo').style.top = '450px';
		document.getElementById('images').style.left = '120px';
		document.getElementById('images').style.top = '480px';
	} else if (w < 1281) {
		document.getElementById('logo').style.left = '240px';
		document.getElementById('logo').style.top = '500px';
		document.getElementById('images').style.left = '240px';
		document.getElementById('images').style.top = '530px';
    } */
}
function printFavorites(id) {
	var url = 'php/print_favorites.php?UserID=' + id;
    var win = window.open(url, '_blank','width='+screen.width+',height='+screen.height+',status=yes,resizable=no,menubar=no,location=no,toolbar=no,scrollbars=yes');
    win.focus();
}

function downloadFileTechnique(p1,p2,p3,p4) {

	var url = 'php/download.php?action=technical_files&files=' + p4;
	
    var win = window.open(url, '_blank');
    win.focus();
}

function openCatalogDecoration() {
	var url = 'http://www.cristallalique.fr/e-catalogue-decoration/';
	var win = window.open(url, '_blank','width='+screen.width+',height='+screen.height+',status=yes,resizable=no,menubar=no,location=no,toolbar=no,scrollbars=no');
}

function openExhibitionSite(){
	var win = window.open("http://www.cristallalique.fr/v1/rene/", "_blank", "width=900,height=600");
	win.focus();
}

function openWindow(url,w,h){
	var opt = '';
	if(w && h) {
		opt = "width=" + w + ",height=" + h;
	}
	var win = window.open(url, "_blank", opt);
	win.focus();
}

function downloadPressPdf(id) {
	var url = 'php/download.php?action=press&id=' + id;
    var win = window.open(url, '_blank');
    win.focus();
}

function downloadPressProductFiles(id) {
	var url = 'php/download.php?action=press_high_resolution&id=' + id;
    window.location.href = url;
}

function downloadProductTechnicalFiles(id) {
	var url = 'php/download.php?action=product_technical_files&id=' + id;
    window.location.href = url;
}

function openAF() {
	var win = window.open('http://www.art-fragrance.com/', '_blank', 'width=' + screen.width + ',height=' + screen.height + ',titlebar=yes,toolbar=yes,menubar=yes,status=yes,scrollbars=yes,menubar=yes,location=yes,resizable=yes,top=0,left=0')
	win.focus();
}
