var infoTimeout
var maxopacity = 1.0;
if (browser.isIE){ maxopacity = 0.6; };
var Triplewise_rules = {

	'a' : function(el) {
		el.onfocus = function() {
			this.blur();
			if (el.getAttribute('rel') == 'external') {
				el.setAttribute('target', '_blank');
		   }
		}
	}, 

	'#showcase' : function(el) {
		el.onmouseover = function() {
			clearTimeout(infoTimeout);
			temp = Element.getOpacity('showcase_detail');
			new Effect.Opacity('showcase_detail', {duration:1.0, from:temp, to:maxopacity});	
		}
		el.onmouseout = function() {
			infoTimeout = setTimeout('new Effect.Opacity(\'showcase_detail\', {duration:1.0, from:maxopacity, to:0});', 1000);
		}
		el.onclick = function() {
			updateShowcase();
		}
	},

	'img' : function(el) {
		el.setAttribute('galleryimg', 'no');
	},

	'#t_contact' : function(el) {
		el.onclick = function() {
			if (Element.hasClassName('contact', 'c_hidden')) {
				Element.removeClassName('contact', 'c_hidden');
				new Effect.ScrollTo('t_contact', {offset: 0});
			} else {
				Element.addClassName('contact', 'c_hidden');
			}
			return false;
		}
	},
	
	'#a_cmb' : function(el) {
		el.onclick = function() {
			if (Element.hasClassName('frm_cmb', 'c_hidden')) {
				Element.removeClassName('frm_cmb', 'c_hidden');
			} else {
				Element.addClassName('frm_cmb', 'c_hidden');
			}
			return false;
		}
	}
	
	
}

Behaviour.register(Triplewise_rules);

function init() {
	Element.addClassName('contact', 'c_hidden');
	Element.addClassName('frm_cmb', 'c_hidden');
	initShowcase();
	initOverLabels();
}

Behaviour.addLoadEvent(init);

function opacity_fix() {
	objMyImg = null;
	if (document.getElementById('showcase_detail')) {
		objMyImg = new OpacityObject('showcase_detail', 'http://www.triplewise.com/_images/infobg');
		objMyImg.setBackground(); 
	}
}

Behaviour.addLoadEvent(opacity_fix); 

function adjust_height() {
	viewport = getWindowHeight();
	totalcontent =  Element.getHeight('canvas') + Element.getHeight('footer') + 60;
	if (totalcontent < viewport) {
		setcontent = 40 + (viewport - totalcontent);
		Element.setStyle('footer', {height: setcontent + 'px'});		
	}
}

Behaviour.addLoadEvent(adjust_height); 

function updateShowcase() {
	base = 'http://www.triplewise.com/_images/random/';
	oldimage = readCookie('oldimage');
	var new_url = 'http://www.triplewise.com/_random/random.php?current=' + oldimage;
	var ajax_request = new Ajax.Request(new_url, { 
		onComplete : function(t) { 
			results = t.responseText.split("|");
			Element.setOpacity('showcase', 0);
			Element.setOpacity('showcase_detail', 0);
			$('showcase_image').src = base + results[0] + '.jpg';
			new Effect.Opacity('showcase', {duration:1.0, from:0, to:1.0});	
			Element.update('showcase_detail',  '<p>' + results[1] + '</p>');
			new Effect.Opacity('showcase_detail', {duration:1.0, from:0, to:maxopacity});
			setCookie('oldimage',results[0],14);
	},
	onFailure : function() {
			$('showcase_image').src = base + 'afa' + '.jpg';
			new Effect.Opacity('showcase', {duration:1.0, from:0, to:1.0});	
			Element.update('showcase_detail',  '<p>The Amsterdam Football Academy</p>');
			new Effect.Opacity('showcase_detail', {duration:1.0, from:0, to:maxopacity});
	}});
}

function initShowcase() {
	Element.setOpacity('showcase', 0);
    Element.setOpacity('showcase_detail', 0);
	new Effect.Opacity('showcase', {duration:1.0, from:0, to:1.0});	
	new Effect.Opacity('showcase_detail', {duration:1.0, from:0, to:maxopacity});
}
