var expressInstall = 'expressInstall.swf';
var params = { menu: 'false', wmode: 'transparent', scale: 'noorder', allowScriptAccess: 'always' };
var flashVars = {}

function slideSwitch() {
  var $active = $('#bn-banner-top img.c-active');
  if($active.length == 0) $active=$('#bn-banner-top img:last');
  var $next= $active.next().length?$active.next():$('#bn-banner-top img:first');
  //uncomment the 3 lines below to pull the images in random order
  //var $sibs = $active.siblings();
  //var rndNum = Math.floor(Math.random()*$sibs.length);
  //var $next = $($sibs[rndNum]);
  $active.addClass('c-active-last');
  $next.css({ opacity:0.0 })
    .addClass('c-active')
    .animate({ opacity:1.0 }, 1000, function() {
      $active.removeClass('c-active c-active-last');
    });
}

function pageMain() {
  //$('body').css('background', '#48afe2');
  fixMenu();
  fixTables();
  setInterval('slideSwitch()', 5000);
  initFontSizeSwitch();
  var $fontSize = $.cookie('fontSize');
  switch($fontSize) {
    case '1':
      $('#bn-ssw-small').click();
      break;
    case '2':
      $('#bn-ssw-medium').click();
    case '3':
      $('#bn-ssw-large').click();
      break;
  }
}

function initFontSizeSwitch() {

  $('#bn-ssw-small').click(function(e) {
    e.preventDefault();
    setFontSize('');
    $(this).addClass('c-active');
    $.cookie('fontSize', '1', { expires: 1 });
  });

  $('#bn-ssw-medium').click(function(e) {
    e.preventDefault();
    setFontSize('c-fs-2');
    $(this).addClass('c-active');
    $.cookie('fontSize', '2', { expires: 1 });
  });

  $('#bn-ssw-large').click(function(e) {
    e.preventDefault();
    setFontSize('c-fs-3');
    $(this).addClass('c-active');
    $.cookie('fontSize', '3', { expires: 1 });
  });

}

function setFontSize(size) {
  $('#bn-ssw a').removeClass('c-active');
  $('body').attr('class', size);
}

function fixMenu() {
  $('#bn-menu-left .c-active:first').prev().css('border-bottom', 'none');
}

function fixNewsBlock() {
  $('.c-news .c-image').siblings().css('padding-left', '160px');
  $('.c-news .c-image').parent().css('min-height', '145px');
}

function fixTables() {
  $('.c-table tr:last-child').addClass('c-last');
  $('.c-table tr td:first-child').addClass('c-first');
  $('.c-table tr td:last-child').addClass('c-last');
}

function initGallery() {
	$('div.content').css('display', 'block');
	var onMouseOutOpacity = 0.67;
	$('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity:   onMouseOutOpacity,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	var gallery = $('#thumbs').galleriffic({
		delay:                     2500,
		numThumbs:                 6,
		preloadAhead:              6,
		enableTopPager:            false,
		enableBottomPager:         false,
		maxPagesToShow:            7,
		imageContainerSel:         '#slideshow',
		controlsContainerSel:      '',
		captionContainerSel:       '',
		loadingContainerSel:       '#loading',
		renderSSControls:          false,
		renderNavControls:         true,
		playLinkText:              '',
		pauseLinkText:             '',
		prevLinkText:              '',
		nextLinkText:              '',
		nextPageLinkText:          'Nākamā',
		prevPageLinkText:          'Iepriekšējā',
		enableHistory:             false,
		autoStart:                 false,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onPageTransitionOut:       function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:        function() {
			this.fadeTo('fast', 1.0);
		}
	});
  gallery.find('a.c-prev').click(function(e) {
    e.preventDefault();
    gallery.previousPage();
  });
  gallery.find('a.c-next').click(function(e) {
    e.preventDefault();
    gallery.nextPage();
  }); 
}
