setDefault('activeport', 1);
setDefault('activecal', 1);

function activateportfolio(caller) {
	var whichport = caller.getAttribute('href').substring(caller.getAttribute('href').lastIndexOf('_') + 1, caller.getAttribute('href').indexOf('.',caller.getAttribute('href').lastIndexOf('_')));
	
	if (whichport != activeport) {
		if (caller.getAttribute('href').indexOf('.html') == -1) {
			$('loaderphoto').innerHTML = '<img src="' + caller.getAttribute('href') + '" alt="" />';
			$('mainphoto').innerHTML = $('loaderphoto').innerHTML;
		} else {
			new Ajax.Updater('mainphoto', caller.getAttribute('href'), {method: 'get', asynchronous: true, evalScripts: true});
		}
		
		var aa = $('switcher').getElementsByTagName('a');
		
		for (var a = 0; a < aa.length; a++) {
			var aport = aa[a].getAttribute('href').substring(aa[a].getAttribute('href').lastIndexOf('_') + 1, aa[a].getAttribute('href').indexOf('.',aa[a].getAttribute('href').lastIndexOf('_')));
			if (aport == activeport) {
				var ii = aa[a].getElementsByTagName('img');
				if (ii.length == 1) {
					ii[0].src = '/images/common/project_inactive.gif';
				}
			} else if (aport == whichport) {
				var ii = aa[a].getElementsByTagName('img');
				if (ii.length == 1) {
					ii[0].src = '/images/common/project_active.gif';
				}
			}
		}
		activeport = whichport;
	}
	return false;
}

function prevportfolio(caller) {
	var whichport = parseInt(activeport) - 1;
	var aa = $('switcher').getElementsByTagName('a');
	
	for (var a = 0; a < aa.length; a++) {
		var aport = aa[a].getAttribute('href').substring(aa[a].getAttribute('href').lastIndexOf('_') + 1, aa[a].getAttribute('href').indexOf('.',aa[a].getAttribute('href').lastIndexOf('_')));
		if (aport == whichport) {
			activateportfolio(aa[a]);
			return;
		}
	}
	
	activateportfolio(aa[aa.length - 1]);
	return;
}

function nextportfolio(caller) {
	var whichport = parseInt(activeport) + 1;
	var aa = $('switcher').getElementsByTagName('a');
	
	for (var a = 0; a < aa.length; a++) {
		var aport = aa[a].getAttribute('href').substring(aa[a].getAttribute('href').lastIndexOf('_') + 1, aa[a].getAttribute('href').indexOf('.',aa[a].getAttribute('href').lastIndexOf('_')));
		if (aport == whichport) {
			activateportfolio(aa[a]);
			return;
		}
	}
	
	activateportfolio(aa[0]);
	return;
}

function swapphoto(t) {
	if ($('mainphoto')) {
		$('mainphoto').src = t;
	}
}

function activatetrademark(name, industry, image, caller) {
	$('trademark_loaderphoto').innerHTML = '<img src="../images/projects/trademarks/'+ image + '" alt="" />';
	$('trademark_photo').innerHTML = $('trademark_loaderphoto').innerHTML;
	$('trademark_client').innerHTML = new String(name);
	$('trademark_industry').innerHTML = industry;
	if (activeport == 1) {
		$('text').getElementsByTagName('a')[0].className = '';
	} else {
		activeport.className = '';
	}
	caller.className = 'active';
	activeport = caller;
}

function opencal(caller) {
	if (activecal != caller) {
		new Ajax.Updater('calendar_detail', caller.getAttribute('href'), {method: 'get', asynchronous: true, evalScripts: true});
		if (activecal == 1) {
			setClass($('calendarlist').getElementsByTagName('a')[0], '', 'active');
		} else {
			setClass(activecal, '', 'active');
		}
		setClass(caller, 'active', '');
		activecal = caller;
	}
}

function openpub(url, type) {
	switch (type) {
		case 'reason':
			newwin = window.open(url,'reason','width=600,scrollbars=yes,toolbar=no,menubar=yes,location=no,resizable=yes');
			newwin.focus();
			break;
		case 'choices':
			var newwin = window.open(url,'choices','width=654,scrollbars=yes,toolbar=no,menubar=yes,location=no,resizable=yes');
			newwin.focus();
			break;
	}
}

var newwindow = '';

function popitup(url) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','height=200,width=150');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}
