



( function( $ ) { $( function() {

  //return;

  $( '#news-overlay' ).css( 'opacity', 0 ).show();
  $( '#news' ).css( 'opacity', 0.7 ).css( 'width', 218 );
  $( '#news-contents li' ).css( 'opacity', 0 ).show().first().css( 'opacity', 1 );

  var overlayed = false;
  var onExpand  = false;
  var liHeight  = $( '#news-headers li' ).height();

  $( '#slider' )
    .bind( 'mouseenter', function() {
      $( '#news' ).animate( { opacity: 1 }, 300 );
    } )
    .bind( 'mouseleave', function() {
      $( '#news' ).animate( { opacity: 0.7 }, 300 );
      $( '#news-clip' ).animate( { width: 218 }, 500, function() {
        if( !onExpand )
          $( '#news' ).css( 'width', 218 );
      } );
      
    } );

  $( '#news' )
    .bind( 'mouseenter', function() {
      $( '#news' ).css( 'width', 690 );
      onExpand = true;
      $( '#news-clip' ).animate( { width: 690 }, 500, function() { onExpand = false } );
      $( '#news-overlay' ).animate( { opacity: 0.5 }, 300 );
      overlayed = true;
    } )
    .bind( 'mouseleave', function() {
      if( overlayed )
        $( '#news-overlay' ).animate( { opacity: 0.0 }, 300 );
    } );

  var newsItem = 0;

  $( '#news-contents li' ).hide().eq( newsItem ).show();

  $( '#news-headers li a' )
    .each( function( index ) {
      $( this ).attr( 'index', index );
    } )
    .bind( 'click', function( event ) {
      
      event.preventDefault();

      var index = $( this ).attr( 'index' );
      if( index == newsItem ) return;
      
      $( '#news-contents li' ).eq( newsItem ).animate( { opacity: 0 }, 500, function() { $( this ).hide() } );
      $( '#news-contents li' ).eq( newsItem = index ).show().animate( { opacity: 1 }, 500 );

      $( '#news-pointer' ).animate( { top: 66 + index*liHeight }, 500 );

    } );

  // ---------------------------------------------------------------------------------
  
  var easing = 'linear';
  
  function goToPromoItem()
  {
    if( promoItem >= promoItemsLength )
      promoItem = 0;
    if( promoItem < 0 )
      promoItem = promoItemsLength -1;
    $( '#promoslider .productslider-scroll' ).animate( { left: -promoItem*slideWidth }, 300, easing );
  }
  
  var promoItemsLength = $( '#promoslider .slide' ).length;
  var promoItem        = 0;
  var slideWidth       = $( '#promoslider .slide' ).width() ||
                         $( '#newslider .slide' ).width() ||
                         $( '#lightingslider .slide' ).width();
 
  $( '#promoslider .btn-prev' )
    .bind( 'click', function( event ) {
      goToPromoItem( --promoItem );
      event.preventDefault();
    } );

  $( '#promoslider .btn-next' )
    .bind( 'click', function( event ) {
      goToPromoItem( ++promoItem );
      event.preventDefault();
    } );
    
  function goToNewItem()
  {
    if( newItem >= newItemsLength )
      newItem = 0;
    if( newItem < 0 )
      newItem = newItemsLength -1;
    $( '#newslider .productslider-scroll' ).animate( { left: -newItem*slideWidth }, 300, easing );
  }
  
  var newItemsLength = $( '#newslider .slide' ).length;
  var newItem        = 0;
 
  $( '#newslider .btn-prev' )
    .bind( 'click', function( event ) {
      goToNewItem( --newItem );
      event.preventDefault();
    } );

  $( '#newslider .btn-next' )
    .bind( 'click', function( event ) {
      goToNewItem( ++newItem );
      event.preventDefault();
    } );
    
  function goToLightingItem()
  {
    if( lightingItem >= lightingItemsLength )
      lightingItem = 0;
    if( lightingItem < 0 )
      lightingItem = lightingItemsLength -1;
    $( '#lightingslider .productslider-scroll' ).animate( { left: -lightingItem*slideWidth }, 300, easing );
  }
  
  var lightingItemsLength = $( '#lightingslider .slide' ).length;
  var lightingItem        = 0;
 
  $( '#lightingslider .btn-prev' )
    .bind( 'click', function( event ) {
      goToLightingItem( --lightingItem );
      event.preventDefault();
    } );

  $( '#lightingslider .btn-next' )
    .bind( 'click', function( event ) {
      goToLightingItem( ++lightingItem );
      event.preventDefault();
    } );
    

/**
 * viva.bg MAIN javascript
 *
 * Copyright (c) 2007 Hristo Drumev [www.hdrumev.com]
 *
 * This file use Credox Framework [www.credox.org]
 */

//jQuery.noConflict();

var Viva = {};

Viva.FILE_IMAGE        = 'thumb.php';
Viva.PARAM_IMAGE_SRC   = 'src';
Viva.PARAM_IMAGE_SIZE  = 'size';

Viva.IMAGE_LOADING_100 = 'img/loading100x100.gif';
Viva.IMAGE_LOADING_300 = 'img/loading300x300.gif';

Viva.ERROR_SEARCH_BG   = 'Моля, въведете текст за търсене';
Viva.ERROR_SEARCH_EN   = 'Enter search string, please';

Viva.preloadedImages   = [];

Viva.preloadImage = function()
{
  for( var i = 0; i < arguments.length; i++ )
  {
    var no = this.preloadedImages.length;
    this.preloadedImages[no] = new Image();
    this.preloadedImages[no].src = arguments[i];
  }
}

Viva.preloadImage( Viva.IMAGE_LOADING_100, Viva.IMAGE_LOADING_300 )

Viva.changeImage = function( id, src, size, lang )
{
  var prefix = lang == 'en' ? '../' : '';

  src  = 'res/pub/' + src;
  var imageElement = document.getElementById( 'image' + id );
  if( size == 100 )
    imageElement.src = prefix + this.IMAGE_LOADING_100;
  else
    imageElement.src = prefix + this.IMAGE_LOADING_300;
  size = size == 100 ? '100x100' : '300x300';
  var imageURL = prefix + this.FILE_IMAGE                 +
                 '?' + this.PARAM_IMAGE_SRC  + '=' + src  +
                 '&' + this.PARAM_IMAGE_SIZE + '=' + size;
  imageElement.src = imageURL;
}

Viva.onSearch = function( form, lang )
{
  if( form.search.value.length < 1 )
  {
    window.alert( lang == 'bg' ? this.ERROR_SEARCH_BG : this.ERROR_SEARCH_EN );
    return false;
  }
  return true;
}

// ------------------------------------------------------------------------------------------------

/*
Viva.carousel = {};

Viva.carousel.INTERVAL        = 10000;
Viva.carousel.SCROLL_INTERVAL = 'slow';

Viva.carousel.page            = 0;
Viva.carousel.countPages      = 0;
Viva.carousel.lastPosition    = 0;
Viva.carousel.scrollWidth     = null;
Viva.carousel.timer           = null;

Viva.carousel.prev = function()
{
  Viva.carousel.page--;
  if( Viva.carousel.page < 0 )
  {
    Viva.carousel.page = Viva.carousel.countPages - 1;
    jQuery( '#carouselscroll' ).css( { left: '-' + ( Viva.carousel.page * Viva.carousel.scrollWidth ) + 'px' } );
    Viva.carousel.page = Viva.carousel.countPages - 2;
  }
  Viva.carousel.move();
}

Viva.carousel.next = function()
{
  Viva.carousel.page++;
  if( Viva.carousel.page >= Viva.carousel.countPages )
  {
    Viva.carousel.page = 1;
    jQuery( '#carouselscroll' ).css( { left: 0 } );
  }
  Viva.carousel.move();
}

Viva.carousel.move = function()
{
  jQuery( '#carouselscroll' ).animate( { left: '-' + ( Viva.carousel.page * Viva.carousel.scrollWidth ) + 'px' }, Viva.carousel.SCROLL_INTERVAL );
  if( Viva.carousel.timer )
  {
    window.clearTimeout( Viva.carousel.timer );
    Viva.carousel.timer = window.setTimeout( Viva.carousel.next, Viva.carousel.INTERVAL );
  }
}

jQuery( document ).ready( function() {
  
  // assign events
  jQuery( '#modelsthumbnails div.prev' ).click( Viva.carousel.prev );
  jQuery( '#modelsthumbnails div.next' ).click( Viva.carousel.next );
  
  // Copy first 4 items to end of the carousel
  var html = '';
  jQuery( '#carouselscroll a' ).slice( 0, 4 ).each( function() {
    html += jQuery( '<div>' ).append( jQuery( this ).clone() ).html();  
  } );
  jQuery( '#carouselscroll' ).append( html );

  Viva.carousel.scrollWidth = jQuery( '#carousel' ).width() / 4;
  Viva.carousel.countPages = parseInt( ( jQuery( '#carouselscroll a' ).length - 1 ) ) + 1 - 3;
  Viva.carousel.lastPosition = -( Viva.carousel.countPages - 1 )*Viva.carousel.scrollWidth;
  
  Viva.carousel.timer = window.setTimeout( Viva.carousel.next, Viva.carousel.INTERVAL );
  
  jQuery( '#carouselscroll a' )
    .mouseover( function() {
      this.oldhtml    = jQuery( '#newitemhelp' ).html(); 
      var title       = jQuery( this ).find( '.title' ).text(),
          description = jQuery( this ).find( '.description' ).text()
      var html = '<strong>' + title + '</strong><br />' + description;
      jQuery( '#newitemhelp > div' ).html( html );
      window.clearTimeout( Viva.carousel.timer );
    } )
    .mouseout( function() {
      jQuery( '#newitemhelp > div' ).html( this.oldhtml );
      Viva.carousel.timer = window.setTimeout( Viva.carousel.next, Viva.carousel.INTERVAL );
    } );
  
} );

*/


/***      VERSION 2 ****/
/***


Viva.carousel = {};

Viva.carousel.speedPerPixel = 8;
Viva.carousel.deadZone      = 160;
Viva.carousel.direction     = 1;

jQuery( document ).ready( function() {
  
  if( !document.getElementById( 'carouselscroll' ) )
    return;
    
  jQuery.easing.def = "linear";

  Viva.carousel.itemsCount   = jQuery( '#carouselscroll a' ).length;
  Viva.carousel.width        = jQuery( '#carousel' ).width();
  Viva.carousel.lastPosition = -( jQuery( '#carouselscroll a' ).length * jQuery( '#carouselscroll a' ).outerWidth( true ) ) + Viva.carousel.width - 3; 
  Viva.carousel.offsetX      = parseInt( jQuery( '#carousel' ).position().left );
  Viva.carousel.center       = parseInt( jQuery( '#carousel' ).width() / 2 );
  
  // Tooltips
  jQuery( '#carouselscroll a' )
    .mouseover( function() {
      this.oldhtml    = jQuery( '#newitemhelp' ).html(); 
      var title       = jQuery( this ).find( '.title' ).text(),
          description = jQuery( this ).find( '.description' ).text()
      var html = '<strong>' + title + '</strong><br />' + description;
      jQuery( '#newitemhelp > div' ).html( html );
      //window.clearTimeout( Viva.carousel.timer );
    } )
    .mouseout( function() {
      jQuery( '#newitemhelp > div' ).html( this.oldhtml );
      //Viva.carousel.timer = window.setTimeout( Viva.carousel.next, Viva.carousel.INTERVAL );
    } );

  // Motion events
  jQuery( '#carousel' ).mousemove( function( event ) {
  
    var x = event.clientX - Viva.carousel.offsetX;  
    var offset = Math.abs( Viva.carousel.center - x );
    var direction = 0;    
    if( offset > Viva.carousel.deadZone )
      direction = x > Viva.carousel.center ? 1 : -1;
    if( direction != Viva.carousel.direction )
    {
      jQuery( '#carouselscroll' ).stop();
      Viva.carousel.direction = direction;
      if( direction != 0 )
      {
        var posX = parseInt( jQuery( '#carouselscroll' ).css( 'left' ) );
        var distance = direction == 1 ? -Viva.carousel.lastPosition - posX : -posX + Viva.carousel.width;
        var speed = distance * Viva.carousel.speedPerPixel;
        if( direction == 1 )
          jQuery( '#carouselscroll' ).animate( { left: Viva.carousel.lastPosition }, speed );
        else
          jQuery( '#carouselscroll' ).animate( { left: 0 }, speed );  
      
      }   
    }
  } );

  jQuery( '#carouselscroll' ).animate( { left: Viva.carousel.lastPosition }, Viva.carousel.speedPerPixel * (-Viva.carousel.lastPosition) * 2 );

} );


*/

Viva.calculate = function()
{
  function get( id ) { return document.getElementById( id ); };
  
  var eArray = { '40': '9', '60': '11', '75': '15', '100': '20' };
  var iArray = { '40': 4, '60': 4, '75': 5, '100': 5.5 }
  
  var power  = get( 'power' ).value;
  var number = get( 'number' ).value;
  var hours  = get( 'hours' ).value;

  var equivalent   = eArray[power];
  var hoursperyear = parseInt( hours ) * 365;
  var consumption1 = parseInt( power ) * hoursperyear * parseInt( number ) * 0.18 / 1000;
  var consumption2 = consumption1 * .2;
  var save         = consumption1 - consumption2;
  var invest       = iArray[power] * number;
  
  get( 'equivalent' ).innerHTML = equivalent + ' W';
  get( 'hoursperyear' ).innerHTML = hoursperyear + ' часа';
  get( 'consumption1' ).innerHTML = consumption1.toFixed( 2 ) + ' лв.';
  get( 'consumption2' ).innerHTML = consumption2.toFixed( 2 ) + ' лв.';
  get( 'save' ).innerHTML = save.toFixed( 2 ) + ' лв.';
  get( 'invest' ).innerHTML = invest.toFixed( 2 ) + ' лв.';
}


// Tooltips
document.observe( 'dom:loaded', function() {

  if( document.getElementById( 'calculator' ) )
  {
    var elements = document.getElementById( 'calculator' ).getElementsByTagName( 'select' );
  
    for( var i = 0; i < elements.length; i++ )
    {
      var element = elements[i];
      element.onchange = Viva.calculate;
      element.onkeyup = Viva.calculate;
    }
  
    Viva.calculate();
  
  }

} );



} ) } )( jQuery.noConflict() );




