/**
 * @section   : Unobtrusive JavaScript events and function calls, triggered on DOMContentLoaded.
 * @project   : Verholen
 * @author    : John van Hulsen <john@e-sites.nl>
 * @version   : 1.0
 */

$(document).ready(function () {

	/* Apply pngfix for MSIE6 and below */
	if (!window.XMLHttpRequest && typeof DD_belatedPNG !== 'undefined'){
		DD_belatedPNG.fix('#swoosh, #splashContent, #nav a, #nav span, .pagination li, #logo');
	}

	/* Opens a new window for anchors with rel=external */
	$('a[rel=external]').bind('click', setExtLinks);

	/* Execute async loading after window.onload event is fired */
	if ($('#googleMap').length) {
		loadMapsAsync();
	}

	$('#contactFrm').bind('submit', function (e) {
		return $(this).chkFrm(e);
	});

	/* MSIE text-shadow */
	if (document.all) {
		initTextShadow();
	}

	/* Init slides */
	$('#slides').slides({
		preload: true,
		container: 'slidesWrapper',
		preloadImage: '/images/misc/loader.gif',
		play: 4000,
		pause: 500,
		pagination: true,
		hoverPause: true
	});

	if ($('.pagination').length) {
		var pag = $('.pagination'),
			firstList = $('li:first-child', pag),
			lastList = $('li:last-child', pag),
			pagWidth = pag.width();

		pag.css({marginLeft : (Math.round((pagWidth / 2) - pagWidth))});
		firstList.addClass('first');
		lastList.addClass('last');
	}

	/* Set opacity when hover items on homepage */
	if ($('#items').length) {
		var anchor = $('#items a');

		$('#items img').css({'opacity' : 1});

		anchor.bind('mouseenter', function() {
			$(this).addClass('active').children('img').animate({'opacity' : 0.5}, 200);
		});

		anchor.bind('mouseleave', function() {
			$(this).removeClass('active').children('img').animate({'opacity' : 1}, 200);
		});
	}

});
