var sIFRfont = { src: PATH.swf + 'themix.swf', ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16] };
var sIFRfontItalic = { src: PATH.swf + 'themix-italic.swf', ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16] };

sIFR.delayCSS = true;
sIFR.activate(sIFRfont);
sIFR.activate(sIFRfontItalic);

function onloadQueue(func) {

	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
					}
				func();
				}
			}
	}

var Base64 = {

    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=,",

    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
	 },

    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

		},

    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
	  },

    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
		}

	}

function setCookie(name_, val_, hours_) {
	if (hours_) {
		var expiration = new Date((new Date()).getTime() + hours_*3600000);
		document.cookie = name_ + "=" + val_ + "; expires=" + expiration.toGMTString() + "; path=" + '/';
		} else {
			document.cookie = name_ + "=" + val_ + "; path=" + '/';
			}
	}

function addToCmpList(id_spa) {

	var cookies = document.cookie;
	var idx = cookies.indexOf('cmplist=');
	if (idx != -1) {
		var start = idx + 8;
		var end = (cookies.indexOf(";", start) != -1) ? cookies.indexOf(";", start) : cookies.length;
		var cmplist = Base64.decode(unescape(cookies.substring(start, end)));		
		if (cmplist.length) {
			cmplist = cmplist.split(',');
			if (cmplist.indexOf(id_spa) == -1) {
				cmplist.push(id_spa);
				}
			}
		}
	if (!cmplist) {
		var cmplist = new Array;
		cmplist.push(id_spa);
		}

	cmplist = cmplist.compact();

	cmplist = Base64.encode(cmplist.join(','));

	setCookie('cmplist', cmplist, 720);

	}

function removeFromCmpList(id_spa) {

	var cookies = document.cookie;
	var idx = cookies.indexOf('cmplist=');
	if (idx != -1) {
		var start = idx + 8;
		var end = (cookies.indexOf(";", start) != -1) ? cookies.indexOf(";", start) : cookies.length;
		var cmplist = Base64.decode(unescape(cookies.substring(start, end))).split(',');
		if (cmplist.indexOf(id_spa) != -1) {
			cmplist[cmplist.indexOf(id_spa)] = null;
			}		

		cmplist = cmplist.compact();

		cmplist = Base64.encode(cmplist.join(','));

		setCookie('cmplist', cmplist, 720);

		}

	}

Effect.SmoothScroll = Class.create();

Object.extend(Object.extend(Effect.SmoothScroll.prototype, Effect.Base.prototype), {

	initialize: function(element) {
		this.element = $(element);
		var options = Object.extend({ x: 0, y: 0, mode: 'absolute'} , arguments[1] || {});
		this.start(options);
		},

	setup: function() {
		if (this.options.continuous && !this.element._ext ) {
			this.element.cleanWhitespace();
			this.element._ext = true;
			this.element.appendChild(this.element.firstChild);
			}
   
		this.originalLeft = this.element.scrollLeft;
		this.originalTop = this.element.scrollTop;

		if (this.options.mode == 'absolute') {
			this.options.x -= this.originalLeft;
			this.options.y -= this.originalTop;
			}
		},

	update: function (position) {
		this.element.scrollLeft = this.options.x * position + this.originalLeft;
		this.element.scrollTop  = this.options.y * position + this.originalTop;
		}

	});

HorizontalScroller = Class.create();

Object.extend(HorizontalScroller.prototype, {

	initialize: function (scroller, controls, options) {

		this.timer		= null;
		this.scroller   = scroller;
		this.controls	= controls;

		this.options    = Object.extend({ frequency: 0.1, step: 1, controlOpacity: 0.5 }, options || {});

		this.events =	{ mouseoverLeft: this.mouseoverLeft.bind(this),  mouseoutLeft: this.mouseoutLeft.bind(this), mouseoverRight: this.mouseoverRight.bind(this),  mouseoutRight: this.mouseoutRight.bind(this) };

		this.bindObservers(this.controls);

		},
	
	bindObservers: function (controls) {
		controls.left.observe('mouseover' ,this.events.mouseoverLeft);
		controls.left.observe('mouseout' ,this.events.mouseoutLeft);
		controls.right.observe('mouseover' ,this.events.mouseoverRight);
		controls.right.observe('mouseout' ,this.events.mouseoutRight);
		},

	mouseoverLeft: function (event) {
		this.controls.left.addClassName('hover');
		this.moveLeft();
		},

	mouseoutLeft: function (event) {
		this.controls.left.removeClassName('hover');
		this.stop();
		},

	mouseoverRight: function (event) {
		this.controls.right.addClassName('hover');
		this.moveRight();
		},

	mouseoutRight: function (event) {
		this.controls.right.removeClassName('hover');
		this.stop();
		},

	stop: function () {
		if (this.timer != null) {
			clearTimeout(this.timer);
			}
		this.controls.left.setOpacity(1);
		this.controls.right.setOpacity(1);
		this.controls.left.down().show();
		this.controls.right.down().show();
		},

	moveLeft: function () {
		this.scroller.scrollLeft -= this.options.step;
		this.controls.left.setOpacity(this.options.controlOpacity);
		this.controls.left.down().hide();
		this.timer = setTimeout(this.moveLeft.bind(this), this.options.frequency);
		},

	moveRight: function () {
		this.scroller.scrollLeft += this.options.step;
		this.controls.right.setOpacity(this.options.controlOpacity);
		this.controls.right.down().hide();
		this.timer = setTimeout(this.moveRight.bind(this), this.options.frequency);
		}

	});

function newsletter(event) {
	Event.stop(event);
	var query  = $('newsletter').serialize();
	$('newsletter').disable();
	new Effect.Fade($('newsletter'), {duration:0.5, to:0.5});
	$('newsletter-submit').hide();
	$('newsletter-wait').show();
	new Ajax.Request('abonare-newsletter', {
		parameters: query,
		onSuccess: function (transport) {
			$('newsletter-response').update(transport.responseText);
			new Effect.Appear($('newsletter'), {duration:0.5});
			$('newsletter').enable();
			$('newsletter-wait').hide();
			$('newsletter-submit').show();
			}
		});
	}

onloadQueue(function () {
	sIFR.replace(sIFRfontItalic, {
		selector: '#header #alege',
		wmode: 'transparent',
		css: { '.sIFR-root': { 'font-size':'13px', 'color': '#397e80', 'font-weight':'bold', 'font-style':'italic' }}
		});
	sIFR.replace(sIFRfont, {
		selector: '.item h1',
		wmode: 'transparent',
		css: { '.sIFR-root': { 'font-size':'22px', 'color': '#ffffff', 'font-weight':'normal' }},
		filters: {	DropShadow: { knockout: false, distance: 0.8, color: '#557677', strength: 0.4 } }
		});
	});

onloadQueue(function () {
	$$('.faded').each(function (elm) {
		Event.observe(elm, 'focus', function (event) {
			if (elm.value == elm.title) {
				elm.removeClassName('faded');
				elm.value = '';
				}
			});
		Event.observe(elm, 'blur', function (event) { 
			if ((elm.value == '') || (elm.value == elm.title)) {
				elm.addClassName('faded');
				elm.value = elm.title;
				}
			});
		});	
	});