( function( $ ) { $( function() {

  var $div1 = $( '#exchanger div' ).eq( 0 );
  var $div2 = $( '#exchanger div' ).eq( 1 );
  
  function show1()
  {
    $div1.fadeToggle( 'fast' );
    $div2.fadeToggle( 'fast' );
    setTimeout( show2, 5000 );
  }
  
  function show2()
  {
    $div1.fadeToggle( 'fast' );
    $div2.fadeToggle( 'fast' );
    setTimeout( show1, 8000 );
  }
  
  setTimeout( show1, 8000 );
  
  
  
  
  
  // CrossSlide
  
  if( $( '#product-movie img' ).length )
  {
    var settings = {
      fade: 1
    };
    var items = [];
    var lows  = ['0%', '20%'];
    var highs = ['80%', '100%'];
    var zooms = ['1x', '1.5x'];
    var times = [3, 4, 5, 6];
    
    $( '#product-movie img' ).each( function() {
      $this = $( this );
      var ex;
      var from1 = lows[Math.floor( 2 * Math.random() )];
      var to1   = highs[Math.floor( 2 * Math.random() )];
      if( Math.random() > 0.5 ) { ex = from1; from1 = to1; to1 = ex; }
      var from2 = lows[Math.floor( 2 * Math.random() )];
      var to2   = highs[Math.floor( 2 * Math.random() )];
      if( Math.random() > 0.5 ) { ex = from2; from2 = to2; to2 = ex; }
      items.push( {
        src:  this.src,
        alt:  this.alt,
        from: from1 + ' ' + from2 + ' ' + zooms[Math.floor( 2 * Math.random() )],
        to:   to1 + ' ' + to2 + ' ' + zooms[Math.floor( 2 * Math.random() )],
        time: times[Math.floor( 4 * Math.random() )]
      } );
    } );
    $( '#product-movie' ).empty().crossSlide( settings, items ); 
  


  }
  

} ) } )( jQuery.noConflict() );
