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:''
	});
});

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');
	}
	
}