// JavaScript Document
$(document).ready(function() {
						   
	// HOME SLIDESHOW
	$(function() {
		// add a 'js' class to the body
		$('body').addClass('js');
		
		// initialise the slideshow when the DOM is ready
		$homeslider.init();
		$('#homeslider ul.slides-nav li:first-child').addClass('on');
	});
	
	// PROTECT EMAIL
	$('a.contactlink').each(function(){
		mail = this.rel.replace('/','@');
		e = mail.replace('?','.');
		this.href = 'mailto:' + e;
		$(this).text(e);
	});
	
	// THUMBNAIL FUNCTION	
    $('#category_services .images .image').each(function() {		 
       var maxWidth = 120;
       var maxHeight = 120;
	   
	   // SET ABSOLUTE POSITION FOR CLIPPING
	   $(this).children('#imagebox').children('.imageholder').children('img').css('position', 'absolute');	   
	   
	   // CHECK IF WE HAD TO RE-POSITION THE IMAGE
	   var image_props = $(this).children('#imagebox').children('.imageholder').children('img');
	   
	   if ( image_props.height() > maxHeight || image_props.width() > maxWidth )
	   {
		   var topPos = ( ( image_props.height() - maxHeight ) / 2 );
		   var leftPos = ( ( image_props.width() - maxWidth ) / 2 );
		   $(this).children('#imagebox').children('.imageholder').children('img').css('top', -topPos); // Set new topPos
		   $(this).children('#imagebox').children('.imageholder').children('img').css('left', -leftPos); // Set new leftPos		   
	   }
    });
	
	// EQUAL HEIGHTS
	$('.left').equalHeights('list_services');
	$('.left').equalHeights('list_about-us');
	$('.left').equalHeights('list_showroom');
	$('.left').equalHeights('list_onlineworld');	
	
	/**
	 * hover and click function for clickable boxes
	 */
	$('.clickable').hover(function() {
		$(this).find('a:first').css({'text-decoration':'underline'});
	},function() {
		$(this).find('a:first').css({'text-decoration':'none'});
	}).click(function() {
		if($(this).find('a:first').attr('target')) {
			window.open($(this).find('a:first').attr('href'));
		} else {
			window.location = $(this).find('a:first').attr('href');
		}
	});	
});
