var sponsorIsOpen = false;
var sponsorTimer;

window.addEvent('domready', function(){
	
	if(activeKwickName) {
		$('kwick_' + activeKwickName).addClass('activeKwick');
	}
	
	// array of nav elements at bottom - kwicks
	var kwicks = $$("#kwicks .kwick");
	

	

	var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.Quad.easeOut});

	kwicks.each(function(kwick, i) {
		kwick.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
			kwicks.each(function(other, j) {
				if(i != j) {
					var w = other.getStyle("width").toInt();
					if(w != szSmall) o[j] = {width: [w, szSmall]};
				}
			});
			fx.start(o);
		});
	});
	
	$("kwicks").addEvent("mouseleave", function(event) {
		var o = {};
		kwicks.each(function(kwick, i) {
			o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
		});
		fx.start(o);
	})
	
	$$('#photoLinks a').each(function(a){
		a.addEvent('click', function(event) {
			e = new Event(event);
			swapImage(this.id);
			swapText(this.id);
			this.blur();
			e.stop();
		})
	});
	
	$$('a.pagLink').each(function(a){
		a.addEvent('click', function(event) {
			e = new Event(event);
			swapImage(this.id);
			swapText(this.id);
			this.blur();
			e.stop();
		})
	});
	
	$('sponsorBlock').addEvent('mouseover', function (event) {
		e = new Event(event);
		if (!sponsorIsOpen) {
			var sponsorTease = new Fx.Styles(this, {'wait':false, duration: 100});
			sponsorTease.options.transition = Fx.Transitions.linear;
			sponsorTease.start({
				'height':68
			});
			sponsorTimer = revealSponsor.delay(1250);
		}
		e.stop();
	});
	
	$('sponsorBlock').addEvent('mouseout', function (event) {
		$clear(sponsorTimer);
		if (!sponsorIsOpen) {
			var sponsorTeaseOut = new Fx.Styles(this, {'wait':false, duration: 100});
			sponsorTeaseOut.options.transition = Fx.Transitions.linear;
			sponsorTeaseOut.start({
				'height':62
			});
		}
	});
	
	$('hideSponsor').addEvent('click', function (event) {
		e = new Event(event);
		hideSponsor();
		this.blur();
		e.stop();
	});

	var p = new Preloader();
			
	$$('.photoBlock img').each(function(img){
		p.addEventOnLoad(img.src, function() {
			img.getParent().setStyle('background', 'none');
			img.setStyle('opacity', 0)
			img.setStyle('display', 'block')
			img.effect('opacity').start(0,1);
		});
		p.addToQueue(img.src);
	});
	
	$('ph_01').setStyle('display','block');
	
});

function swapImage(id) {
	var num = id.substring(3);
	if( $('pa_' + num) ) {
		$$('#photoLinks a').each(function(a){
			a.removeClass('active');
		});
		$$('.photoBlock').each(function(div){
			div.setStyle('display', 'none');
		});
		$('pa_' + num).addClass('active');
		$('ph_' + num).setStyle('display', 'block');
	}
}

function swapText(id) {
	var num = id.substring(3);
	if( $('pr_' + num) ) {
		$$('#profile p').each(function(p){
			p.removeClass('active');
		});
		$(id).addClass('active');
		$('pr_' + num).addClass('active');
	}
}

function revealSponsor(delay) {
	sponsorIsOpen = true;
	$('sponsorBlock').setStyles({
		'width':304,
		'height':216
	});
	$('sponsorContent').setStyles({
		'top':0,
		'left':0
	});
}

function hideSponsor() {
	sponsorIsOpen = false;
	$('sponsorBlock').setStyles({
		'width':128,
		'height':62
	});
	$('sponsorContent').setStyles({
		'top':-86,
		'left':-176
	});
}

/* OPERATIVE'S RANDOM NUMBER GENERATOR */

var axel = Math.random() + "";
var ord = axel * 1000000000000000000;