	

	String.prototype.is_string = true;

	function $( ID ) { return document.getElementById( ID ); };

	function $$( OBJ, TAG ) {
		if( !TAG ) { TAG = OBJ; OBJ = document; }

		if( OBJ.is_string )
			OBJ	= $( OBJ );

		return OBJ.getElementsByTagName( TAG );
	};

	function El( TAG, PARAMS ) {
		if( TAG.is_string )
			var obj	= document.createElement( TAG );
		else
			obj		= TAG;

		if( PARAMS ) {
			if( PARAMS.hasOwnProperty('class') )
				obj.className	= PARAMS['class'];
			if( PARAMS.hasOwnProperty('id') )
				obj.setAttribute( 'id', PARAMS['id'] );
			if( PARAMS.hasOwnProperty('parent') ) {
				if( PARAMS['parent'].is_string )
					PARAMS['parent'] = $( PARAMS['parent'] );
				PARAMS['parent'].appendChild( obj );
			}
			if( PARAMS.hasOwnProperty('insertBefore') ) {
				if( PARAMS['insertBefore'].is_string )
					PARAMS['insertBefore'] = $( PARAMS['insertBefore'] );

				PARAMS['insertBefore'].parentNode.insertBefore( obj, PARAMS['insertBefore'] );
			}
		}

		return obj;
	};

	function Controller() {
		if( !$('products') )
			return;

		var PRODUCTS	= $$( 'products', 'li' );

		this.maxPage	= Math.ceil( PRODUCTS.length / 6 );
		this.playing	= false;
		this.curPage	= 1;

		if( this.maxPage == 1 )
			return $('control').style.display = 'none';

		$('control').onselectstart = $('control').onmousedown = function() { return false; }

		$('all-pages').firstChild.data	= this.maxPage;
		$('products').scrollTop			= 0;

		$('control-next').onclick = this.PageMove.call(this, 1);
		$('control-prev').onclick = this.PageMove.call(this, -1);

		$('control-next').style.visibility = this.curPage == this.maxPage ? 'hidden' : 'visible';
		$('control-prev').style.visibility = this.curPage == 1 ? 'hidden' : 'visible';

		if( PRODUCTS.length - 1 >= 0 )
			PRODUCTS[ PRODUCTS.length - 1 ].style.marginBottom = ( $('products').scrollHeight % 400 + 3 ) + 'px';
		else
			$('control').style.display = 'none';
	}

	Controller.prototype.PageMove	= function( DIR ) {
		var o = this, p = $('products'), cn = $('control-next'), cp = $('control-prev'), curpage = $('current-page'), MT = null;

		return function() {
			if( MT )
				MT.stop();

			if( o.curPage + DIR < 1 || o.curPage + DIR > o.maxPage )
				return false;

			o.curPage += DIR;

			curpage.firstChild.data = o.curPage;

			cn.style.visibility = o.curPage == o.maxPage ? 'hidden' : 'visible';
			cp.style.visibility = o.curPage == 1 ? 'hidden' : 'visible';

			o.playing = true;

			MT	= new Tween( p, 'scrollTop', Tween.strongEaseInOut, p.scrollTop, 400 * ( o.curPage - 1 ), .5 );
			MT.onMotionFinished	= function() { o.playing = false; }
			MT.start();

			return false;
		}
	};

	function Partners() {
		if( !$('partners') )
			return;

		var PARTNERS	= $$( 'ptrs', 'li' );

		this.maxPage	= Math.ceil( PARTNERS.length / 4 );
		this.UL			= $( 'ptrs' );
		this.playing	= false;
		this.curPage	= 1;

		$('partners').onselectstart = $('partners').onmousedown = function() { return false; }

		this.UL.scrollLeft	= 0;

		$('partners-next').onclick = this.PageMove.call(this, 1);
		$('partners-prev').onclick = this.PageMove.call(this, -1);

		$('partners-next').className	= this.curPage == this.maxPage ? 'inactive' : '';
		$('partners-prev').className	= this.curPage == 1 ? 'inactive' : '';

		PARTNERS[ PARTNERS.length - 1 ].style.marginRight = ( ( 4 - PARTNERS.length % 4 ) * ( this.UL.scrollWidth % 828 ) ) + 'px';
	};

	Partners.prototype.PageMove	= function( DIR ) {
		var o = this, p = this.UL, cn = $('partners-next'), cp = $('partners-prev'), MT = null;

		return function() {
			if( o.curPage + DIR < 1 || o.curPage + DIR > o.maxPage )
				return false;

			if( MT )
				MT.stop();

			o.curPage += DIR;

			$('partners-next').className	= o.curPage == o.maxPage ? 'inactive' : '';
			$('partners-prev').className	= o.curPage == 1 ? 'inactive' : '';

			o.playing = true;

			MT	= new Tween( p, 'scrollLeft', Tween.strongEaseInOut, p.scrollLeft, 828 * ( o.curPage - 1 ), .350 );
			MT.onMotionFinished	= function() { o.playing = false; }
			MT.start();

			return false;
		}
	};

	function HideDescriptions() {
		for( var i = 0, descs = $$('descriptions','div'); i< descs.length; i++ )
			if( descs[i].className == 'product-description' )
				descs[i].style.display = 'none';
	}

	function Fader( o ) { this.obj = o; };

	// Current time
	Fader.prototype.cTime    = function() { return new Date().getTime(); };

	Fader.prototype.startTimer    = function( secs, direction ) {
	    this.duration    = secs * 1000; // milliseconds
	    this.startTime    = this.cTime();
	    this.endTime    = this.startTime + this.duration;
	    this.fadeDir    = direction;

	    this.processTimer();
	};

	Fader.prototype.fadeOut    = function( secs ) { this.startTimer( secs, -1 ); };
	Fader.prototype.fadeIn    = function( secs ) { this.startTimer( secs, 1 ); };

	Fader.prototype.setOpacity    = function ( obj, opacity ) {
	    this.obj.style.filter    = 'alpha(opacity=' + opacity + ')';
	    this.obj.style.opacity    = opacity / 100;
	};

	Fader.prototype.processTimer    = function() {
	    var c    = ( 100 * ( this.cTime() - this.startTime ) ) / this.duration, o = this;

	    if( this.fadeDir < 0 )    c = 100 - c;

	    if( c > 100 || c < 0 ) {
	        this.setOpacity( this.obj, this.fadeDir < 0 ? 0 : 100 );

	        if( this.onFinish )
	            this.onFinish();

	        return;
	    }

	    this.setOpacity( this.obj, c );

	    window.setTimeout( function() { o.processTimer(); }, 0 );
	};

	function JustRefreshHeader( IMAGES, prices ) {
		if (!prices) 
		{
			var prices = [];
		};

		if( document.documentElement && document.documentElement.scrollTop )
			var SCOB	= document.documentElement;
		else if( document.body )
			var SCOB = document.body;

		MT	= new Tween( SCOB, 'scrollTop', Tween.strongEaseInOut, SCOB.scrollTop, $('header').offsetTop, .2 );
		MT.onMotionFinished	= function() { LoadHeader( IMAGES, prices ); }
		MT.start();
	}

	function productReview( OBJ, IMAGES, ID, prices ) {
		if (!prices) 
		{
			var prices = [];
		};



		if( document.documentElement && document.documentElement.scrollTop )
			var SCOB	= document.documentElement;
		else if( document.body )
			var SCOB = document.body;

		HideDescriptions();

		var o	= $( 'product-' + ID );
		$('descriptions').style.display = 'block';
		o.style.visibility	= 'hidden';
		o.style.display		= 'block';

		MT	= new Tween( SCOB, 'scrollTop', Tween.strongEaseInOut, SCOB.scrollTop, $('header').offsetTop, .2 );
		MT.onMotionFinished	= function() {
			o.style.visibility = 'visible';

			var IE = false;
			/*@cc_on IE = true; @*/

			if( !IE ) {
				o.style.opacity = 0;
				new Fader( o ).fadeIn( 1 );
			}
			LoadHeader( IMAGES,  prices );
		}
		MT.start();

		if( $$( o, 'div' ).length == 0 ) {
			var C	= El( 'div', { 'insertBefore': o.firstChild, 'class': 'product-thumb' } );
			var Im	= El( 'img', { 'parent': C } );
			var L	= El( 'a', { 'parent': C } );
			El( document.createTextNode( 'виж снимките' ), { 'parent': L } );
			var CL	= El( 'a', { 'insertBefore': o.firstChild, 'class': 'close' } );
			CL.setAttribute( 'href', '#' );
			CL.onclick	= function() {
				if( document.documentElement && document.documentElement.scrollTop )
					var SCOB	= document.documentElement;
				else if( document.body )
					var SCOB = document.body;

				MT	= new Tween( SCOB, 'scrollTop', Tween.strongEaseInOut, SCOB.scrollTop, $('content').offsetTop + $('content').offsetParent.offsetTop, .5 ).start();
				this.parentNode.parentNode.style.display	= 'none';
				return false;
			}
			L.onclick	= function() {
				if( document.documentElement && document.documentElement.scrollTop )
					var SCOB	= document.documentElement;
				else if( document.body )
					var SCOB = document.body;

				MT	= new Tween( SCOB, 'scrollTop', Tween.strongEaseInOut, SCOB.scrollTop, $('header').offsetTop, .2 );
				MT.onMotionFinished	= function() {
					LoadHeader( IMAGES, prices );
				}
				MT.start();
			}
			L.setAttribute( 'href', 'javascript://View Pictures' );
			Im.setAttribute( 'src', $$( OBJ.parentNode, 'img' )[0].getAttribute( 'src' ) );
		}

		return false;
	}

	function LoadHeader(HeaderImages, HeaderPrices)
	 {
	 	if (!HeaderPrices) 
	 	{
	 		var HeaderPrices = [];
	 	};

	  swfobject.embedSWF('http://www.casanuova.bg/images/swf/header.swf', 'header-inner', '950px', '380px', '9', null, { Images : HeaderImages.join(', '), Prices : HeaderPrices.join(', ') });
	 }


	function Start( HeaderImages, prices ) {
		if (!prices) 
		{
			var prices = [];
		};


		
		$('header').innerHTML = '<div id="top-header"><div id="header-inner"></div></div>';

		$$( 'menu', 'a' )[4].setAttribute( 'id', 'nodivider' );

		El( 'li', { 'parent': 'menu', 'id': 'player' } );

		swfobject.embedSWF( 'http://www.casanuova.bg/images/swf/player.swf', 'player', '96px', '49px', '9', null );
		LoadHeader( HeaderImages, prices );

		for( var i = 0, H2s	= $$( 'h2' ); i < H2s.length; i++ )
			El( 'span', { 'parent': H2s[i], 'class': 'right' } );

		for( var i = 0, IPS = $$( 'input' ); i < IPS.length; i++ ) {
			if( IPS[i].className.match( /(^| )autoerase( |$)/ ) ) {
				IPS[i].onfocus	= function() {
					if( this.value == this.defaultValue ) {
						this.style.color	= '#000000';
						this.value	= '';
					}
				}
				IPS[i].onblur	= function() {
					if( this.value == '' ) {
						this.style.color	= '#bbbbbb';
						this.value	= this.defaultValue;
					}
				}
			}
		}

		if( $('descriptions') )
			$('content').insertBefore( $('descriptions'), $('content').firstChild );

		El( 'span', { 'parent': 'footer', 'id': 'f-lb' } );
		El( 'span', { 'parent': 'footer', 'id': 'f-rb' } );

//		$('l').setAttribute( 'href', window.location.href.replace(/(\.bg\.html|\.en\.html)/,'.html').replace(/^(.+?)(\.html)$/, '$1.' + $('l').getAttribute('href') + '$2') );

		new Controller();
		new Partners();
	};


