// when the DOM is ready...




function re_load_id(x){

	var xxx = getElementsByClassName(x+'_panels');
	
	for (i=0;i<xxx.length;i++){
	
		xxx[i].setAttribute("id","Element_"+i);
	
	}
	
}

function indexChange(x){
if (x=='up'){
document.getElementById('highlight').style.zIndex = '1';
}
else{
document.getElementById('highlight').style.zIndex = '4';
}
}

function open_close(){
	var x = document.getElementById('thumbnails');
	document.getElementById('thumbnails').style.left = new_pos+'px';
	if (x.style.display=='none'){
	x.style.display='block';
	}
	else{x.style.display='none';}
}

function re_load_menu(x){
	
	var z = 0;
	var xxx = getElementsByClassName(x+'_menu')[0].getElementsByTagName('img');

	var rebuild = '';
	rebuild = '<img class="scrollButtons left" src="images/left_scroll.png"/><img class="scrollButtons right" src="images/right_scroll.png"/><img class="trigger" src="images/thumbnail_trigger.png" border="0" onclick="open_close();indexChange('+"'up'"+')"/>';
	rebuild += '<div id="thumbnails" style="display:none">';
	
	for (i=0;i<=xxx.length;i++){
		
		if (document.getElementById('Element_'+i)!=null){
			
			var is_image = document.getElementById('Element_'+i).innerHTML;	
			var find_image = is_image.search(/sixfour_/i);
		
		
			if(find_image!=-1){
				rebuild += '<a href="#Element_'+i+'"onclick="document.getElementById('+"'thumbnails'"+').style.display='+"'none'"+';indexChange('+"''"+')"/><img border="0" src="'+xxx[z].src+'"/></a>';
				z++;
			}
		
		}
	
	}
	rebuild += '</div>';
	getElementsByClassName(x+'_menu')[0].innerHTML = rebuild;
}

function visible_load(x){

	if (x=='on'){
		if (document.getElementById('load')!=null){
		document.getElementById('load').style.visibility = 'visible';
		}
		if (document.getElementById('loadzable')!=null){
		document.getElementById('loadzable').style.visibility = 'visible';
		}
		if (document.getElementById('loadmakuti')!=null){
		document.getElementById('loadmakuti').style.visibility = 'visible';
		}
		if (document.getElementById('loadmanuel')!=null){
		document.getElementById('loadmanuel').style.visibility = 'visible';
		}
	}
	else{
		if (document.getElementById('load')!=null){
		document.getElementById('load').style.visibility = 'hidden';
		}
		if (document.getElementById('loadzable')!=null){
		document.getElementById('loadzable').style.visibility = 'hidden';
		}
		if (document.getElementById('loadmakuti')!=null){
		document.getElementById('loadmakuti').style.visibility = 'hidden';
		}
		if (document.getElementById('loadmanuel')!=null){
		document.getElementById('loadmanuel').style.visibility = 'hidden';
		}
	}

}



function load_slide(x) {
	
	
	if (getElementsByClassName(x+'_menu')[0]!=null){
	
		visible_load('on');
		getElementsByClassName(x+'_menu')[0].style.display = 'none';
		
		re_load_id(x);
		re_load_menu(x);
	
		
		var $panels = $('#'+x+' .'+x+'_scrollContainer > div');
		var $container = $('#'+x+' .'+x+'_scrollContainer');
	
		// if false, we'll float all the panels left and fix the width 
		// of the container
		var horizontal = true;
	
		// float the panels left if we're going horizontal
		if (horizontal) {
			$panels.css({
				'float' : 'left',
				'position' : 'relative' // IE fix to ensure overflow is hidden
			});
	
			// calculate a new width for the container (so it holds all panels)
			$container.css('width', $panels[0].offsetWidth * $panels.length);
		}
	
		// collect the scroll object, at the same time apply the hidden overflow
		// to remove the default scrollbars that will appear
		var $scroll = $('#'+x+' .'+x+'_scroll').css('overflow', 'hidden');
	
		// apply our left + right buttons
	  
		// handle nav selection
		function selectNav() {
			$(this)
				.parents('ul:first')
					.find('a')
						.removeClass('selected')
					.end()
				.end()
				.addClass('selected');
		}
	
		$('#'+x+' .'+x+'_menu').find('a').click(selectNav);
	
		// go find the navigation link that has this target and select the nav
		function trigger(data) {
			var el = $('#'+x+' .'+x+'_menu').find('a[href$="' + data.id + '"]').get(0);
			selectNav.call(el);
		}
	
		if (window.location.hash) {
			trigger({ id : window.location.hash.substr(1) });
		} else {
			$('ul.'+x+'_menu a:first').click();
		}
	
		// offset is used to move to *exactly* the right place, since I'm using
		// padding on my example, I need to subtract the amount of padding to
		// the offset.  Try removing this to get a good idea of the effect
		var offset = parseInt((horizontal ? 
			$container.css('paddingTop') : 
			$container.css('paddingLeft')) 
			|| 0) * -1;
	
	
		var scrollOptions = {
			target: $scroll, // the element that has the overflow
	
			// can be a selector which will be relative to the target
			items: $panels,
	
			navigation: '.'+x+'_menu a',
	
			// selectors are NOT relative to document, i.e. make sure they're unique
			 prev: 'img.left',
			 next: 'img.right',
			
			// allow the scroll effect to run both directions
			axis: 'xy',
	
			onAfter: trigger, // our final callback
	
			offset: offset,
	
			// duration of the sliding effect
			duration: 500,
	
			// easing - can be used with the easing plugin: 
			// http://gsgd.co.uk/sandbox/jquery/easing/
			easing: 'swing'
		};
	
		// apply serialScroll to the slider - we chose this plugin because it 
		// supports// the indexed next and previous scroll along with hooking 
		// in to our navigation.
		$('#'+x).serialScroll(scrollOptions);
	
		// now apply localScroll to hook any other arbitrary links to trigger 
		// the effect
		$.localScroll(scrollOptions);
	
		// finally, if the URL has a hash, move the slider in to position, 
		// setting the duration to 1 because I don't want it to scroll in the
		// very first page load.  We don't always need this, but it ensures
		// the positioning is absolutely spot on when the pages loads.
		scrollOptions.duration = 1;
		$.localScroll.hash(scrollOptions);
	
	
		getElementsByClassName(x+'_menu')[0].style.display = 'block';
		
		setTimeout("document.getElementById('"+x+"').style.visibility = 'visible';",3000);
		
		setTimeout("visible_load('');",3000);
		
	}
}





/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};


