


/*
	eq_object.js
	Global euroquick object
	copyright Copyright (c) 2007, Sen Haerens
*/

if (!eq)
{
	var eq = new Object();
}

// Set debug output
sh.debug.set = false;

// User interface routines
eq.ui = new Object();

// Toggle element visibility
eq.ui.toggle = function(element)
{
	var element = document.getElementById(element);
	
	if (element.style.display == 'block')
	{
		element.style.display = 'none';
	}
	else
	{
		element.style.display = 'block';
	}
}

// Display confirmation box
eq.ui.confirm = function(question)
{
	var confirm = window.confirm(question);
	return confirm;
}

// Insert tags
// Based on punbb - copyright (c) 2007, Rickard Andersson
eq.ui.insert_tag = function(open, close, element)
{
	msgfield = document.getElementById(element);

	// IE support
	if (document.selection && document.selection.createRange)
	{
		msgfield.focus();
		sel = document.selection.createRange();
		sel.text = open + sel.text + close;
		msgfield.focus();
	}

	// Moz support
	else if (msgfield.selectionStart || msgfield.selectionStart == '0')
	{
		var startPos = msgfield.selectionStart;
		var endPos = msgfield.selectionEnd;

		msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
		msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
		msgfield.focus();
	}

	// Fallback support for other browsers
	else
	{
		msgfield.value += open + close;
		msgfield.focus();
	}

	return;
}

// Relocate to given anchor
eq.ui.jump2anchor = function(anchor)
{
	if (anchor != null)
	{
		window.location.hash = anchor;
	}
}

// Transform input filepath to a proper title
eq.ui.file2title = function(filepath, target)
{
	var target = document.getElementById(target);
	
	if (target != null && filepath != null)
	{
		// Extract basename
		// 0 = string, 1 = dir path, 2 = filename, 3 = file extension
		filepath = filepath.match(/^(.*\/|\\)?(.*)(\..{0,4})/);
		var title = filepath[2];
		
		// Clean up dashes and underscores
		title = title.replace(/(-|_)+/g, ' ');
		
		// Convert to title case
	 	title = title.toLowerCase().replace(/\w+/g, function(s)
		{
			return s.charAt(0).toUpperCase() + s.substr(1);
		})
		
		target.value = title;
	}
}

// Dealer routines
eq.dealer = new Object();

// Dealer *Live search*
eq.dealer.search = function(query)
{
	var self = this;		
	this.query = query;
	this.target = document.getElementById('middle');
	
	if (query != undefined && query != '')
	{
		// Execute xmlhttprequest
		var process = function()
		{
			var req = new sh.xml.request();
			req.url = '/verkoopadressen/zoek/' + query;
			req.submit();
			
			req.onComplete = function(response)
			{
				if (response)
				{
					self.target.innerHTML = response;					
				}
				else
				{
					self.target.innerHTML = '';					
				}
			}
		}
	
		// Keep our database server happy
		// http://www.kevlindev.com/blog/?p=72
		window.setTimeout(process, 25);
	}
	else
	{
		this.target.innerHTML = '';
	}
}

// Animation routines
// jQuery library required

$(function()
{
	// Cascade fade
	var sh_duration = 500;

	$('.sh_cascade_fade').each(function()
	{
		$(this).hide().fadeIn(sh_duration);
		sh_duration = sh_duration + 250;
	});
	
	// Thumbnail gallery
	$('.sh_thumb_gallery').bind('click', null, function()
	{
		var href = $(this).attr('href');
		var img = $('#sh_product_image');
		
		// Only animate if img src is different		
		if (href != img.attr('src'))
		{
			img.fadeOut('normal', function()
			{
				//img.hide();
				$(this).attr('src', href).fadeIn('normal');		
			});
			
			//img.fadeTo('normal', 0, function()
			//{
			//	$(this).attr('src', href).fadeTo('normal', 100, null);		
			//});
		}
		
		return false;			
	});
	
	// JCarousel
	$('#mycarousel').jcarousel({
	});

});

