
var pullTabY = 0;
function doPullTab() {
	new Effect.Move('shade', { x: 0, y: pullTabY, mode: 'absolute', duration: 0.5 });
	pullTabY = (pullTabY == 0) ? -93 : 0;
	setTimeout("$('pull-tab').className = $('pull-tab').className ? '':'closeme'",500);
}

var my_glider;
var gliderLastclicked = 0;
var glideInterval = -1;

function initGlider(id) {
	my_glider = new Glider(id, {duration:1.0});
	autoGlide();
}

function autoGlide() {
	glideInterval = setInterval('scrollnext()',10000);
}

function stopGlide() {
	clearInterval(glideInterval);
	//autoGlide();
	return false;
}

function scrollimg(id) {
	if ((my_glider.current == null && id == 0) || (my_glider.current != null && my_glider.current._index == id)) { return; }

	my_glider.goTo(id);
	$('hdg'+(gliderLastclicked+1)).fade();
	$('hdg'+(id+1)).appear();
	$('navlink'+(gliderLastclicked+1)).removeClassName('active');
	$('navlink'+(id+1)).addClassName('active');
	$('read-more-link').href = $('section'+(id+1)).down().href;
	gliderLastclicked = id;
	return false;
}

function scrollnext() {
	var id = (gliderLastclicked+1)%7;
	scrollimg(id);
	return false;
}

function scrollprev() {
	var id = gliderLastclicked-1;
	if (id < 0) {
		id = 6;
	}
	scrollimg(id);
	return false;
}

function toggleLingo(obj) {
	var tab = $(obj).up('li');
	tab.toggleClassName('open');
	return false;
}

function jumperOff(obj) {
	var index = (obj.current) ? $(obj.current).id.split('-')[1] : 1;
	$('jumper-'+index).removeClassName('carousel-selected');
}

function jumperOn(obj) {
	var index = $(obj.current).id.split('-')[1];
	$('jumper-'+index).addClassName('carousel-selected');
}

function carouselTogglePrevNext(obj) {
	if (obj.current._index == 0) {
		$('link-prev').addClassName('hidden');
	}
	else {
		$('link-prev').removeClassName('hidden');
	}
	if (obj.current._index == (obj.slides.length - 1)) {
		$('link-next').addClassName('hidden');
	}
	else {
		$('link-next').removeClassName('hidden');
	}
}

function doPortTab(grp,srt) {
	$('whyhired').update(snippets[grp]);
	$('projects').className=grp;
	if(srt){
		$('sorts').className=srt;
		$('portfolio').className=srt;
		track('PORTSORT',srt);
	}
	track('PORTGROUP',grp);
	return false;
}

function track(key,value)
{
	setCookie(key, value);
}

function doCGTab(obj,id,cls) {
	var sibs = $(obj.parentNode).siblings();
	for (var i = 0; i < sibs.length; i++) {
		Element.removeClassName(sibs[i],'active');
	}
	Element.addClassName($(obj.parentNode),'active');

	if(cls) {
		$(id).className = cls;
		obj.blur();
	}
	
	if(id == 'portfolio') {
		var sibs = $('show-all').siblings();
			for (var i = 0; i < sibs.length; i++) {
			Element.removeClassName(sibs[i],'active');
		}
		$('show-all').className = 'active';
		$('projects').className = 'everything';
	}
	return false;
}

function doThumb(obj,id,path) {
	var sibs = $(obj.parentNode).siblings();
	for (var i = 0; i < sibs.length; i++) {
		Element.removeClassName(sibs[i],'active');
	}
	Element.addClassName($(obj.parentNode),'active');

	$(id).src = "/_media/"+path;
	obj.blur();
	return false;
}


function extpop() { // v1.0 | www.TJKDesign.com (modified by Caxiam)
	var thisDomain = document.domain.toUpperCase();
	$$('a').each(function(a) {
		var href = a.readAttribute('href');
		if (href && href.indexOf('://') != -1 && href.toUpperCase().indexOf(thisDomain) == -1) {
			if ($(a).hasClassName('int-link') == false && $(a).up().id.indexOf('twitter-feed') == -1) {
				a.addClassName('extlink');
				a.title += ' (opens in new window)';
		        a.onclick = function(){newWin=window.open(this.href,'TJKWin');if(window.focus){newWin.focus()} return false;}
			}
		}
	});
}

function setCookie(name,value) {
	document.cookie = name + "=" + value + "; path=/";
}

function getKeywordFlash() {					
	$$('div.keywords div.flash ul')[0].hide();
	var k = $$('div.keywords div.flash li').pluck('innerHTML').join();	
	$$('div.keywords div.flash')[0].insert('<div id="swfObject"></div>');
	var flashvars = { ijog: 4, idelay: 1, itime: 1, fmin: 2, fmax: 4, fdelay: 0, ftime: 1, keywords: k };
	var attributes = {};
	var params = {};
	params.wmode = "opaque";
	params.scale = "noscale";
	params.salign = "tl";
	swfobject.embedSWF("/_media/_swf/keywords.swf", "swfObject", "437", "164", "9.0.0", false, flashvars, params, attributes);
}

var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<html>\n<head>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n<link href="/_media/_css/printview.css" rel="stylesheet" type="text/css" media="all">';
		html += '\n</he' + 'ad>\n<body>\n';
		
		var printReadyElem = document.getElementById("printable");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</bo' + 'dy>\n</ht' + 'ml>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}




function initSiteMap()
{
	
	// Define Variables Here
	var sections =  $$('div.sitemap dl');
	var itemclass = 'additional';
	var hideclass = 'hide';
	var showlabel = '[ Show Additional Items ]';
	var hidelabel = '[ Hide Additional Items ]';
	var linkhtml =  '<div class="show-hide"><a href="#">' + showlabel + '</a></div>';
	
	// Exit If No Site Map Sections Exist
	if (!sections.any()) return;
	
	sections.each(function(s, i) {
		
		// Select Only the Direct Children of Each Section and Apply the Classes
		var children = s.childElements();
		children.each( function(c) {  
			if (c.hasClassName(itemclass)) {
				c.addClassName(hideclass);
			}
		});
		
		// If Any Children Exist That Have the Class Applied
		if ( children.any( function(c) { return c.hasClassName(itemclass); } )) {
			
			// Insert the Link After the Section
			s.insert({ 'after': linkhtml });
			var showhide = s.next('div.show-hide').down('a');
			
			// When the Link is Clicked
			showhide.observe('click', function(e) { 
				children.each( function(c) {
					
					// Show/Hide Affected Items
					if (c.hasClassName(itemclass)) {
						c.toggleClassName(hideclass);
					}
				});
			
				// Adjust the Link Text
				if (showhide.innerHTML == showlabel) showhide.update(hidelabel);
				else showhide.update(showlabel);
				
				// Stop the Link from Moving the Page Position
				e.stop();
			
			});
		}
	});
}
