function $( id ) {
	return document.getElementById( id ) ? document.getElementById( id ) : null;
}

function viewport() {
    this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
    this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
    this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
    this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
    this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
    this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}

function hide( id, timeout ) {

	if (timeout > 0) {
		setTimeout("hide('" + id + "')", timeout );
	} else {
		obj = $( id );
		//if (obj.style.display != 'none') {
			obj.style.display = 'none';
		//}
	}
}

var productLayer = 0;

function show( id ) {
	obj = $( id );
	obj.style.display = 'block';
	if (id.indexOf('product-layer') > -1) {
		if (productLayer && productLayer != id) {
			hide(productLayer);
		} 
		productLayer = id;
	}
}

function opacityFader( id, opacStart, opacEnd, millisec ) {

		//if id is specified as Object
    	if (typeof(id) == "object") id = id.id;
    	var obj = $(id);
    	if (obj.style.display == 'none') {
    		setOpacity( id, 0 );
    		obj.style.display = '';
    	}

		//speed for each frame
		if (!millisec) millisec = 300; //default fade time
		var fps = 50;
		var frames = fps * millisec / 1000;
    	var speed = Math.round(millisec / frames);
		var counter = Math.ceil((opacEnd - opacStart) / frames);
    	var timer = 0;

    	//determine the direction for the blending, if start and end are the same nothing happens
    	if (opacStart > opacEnd) {
        	for ( i = opacStart; i >= opacEnd; i += counter ) {
            	setTimeout("setOpacity('" + id + "', " + i + ")",(timer * speed));
            	timer++;
        	}
			if (i != opacEnd) setTimeout("setOpacity('" + id + "', " + opacEnd + ")",(timer * speed));
    	} else if (opacStart < opacEnd) {
        	for ( i = opacStart; i <= opacEnd; i += counter ) {
            	setTimeout("setOpacity('" + id + "', " + i + ")",(timer * speed));
            	timer++;
        	}
			if (i != opacEnd) setTimeout("setOpacity('" + id + "', " + opacEnd + ")",(timer * speed));
    	}

}

function setOpacity ( obj, opacity ) {

    	//if obj is specified as Object ID
    	if (typeof(obj) != "object") obj = $( obj );

		var oStyle = obj.style;
		oStyle.opacity = (opacity / 100);
		oStyle.MozOpacity = (opacity / 100);
		oStyle.KhtmlOpacity = (opacity / 100);
		oStyle.filter = "alpha(opacity=" + opacity + ")";

}

function showImage( src, txt ) {

	var show = '<img src="'+src+'" alt="Preview" />';
	if (txt) show += '<div class="text">'+txt+'</div>';
	showFloatLayer( show );
	return false;
	
}

function showFloatLayer( HTML, type ) {

	if (!type) type = 'photo';
	if (typeof(HTML) == 'object') HTML = HTML.innerHTML;
	$( type+'-layer-inner').innerHTML = HTML;
	
	var view = new viewport();
	if (view.windowY > view.pageY) {
		$( 'layer-bg').style.height = view.windowY + 'px';
	} else {
		$( 'layer-bg').style.height = view.pageY + 'px';
	}
	$( type+'-layer').style.top = 100 + view.scrollY + 'px';

	$( 'layer-bg' ).style.display = 'block';
	//opacityFader( 'layer-bg', 0, 80, 300);
	$( type+'-layer').style.display = 'block';
	

	return false;
}

function closeMe( type ) {
	$( 'layer-bg' ).style.display = 'none';
	//opacityFader( 'layer-bg', 80, 0, 300);
	//hide( 'layer-bg', 300 );
	$( type+'-layer' ).style.display = 'none';
}

function contactsForm( x ) {
	showFloatLayer(x.getText(), 'float');
}

function ajaxResponse( x ) {
	showFloatLayer(x.getText(), 'photo');
}

var faq = 0;
function showFAQ( id ) {

	
	if (faq > 0) hide( 'answer-'+faq );
	if (faq != id) $('answer-'+id).style.display = '';
	else { hide( 'answer-'+id ); faq = 0; return };
	faq = id;

}

var cfaq = 0;
function showCFAQ( id ) {

	
	/*if (cfaq > 0) hide( 'cfaq-'+cfaq );
	if (cfaq != id) $('cfaq-'+id).style.display = '';
	else { hide( 'cfaq-'+id ); cfaq = 0; return };
	cfaq = id;*/

}


function openVideo( obj ) {
	window.open( obj.href, null,  "height=355,width=430,status=yes,toolbar=no,menubar=no,location=no");
	return false;
}

function paypalResponse( x ) {
	var out = x.getText();
	var url = out.split("=");
	var go = url[1];
	if (url[0] == 'url') {
		var o = $('paypal-form-body');
		o.action = go;
		o.submit();
	} else {
		showFloatLayer(out);
	}
}

function m( n, d, s ) {

	n = n.split(',');
	var nn = '';
	for (var i = 0; i < n.length; i++) {
		nn += String.fromCharCode(n[i]);
	}
	d = d.split(',');
	var dd = '';
	for (var i = 0; i < d.length; i++) {
		dd += String.fromCharCode(d[i]);
	}
	if (s.length > 0) {
		s = s.split(',');
		var ss = '';
		for (var i = 0; i < s.length; i++) {
			ss += String.fromCharCode(s[i]);
		}
	}

	var l = '';
	l += String.fromCharCode(109);
	l += String.fromCharCode(97);
	l += String.fromCharCode(105);
	l += String.fromCharCode(108);
	l += String.fromCharCode(116);
	l += String.fromCharCode(111);
	l += String.fromCharCode(58);
	l += nn;
	l += String.fromCharCode(64);
	l += dd;
	if (s.length > 0) {
		l += String.fromCharCode(63);
		l += String.fromCharCode(115);
		l += String.fromCharCode(117);
		l += String.fromCharCode(98);
		l += String.fromCharCode(106);
		l += String.fromCharCode(101);
		l += String.fromCharCode(99);
		l += String.fromCharCode(116);
		l += String.fromCharCode(61);
		l += ss;
	}
	window.location = l;

}

