function highlightPullout(dir,num) {
	if(dir=='over') {
		$('pullout'+num).set('morph', {duration: 500, transition: 'sine:out'});
		$('pullout'+num).morph('div.pullout_active');
		var img_tags = document.getElementById('pullout'+num).getElementsByTagName('img');
		for(var x=0;x<img_tags.length;x++) {
			if(img_tags[x].src.indexOf('pullout_title'+num+'.png')>=0) img_tags[x].src = '/images/pullout_title'+num+'_active.png';
			if(img_tags[x].src.indexOf('pullout_arrow.png')>=0) img_tags[x].src = '/images/pullout_arrow_active.png';
		}
		var p_tags = document.getElementById('pullout'+num).getElementsByTagName('p');
		for(var x=0;x<p_tags.length;x++) { $(p_tags[x]).morph('p.pullout_active'); }
	} else if(dir=='out') {
		$('pullout'+num).morph('div.pullout');
		var img_tags = document.getElementById('pullout'+num).getElementsByTagName('img');
		for(var x=0;x<img_tags.length;x++) {
			if(img_tags[x].src.indexOf('pullout_title'+num+'_active.png')>=0) img_tags[x].src = '/images/pullout_title'+num+'.png';
			if(img_tags[x].src.indexOf('pullout_arrow_active.png')>=0) img_tags[x].src = '/images/pullout_arrow.png';
		}
		var p_tags = document.getElementById('pullout'+num).getElementsByTagName('p');
		for(var x=0;x<p_tags.length;x++) { $(p_tags[x]).morph('p.pullout'); }
	}
}
function openPDF(url) {
	window.open(url, "pdf_file",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,modal=yes,close=no,resizable=1,width=800,height=600,left=100,top=100');
}

var preform_next = function() { performMovement('N'); };
var preform_prev = function() { performMovement('P'); };
var slide_timer = 0;
window.onload = function() { if($('playslide')) { if($('playslide').value=='Y') slide_timer = setTimeout("moveSlide('N','Y');",slideshow_delay); } };

function updateCaption() {
	var id = $('current_slide').value.split(".");
	var id = id[0].replace('gal','');
	var http = getHTTPObject();
	http.open("GET", "includes/getcaption.php?id="+id, true);
	http.onreadystatechange = function(http) {
		if(this.readyState==4) {
			var textout = this.responseText;
			$('slide_caption').innerHTML = textout;
			$('slide_container').morph({opacity: 1});
			$('slide_buttons').morph({opacity: 1});
		}	
	};
	http.send(null);
}
function moveSlide(dir,fromslide) {
	$('slide_container').set('opacity',1);
	$('slide_container').set('morph', {duration: Math.round(slide_duration/2), onComplete: updateCaption});
	$('slide_container').morph({opacity: 0});
	$('slide_buttons').set('opacity',1);
	$('slide_buttons').set('morph', {duration: Math.round(slide_duration/2), onComplete: updateCaption});
	$('slide_buttons').morph({opacity: 0});
	if(fromslide!='Y') { $('playslide').value = 'N';clearTimeout(slide_timer);$('pause_play').innerHTML = 'PLAY'; }
	var slideshow = $('slideshow_array').value.split("#");
	var curr_sld = $('current_slide').value;
	var key = slideshow.indexOf(curr_sld);
	var next_sld = (typeof(slideshow[(key + 1)])=='undefined'||slideshow[(key + 1)]=='') ? slideshow[0] : slideshow[(key + 1)];
	var prev_sld = (typeof(slideshow[(key - 1)])=='undefined'||slideshow[(key - 1)]=='') ? slideshow[(slideshow.length - 1)] : slideshow[(key - 1)];
	if(dir=='N') {
		$('gal_image1').setStyle('left', '0px');
		$('gal_image2').setStyle('left', '960px');
		$('gal_image2').addEvent('load', preform_next);
		$('gal_image1').src = '/slideshow/'+curr_sld;
		$('gal_image2').src = '/slideshow/'+next_sld;
		$('current_slide').value = next_sld;
	} else if(dir=='P') {
		$('gal_image1').setStyle('left', '-960px');
		$('gal_image2').setStyle('left', '0px');
		$('gal_image1').addEvent('load', preform_prev);
		$('gal_image1').src = '/slideshow/'+prev_sld;
		$('gal_image2').src = '/slideshow/'+curr_sld;
		$('current_slide').value = prev_sld;
	}
	
}
function pausePlaySlide() {
	if($('playslide').value=='Y') {
		clearTimeout(slide_timer);
		$('playslide').value = 'N';
		$('pause_play').innerHTML = 'PLAY';	
	} else if($('playslide').value=='N') {
		$('playslide').value = 'Y';	
		slide_timer = setTimeout("moveSlide('N','Y');",slideshow_delay);
		$('pause_play').innerHTML = 'PAUSE';	
	}
}
function performMovement(dir) {
	if(dir=='N') {
		$('gal_image1').set('morph', {link: 'chain', duration: slide_duration, transition: 'sine:out'});
		setTimeout("$('gal_image1').morph('img.gal_image1_inactive');",50);
		$('gal_image2').set('morph', {duration: slide_duration, transition: 'sine:out'});
		$('gal_image2').morph('img.gal_image2_active');
	} else if(dir=='P') {
		$('gal_image2').set('morph', {link: 'chain', duration: slide_duration, transition: 'sine:out'});
		setTimeout("$('gal_image2').morph('img.gal_image2_inactive');",50);
		$('gal_image1').set('morph', {duration: slide_duration, transition: 'sine:out'});
		$('gal_image1').morph('img.gal_image1_active');
	}
	$('gal_image1').removeEvents('load');
	$('gal_image2').removeEvents('load');
	if($('playslide').value=='Y') {
		slide_timer = setTimeout("moveSlide('N','Y');",slideshow_delay);
	}
}
function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}
function submitContact(fromVeg) {
	var name = $('name').value;
	var company_name = $('company_name').value;
	var phone = $('phone').value;
	var email = $('email').value;
	var message = $('message').value;
	if(name!=''&&email!=''&&message!='') {
		$('send_button').className = 'send_button_submitted';
		var set_height = $('form_fields').offsetHeight;
		$('contact_form_cont').setStyle('height',set_height);
		$('form_fields').set('morph',{duration:800,onComplete: showSubmitting});
		$('form_fields').morph({opacity:0});
		var http = getHTTPObject();
		http.open("GET", "/includes/sendEmail.php?name="+name+"&company_name="+company_name+"&phone="+phone+"&email="+email+"&message="+message+"&fromVeg="+fromVeg, true);
		http.onreadystatechange = function(http) { if(this.readyState==4) { var textout = this.responseText; } };
		http.send(null);
	} else {
		alert('You must provide at least a name, email and message to continue.  Please amend and try again.');
		return false;
	}
}
function showSubmitting() {
	$('form_fields').style.display = 'none';
	$('sending_request').setStyle('opacity',0);
	$('sending_request').style.display = 'block';
	var set_height = $('sending_request').offsetHeight;
	$('contact_form_cont').set('morph',{duration:1000,onComplete: function() { setTimeout(showCompleted,2500); } });
	$('contact_form_cont').morph({height:set_height});
	$('sending_request').set('morph',{duration:800});
	$('sending_request').morph({opacity:1});
}
function showCompleted() {
	$('sending_request').set('morph',{
		duration:800,
		onComplete: function() {
			$('sending_request').style.display = 'none';
			$('successfully_sent').setStyle('opacity',0);
			$('successfully_sent').style.display = 'block';
			var set_height = $('successfully_sent').offsetHeight;
			$('contact_form_cont').set('morph',{duration:1000});
			$('contact_form_cont').morph({height: set_height,backgroundColor: '#F4F4F4', borderColor: '#DBDBDB'});
			$('successfully_sent').set('morph',{duration:800});			
			$('successfully_sent').morph({opacity:1});
		}
	});
	$('sending_request').morph({opacity:0});
}
function keyCheck(check_type,obj,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	switch(check_type) {
		case 'phone':
			var chrcodes_allowed = new Array(32,43,48,49,50,51,52,53,54,55,56,57);
			var keycodes_allowed = new Array(32,96,97,98,99,100,101,102,103,104,105,107);
		break;
		case 'email':
			var chrcodes_allowed = new Array(38,43,45,46,47,48,49,50,51,52,53,54,55,56,57,61,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122);
			var keycodes_allowed = new Array(58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,96,97,98,99,100,101,102,103,104,105,109,189,187,191);
		break;
	}
	if(keycodes_allowed.indexOf(keycode)<0) {
		var initial_string = obj.value;
		for(var v=0;v<obj.value.length;v++) {
			var chrcod = obj.value.charCodeAt(v);
			if(chrcodes_allowed.indexOf(chrcod)==-1) {
				obj.value = obj.value.split(initial_string.substr(v,1)).join('');
			}
		}
	}
}
