var timerId;

$(document).ready(function () {
	$('#lightBoxFlash1').lightBoxFlash(getFlashData('#lightBoxFlash1'));
	$('#lightBoxFlash2').lightBoxFlash(getFlashData('#lightBoxFlash2'));
	$('#lightBoxFlash3').lightBoxFlash(getFlashData('#lightBoxFlash3'));
	$('a.lightbox').lightBox({
		imageLoading: GLOBAL_PATH + '/_img/_common/lightbox-ico-loading.gif',
		txtImage:'',
		txtOf:'/',
		txtTitle:''
	});

        menu = new mainMenu();
        menu.init();

//        languages = new toggleLanguagesMenu();
//        languages.init();
});

//function toggleLanguagesMenu() {
//    this.languagesSelector = $('#menu_dropdown li.submenu');
//    _thisTLM = this;
//}
//
//toggleLanguagesMenu.prototype = {
//    init: function() {
//		_thisTLM.languagesSelector.bind('mouseenter', _thisTLM.showLanguages);
//        _thisTLM.languagesSelector.bind('mouseleave', _thisTLM.hideLanguages);
//    },
//
//    hideLanguages: function(event) {
//		$(event.currentTarget).find('ul.menu').hide();
//    },
//
//    showLanguages: function(event) {
//		$(event.currentTarget).find('ul.menu').show();
//    }
//}

function startHideShowText() {
	
	$('.to-show').hide();
	$('.click-to-show').html('... <a href="javascript:;" title="more" class="more">&nbsp;</a>');
	$('.click-to-hide').html('<a href="javascript:;" title="more" class="less">&nbsp;</a>');
	
	$('.click-to-show').click(function (ev) {
		
		var element = ev.currentTarget;
		var $li = $(element).parents('li.program-item');
		$li.find('.click-to-show').empty();
		$li.find('.to-show').show();
		
	});
	
	$('.click-to-hide').click(function (ev) {
		
		var element = ev.currentTarget;
		var $li = $(element).parents('li.program-item');
		$li.find('.click-to-show').html('... <a href="javascript:;" title="more" class="more">&nbsp;</a>');
		$li.find('.to-show').hide();
		
	});
	
}

function showParticipants(choosenLetter) {
	if (choosenLetter) {
		$('.participantsList, .participantsListEmpty').hide();
		$('#participantsList' + choosenLetter).show();
	} else {
		$('.participantsListEmpty').hide();
		$('.participantsList').show();
	} 
}


function getFlashData(selector) {
	if ($(selector).length == 0) 
		return {}
	
	var strData = $(selector).attr('href');
	if (strData.search('flashData=') == -1) 
		return {}

	var arrData = strData.split('flashData=');
	var obj = eval('('+ arrData[1] +')');
	var conf =  {
		callBack: function () {
			try {
				stopAnimation();
			} catch (e) {}
			loadFlashLayer(obj[0], obj[1], obj[2], obj[3], obj[4], obj[5], 1000);
		},
		onClose: function () {
			try {
				startAnimation();
			} catch (e) {}
		},
		imageLoading: GLOBAL_PATH + '/_img/_common/lightbox-ico-loading.gif',
		imageBtnPrev: GLOBAL_PATH + '/_img/_common/lightbox-blank.gif',
		imageBtnNext: GLOBAL_PATH + '/_img/_common/lightbox-blank.gif',
		imageBtnClose: GLOBAL_PATH + '/_img/_common/lightbox-btn-close.gif',
		imageBlank: GLOBAL_PATH + '/_img/_common/lightbox-blank.gif'
	}
	
	return conf;
}

function loadFlashLayer(path, title, width, height, scale, bgcolor, time) {

	if (!time) time = 2000;
	if (!bgcolor) bgcolor = "";

	function loadFlash() {
		//$('#jquery-lightbox').unbind('click');
		var so = new SWFObject(path, title, width, height, "8", bgcolor);
		so.addParam("align", "middle");
		so.addParam("allowfullscreen", "true");
		so.addParam("allowscriptaccess", "always");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.addVariable("autoplay", 1);
		if (scale) {
			so.addParam("scale", scale);
		}
		so.write("lightbox-container-image");
	}
	
	clearTimeout(timerId);
	timerId = setTimeout(loadFlash, time);
}

function toggleText(element, toShow, className) {
	$(toShow).toggle();
	$(element).toggleClass(className);
}

var imageWall = {
	selected: 0,
	show: function (n) {
		
		if (!n) {
			n = 0;
		}
		
		$('ul.image-list').hide();
		var element = $('.image-list')[n];
		$(element).show();
		
		this.selected = n;
		
		this.setSelected();
	},
	
	getTotal: function () {
		return $('.image-list').length;
	},
	
	prev: function () {
		var n = this.selected - 1;
		if (n < 0) {
			n = this.getTotal() - 1;
		}
		this.show(n);
	},
	
	next: function () {
		var n = this.selected + 1;
		if (n > (this.getTotal() - 1)) {
			n = 0;
		}
		this.show(n);
	},
	
	setSelected: function () {
		var n = this.selected + 1;
		$('ul.pagination > li > a').removeClass('selected');
		$($($('ul.pagination > li > a')[n])).addClass('selected');
	}
	
};

mainMenu = function(){
    this.menu = $('#yearNavigation');
    _this = this;
}

mainMenu.prototype = {
    init: function() {
        if (!_this.hasSelected())
            _this.selectFirst();

        //_this.addEvents();
        _this.fixSelectedLine();
    },

    addEvents: function() {
        this.menu.find(' dt a').bind('click', _this.showTab);
    },

    fixSelectedLine: function() {
        if ($('.mainNavigation li a.selected').parent().next().length > 0) {
            $('.mainNavigation li a.selected').parent().addClass('line');
            $('.mainNavigation li a.selected').parent().prev().addClass('line');
        } else {
            $('.mainNavigation li a.selected').parent().prev().addClass('line');
		}
    },

    getSelected: function() {
        return this.menu.find(' dt a.selected');
    },

    hasSelected: function() {
        if (_this.getSelected().length > 0)
            return true;

        return false;
    },

    hideSelected: function() {
        _this.getSelected().parent().next().addClass('hide');
        _this.getSelected().removeClass('selected');
    },

    selectFirst: function() {
        var selected = _this.menu.find(' dt:first');
        selected.find('a').addClass('selected');
        selected.next().removeClass('hide');
    },

    showTab: function(element) {
        _this.hideSelected();
        var currentElement = $(element.currentTarget);
        currentElement.addClass('selected');
        currentElement.parent().next().removeClass('hide');
        return false;
    }
}