var flashvars = {};
var params = {
  wmode: "transparent"
};
var attributes = {};
// swfobject.embedSWF("swf/file.swf", "fl_replace", "100%", "100%", "8.0.0","swf/expressInstall.swf", flashvars, params, attributes);

Cufon.replace('#expandable-box h1, #content-box h1, .content-navigation ul li a' );

/**
 * BACKGROUND IMAGE ROTATION
 */
var rotate_background_img = function() {
  if ($('#holder .background img').size() == 1 && $('#holder .background img:first').is(':visible')) {
    return;
  }

  $('#holder .background img').hide();

  if ($('#bg_image_id').size() != 0 && $('#bg_image_id').val() != '') {
    $('#' + $('#bg_image_id').val()).fadeIn(500);
  }
  else {
    $('#holder .background img:first').fadeIn(500);
  } 
}

$(document).ready(function() {
  $('a.lightbox').lightBox({
    fixedNavigation: false,
    imageLoading: 'static_files/images/lightbox-ico-loading.gif',
    imageBtnClose: 'static_files/images/lightbox-btn-close.gif',
    imageBtnPrev: 'static_files/images/lightbox-btn-prev.gif',
    imageBtnNext: 'static_files/images/lightbox-btn-next.gif',
    imageBlank: 'static_files/images/lightbox-blank.gif'
  });

  $(".collapse").toggle(
    function() {
      $(".expandable-box-inner").slideUp();
      $(".expander", this).text("Expand").css("background-position", "right -11px");
    }, 
    function() {
      $(".expandable-box-inner").slideDown();
      $(".expander", this).text("Collapse").css("background-position", "right 4px");
    }
  );
  
  lastBlock = $(".expanded");
  maxWidth = 320;
  minWidth = 160;

  $('#so li').hover(function() {
    $(this).css({margin: 0, width: '156px', height: '76px'});
    //$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
    //$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
    //lastBlock = this;
  }, function() {
    $(this).css({margin: '3px', width: '150px', height: '70px'});
  });

  var pos = Math.floor($("#footer").position().top);
  if(pos+$("#footer").height()<$(window).height()) {
    $("#footer").height($(window).height() - pos - 1);
  }
  
  // for switcher
  var closer = false;

  $(".content-box .inner-box:first").show().addClass("exp");

  $('.content-navigation ul li a').click(function() {
    $(this).parent().parent().find('li.active').removeClass('active');
    $(this).parent().addClass('active');

    var $url = $(this).attr('href');

    $('.content-holder').fadeOut(250, function() {
      $('.content-box .ajax-loader').fadeIn(250, function() {
        if (closer == true) {
          closer = false;
          $('.closer').animate({"left":"860px"});
          $('.content-box').animate({"width":"645px"});
          $('.closer').css("background-position", "top right");
        }

        $.post($url, function(data) {
          $('.content-holder').html(data);
          
          $('.content-box .ajax-loader').hide(); 
          $('.content-holder, .nexter').fadeIn(250, function() {
            $('.content-holder .scroll-pane').jScrollPane();
          });

          rotate_background_img();
          Cufon.refresh();
          $('a.lightbox').lightBox({
            fixedNavigation: false,
            imageLoading: 'static_files/images/lightbox-ico-loading.gif',
            imageBtnClose: 'static_files/images/lightbox-btn-close.gif',
            imageBtnPrev: 'static_files/images/lightbox-btn-prev.gif',
            imageBtnNext: 'static_files/images/lightbox-btn-next.gif',
            imageBlank: 'static_files/images/lightbox-blank.gif'
          });
        });
      });
    });
    return false;
  });


  if (!window.location.pathname.match('/form/') && $('#page_level').val() == 0) {
    $('.content-navigation ul li:first a').trigger('click');
  }
  else {
    $('.content-box .ajax-loader').hide(); 
    $('.content-holder, .nexter').fadeIn(250, function() {
      $('.content-holder .scroll-pane').jScrollPane();
    });
    rotate_background_img();
  }


  $('.nexter').click(function() {
    if ($('.content-navigation ul li.active').size() == 0) {
      var active_item = false;
    }
    else {
      var active_item = $('.content-navigation ul li.active');
    }

    if (active_item == false) {
      var next_item = $('.content-navigation ul li:first');
    }
    else {
      var next_item = $(active_item).next();

      if ($(next_item).size() == 0) {
        var next_item = $('.content-navigation ul li:first');
      }
    }
    
    $(next_item).find('> a').trigger('click');
  });

  $(".closer").click(function() {
    if(closer) {
      closer = false;
      $(this).animate({"left":"860px"});
      $(".content-box").animate({"width":"645px"});
      $(this).css("background-position", "top right");
      $(".content-holder, .nexter").fadeIn();
    } else {
      closer = true;
      $(this).animate({"left":"240px"});
      $(".content-box").animate({"width":"0px"});
      $(this).css("background-position", "bottom right");
      $(".content-holder, .nexter").fadeOut();
    }
  });

  /**
   * FISHEYE EFFECT FOR TOP NAVIGATION
   */
  $('#top_navigation').Fisheye({
    maxWidth: 10,
    items: 'a',
    itemsText: 'span',
    container: '.top-nav-container',
    itemWidth: 75,
    proximity: 90,
    halign : 'center'
  });

  /**
   * JSCROLLPANE
   */

  $('.scroll-pane').jScrollPane();
});

