(function(){
	
    EYE.main = function() {
		Cufon.replace('ul#leftNav li a, ul#rightNav li a', {hover: true, fontFamily: "ArialNarrow"});
		Cufon.replace('div.leftBoxMedium h3, div.leftBoxSmall h3, div.rightBox h3', {fontFamily: "ArialNarrow"});
    };
    EYE.register(EYE.main);

	EYE.homepageSlider = function() {
		var el,
			slides,
			indicators,
			current = -1,
			timer,
			stoped = false,
			duration = 5000;
		var goTo = function(slide) {
			clearTimeout(timer);
			if (current > -1) {
				slides.eq(current).stop()
					.animate({
						left: 408
					}, 500);
				indicators.eq(current).removeClass('selected');
			}
			current = slide;
			slides.eq(current).stop()
				.animate({
					left: 0
				}, 800);
			indicators.eq(current).addClass('selected');
			timer = setTimeout(goNext, duration);
		};
		var goNext = function() {
			var nextSlide = current + 1;
			if (nextSlide >= slides.size()) {
				nextSlide = 0;
			}
			goTo(nextSlide);
		};
		var stop = function() {
			clearTimeout(timer);
			stoped = true;
		};
		var start = function() {
			stoped = false;
			timer = setTimeout(goNext, duration);
		};
		return {
			init: function() {
				if ((el = $('#hotNews')).size() == 1) {
					el.bind('mouseenter', stop).bind('mouseleave', start);
					slides = el.find('a.hotNewsItemPhoto').appendTo('#hotNewsMainImg');
					indicators = el.find('div.hotNewsItem');
					goTo(0);
				}
			}
		};
	}();
    EYE.register(EYE.homepageSlider.init);

	EYE.programma = function() {
		var el, els;
		var click = function() {
			var indx = els.index(this);
			var tabs = el.find('div.program');
			if (tabs.size() > indx) {
				tabs.removeClass('active').eq(indx).addClass('active');
				els.removeClass('active').eq(indx).addClass('active');
				return false;
			}
		};
		return {
			init: function() {
				if ((el = $('#programContent')).size() == 1) {
					els = el.parent().find('ul:first a').bind('click', click);
				}
			}
		};
	}();
    EYE.register(EYE.programma.init);

	EYE.seats = function(sel) {
		var el, tooltipEl, timer;
		var showTooltip = function(sel) {
			stopTimer();
			tooltipEl.stop().css({
				display: 'none',
				width: 'auto'
			});
			var rel = parseInt(sel.attr('rel'), 10);
			if (EYE.seatholders[rel]) {
				$('#tooltipLeft')
					.html(tmpl('seat_tmpl', EYE.seatholders[rel]));
					var tooltipWidth = Math.min(tooltipEl.outerWidth(), 250);
					var offset = sel.offset();
					var top = offset.top + sel.outerHeight();
					var left = offset.left + sel.outerWidth()/2;
					tooltipEl.stop().css({
						width: tooltipWidth,
						top: top + 10,
						left: left + 1 - tooltipWidth/2,
						opacity: 0,
						display: 'block'
					}).animate({
						top: top,
						opacity: 1
					}, 300);
			}
		};
		var hideTooltip = function() {
			tooltipEl.stop().animate(
				{
					top: '+=10',
					opacity: 0
				},
				300,
				hideTooltipEnd
			);
		};
		var hideTooltipEnd = function() {
			this.style.display = 'none';
		};
		var enter = function() {
			showTooltip($(this).addClass('hover'));
		};
		var leave = function() {
			$(this).removeClass('hover');
			startTimer();
		};
		var stopTimer = function() {
			clearTimeout(timer);
		};
		var startTimer = function() {
			timer = setTimeout(hideTooltip, 300);
		}
		return {
			init: function() {
				if ((el = $('#seatholders')).size() == 1) {
					tooltipEl = $('#tooltip')
									.bind('mouseenter', stopTimer)
									.bind('mouseleave', startTimer);
					el.find('li').bind('mouseenter', enter).bind('mouseleave', leave);
				}
			}
		};
	}();
    EYE.register(EYE.seats.init);

	EYE.sponsors = function() {
		var el, max, elsize = 115, current= 0, dir = -1;
		var goNext = function() {
			current += dir;
			if (current < 0) {
				dir = 1;
				current = 1;
			} else if (current > max) {
				dir = -1;
				current = max - 1;
			}
			$(el).animate({left: -current * elsize}, 300);
			setTimeout(goNext, 2500);
		};
		return {
			init: function() {
				el = $('#footerLogosWrapper>div:first');
				var subs = el.find('a');
				if (subs.size() > 7) {
					max = subs.size() - 7;
					goNext();
				}
			}
		};
	}();
    EYE.register(EYE.sponsors.init);

	EYE.live = function() {
		var reLoad = function() {
			window.location.reload();
		};
		return {
			init: function() {
				if (EYE.liveTrans) {
					setTimeout(reLoad, 60000);
				}
			}
		};
	}();
    EYE.register(EYE.live.init);
    
})();

// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
  var cache = {};

  this.tmpl = function tmpl(str, data){
    // Figure out if we're getting a template, or if we need to
    // load the template - and be sure to cache the result.
    var fn = !/\W/.test(str) ?
      cache[str] = cache[str] ||
        tmpl(document.getElementById(str).innerHTML) :

      // Generate a reusable function that will serve as a template
      // generator (and which will be cached).
      new Function("obj",
        "var p=[],print=function(){p.push.apply(p,arguments);};" +

        // Introduce the data as local variables using with(){}
        "with(obj){p.push('" +

        // Convert the template into pure JavaScript
        str
          .replace(/[\r\t\n]/g, " ")
          .split("<%").join("\t")
          .replace(/((^|%>)[^\t]*)'/g, "$1\r")
          .replace(/\t=(.*?)%>/g, "',$1,'")
          .split("\t").join("');")
          .split("%>").join("p.push('")
          .split("\r").join("\\'")
      + "');}return p.join('');");

    // Provide some basic currying to the user
    return data ? fn( data ) : fn;
  };
})();

$(document).ready(function(){
	
	$('.mceEYEGalleryPart a > img').parent().addClass('pirobox');
	
	if(typeof($().piroBox) != "undefined"){
		$().piroBox({
				my_speed: 400, //animation speed
				bg_alpha: 0.1, //background opacity
				slideShow : true, // true == slideshow on, false == slideshow off
				slideSpeed : 4, //slideshow duration in seconds(3 to 6 Recommended)
				close_all : '.piro_close,.piro_overlay'// add class .piro_overlay(with comma)if you want overlay click close piroBox
	 
		});
	}
});
