var startPos, mover, fader, fadertwo, faderend, imageScroll, IE;

window.addEvent('domready', function(){ 
	replaceLinks();
	mover       = new Fx.Tween('floating-bar');
	fader       = new Fx.Tween('floating-bar');
	faderend    = new Fx.Tween('floating-bar');
	fader.set("opacity", 0);
	fadertwo    = new Fx.Tween('floating-bar');
	startPos    = $('floating-bar').getPosition();
	$('menu-icons').addEvent('mouseleave', function() {fader.cancel();fadertwo.cancel();faderend.start("opacity", 0);})
	/*imageScroll = new Fx.Scroll('gallery',
		{
	    	offset: {
	        	'x': -(parseInt(document.body.getStyle('width').replace("px", "")) / 2)
	    	}
		}
	);*/
});

function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

var contactSubmit = function(){
	// Stops the submission of the form.
	//new Event(evt).stop();

	// Sends the form to the action path,
	// which is 'script.php'
	$('contact-form').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		//Empty the log and show the spinning indicator.
		//var log = $('log_res').empty().addClass('ajax-loading');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) { 
			if (response != '1')
				alert(response);
			else
				alert('sent!');
		}});
		//Send the form.
		this.send();
	});
	/*$('contact-form').send({
		onComplete: function(response) {
			if (response != '1')
			{
				alert(response);
			} else {
				box.close();
			}
		}
	});*/
}

var replaceLinks = function()
{
	tfp_replace_selector.split(',').each(function(s) {
		$$(s).each(function(el) {
			if (el.href.indexOf("#") <= -1 && el.href.indexOf(siteurl) > -1)
				el.href = "/#" + el.href.replace("http://" + siteurl + "/", "");
		});
	});
}

var moveFloatTo = function(obj, text)
{
	IE = /*@cc_on!@*/false;
	if (IE)
		return false;
	mover.cancel(); fader.cancel(); fadertwo.cancel();
	$('floating-bar').innerHTML = text;
	mover  = new Fx.Tween('floating-bar', {duration: 800, transition: Fx.Transitions.Bounce.easeOut });
	fader  = new Fx.Tween('floating-bar', {
		duration: 400, 
		onChainComplete: 
			function() {
				fadertwo = new Fx.Tween('floating-bar', {duration: 400});
				fader.start("opacity", 1);
			}
		}
	);
	objPos = obj.getPosition();
	objWid = parseInt(obj.getStyle('width').replace("px", "")) / 2;
	mover.start("left", ((objPos.x - startPos.x) - (183 + 136)) + objWid);
	fader.start("opacity", .25);
}
