﻿/// <reference path="jquery-1.4.4.min.js" />
var _defaultBgImage = '';
var _defaultBgColor = '';
var _movie;
function changeSpot() {
 //change bg
 if (_defaultBgImage == '') {
  _defaultBgImage = $('#ContainerMain').css("background-image");
  _defaultBgColor = $('#ContainerMain').css("background-color");
 }
 if (arrBG[_activeSpot - 1] != '') {
  $('#ContainerMain').css('background-image', 'url(' + arrBG[_activeSpot - 1] + ')');
 }
 else {
  $('#ContainerMain').css('background-image', _defaultBgImage);
 }

 if (arrBGColor[_activeSpot - 1] != '') {
  $('#ContainerMain').css('background-color', arrBGColor[_activeSpot - 1]);
 }
 else {
  $('#ContainerMain').css('background-color', _defaultBgColor);
 }

 if ($('#MainSpot .SpotContent ul li:eq(' + (_activeSpot - 1) + ') object').length > 0) {
  eval('movie = window.document.' + $('#MainSpot .SpotContent ul li:eq(' + (_activeSpot - 1) + ') object').attr("id"));
  setTimeout("movie.Rewind()", 133);
  setTimeout("movie.Play()", 133);
 }

 $('#MainSpot .SpotContent .Pager span').attr('class', '');
 $('#MainSpot .SpotContent .Pager span:eq(' + (_activeSpot - 1) + ')').attr('class', 'Active');
 _carousel.scroll(jQuery.jcarousel.intval(_activeSpot));

 // set depending on activeSpot next prev disabled

 $('#MainSpot a#RightArrow').attr('class', '');
 $('#MainSpot a#LeftArrow').attr('class', '');

 if (_activeSpot == _len) {
  $('#MainSpot a#RightArrow').attr('class', 'DRightArrow');
 }
 else if (_activeSpot == 1) {
  $('#MainSpot a#LeftArrow').attr('class', 'DLeftArrow');
 }

 if (_autoPlay && _len > 1) {
  clearInterval(_intAutoPlay);
  _intAutoPlay = setInterval("nextScene()", arrSpotTimer[(_activeSpot - 1)]);
 }
 return false;
}

function nextScene() {
 _activeSpot = ((_activeSpot) % _len) + 1; ;
 changeSpot();
}

var _carousel, _autoPlay = 1, _intAutoPlay = 0, _activeSpot = 1, arrSpotTimer = new Array(), arrBG = new Array(), arrBGColor = new Array(), _len = 0;

function mycarousel_initCallback(carousel) {

 //load
 _len = $('#MainSpot .SpotContent ul li').length;
 _carousel = carousel;
 for (i = 0; i < _len; i++) {
  arrSpotTimer[i] = $('#MainSpot .SpotContent ul li:eq(' + i + ')').attr("t") * 1000;
  arrBG[i] = $('#MainSpot .SpotContent ul li:eq(' + i + ')').attr("bg");
  arrBGColor[i] = $('#MainSpot .SpotContent ul li:eq(' + i + ')').attr("bcolor");

  $('#MainSpot .SpotContent .Pager').append('<span></span>');

 }
 changeSpot();
 $('#MainSpot .SpotContent ul').css('visibility', 'visible');


 //functions
 $('#MainSpot .SpotContent .Pager span').bind('click', function () {
  clearInterval(_intAutoPlay);
  _autoPlay = 0;
  _activeSpot = ($(this).index() - 1 + 2);
  changeSpot();
 });

 $('#MainSpot a#RightArrow').bind('click', function () {
  clearInterval(_intAutoPlay);
  if (_activeSpot < _len) {
   _autoPlay = 0;
   nextScene();
  }
 });

 $('#MainSpot a#LeftArrow').bind('click', function () {
  clearInterval(_intAutoPlay);
  if (_activeSpot > 1) {
   _autoPlay = 0;
   _activeSpot--;
   changeSpot();
  }
 });
};


$(document).ready(function () {



 $("#MainSpot .SpotContent").jcarousel({
  scroll: 1,
  initCallback: mycarousel_initCallback,
  buttonNextHTML: null,
  buttonPrevHTML: null
 });

 $('#ActionMenu ul li a[class^="Icon"]').bind('mouseover', function () {

  if ($('span', this).length == 0) {
   $('<span class="tooltip">' + $(this).attr("title") + '</span>').hide().appendTo(this).show();
   $('span', this).animate({ marginTop: -23 });
  }

 });


 $('#ActionMenu ul li a[class^="Icon"]').bind('mouseleave', function () {
  $('span', this).remove();
 });


});


