$(function(){
	//Required for stupid IE
	$.ajaxSetup({cache: false});

	/*$('div.navigation ul li:last-child').addClass('last');

	if ($('.side-navigation h3 > a').length) {
		$('div.navigation > ul > li > a').each(function() {
			if (this.pathname.toLowerCase() == $('.side-navigation h3 > a').attr('pathname').toLowerCase()) {
				$(this).addClass('selected').parent().addClass('selected');
			}
		});
	}*/

	$('ul.nav-list').find('a').each(function() {
		var pathName = this.pathname.toLowerCase();
		if (pathName.charAt(0) != '/') {
			pathName = '/' + pathName;
		}

		if (pathName == window.location.pathname.toLowerCase()) {
			if ($(this).addClass('selected').parent().parent('ul.nav-list').get(0)) {
				$(this).append('<span></span>');
			} else {
				$(this).closest('ul').prev('a').addClass('selected').append('<span></span>');
			}
			return false;
		}
	});

	$("a[rel=clbox]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#1f1a1a',
		'overlayOpacity'	: '0.8',
		'titlePosition' 	: 'outside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

	$("#id-contact").fancybox({
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#1f1a1a',
		'overlayOpacity'	: '0.8',
		'outerColor'		: 'none',
		'titleShow'			: false,
		'onComplete'		: function(){
									$('form').ajaxForm({
										target:'#fancybox-inner',
										success: function(){
											$.fancybox.resize();
										}
									});
								}
	});

});

slideshowtime=5000;
var currentPosition = 1;
tslideshowimg=0;
function showit() {
	$(".slidingimages ul li."+currentPosition+"sld").fadeOut('slow');
	$("."+currentPosition+"slddot a").removeClass('selected');
	currentPosition =  currentPosition+1;
	if(currentPosition>tslideshowimg)
		currentPosition=1;
	$(".slidingimages ul li."+currentPosition+"sld").fadeIn('slow');
	$("."+currentPosition+"slddot a").addClass('selected');
}
$(document).ready(function() {
	tslideshowimg=$('.slidingimages ul li').length;
	if(tslideshowimg>1)
		inv=setInterval('showit()',slideshowtime);
	$(".pagination-dots ul li").click(function(event){
		clearInterval(inv);
		currentPosition=parseInt($(this).attr('class'));
		$(".slidingimages ul li").fadeOut('slow');
		$(".slidingimages ul li."+currentPosition+"sld").fadeIn('slow');
		$(".pagination-dots li a").removeClass('selected');
		$("."+currentPosition+"slddot a").addClass('selected');
		inv=setInterval('showit()',slideshowtime);
	});

	currentPos = 0;
	slideWidth = 136;
	slides = $('.sliderContent');
	numberOfSlides = slides.length;
	beforePosition = 1;
	oldPosition = 0;
	slideWidth=slideWidth*3;
	conwidth=slideWidth * Math.ceil(numberOfSlides/3);
	//alert(slideWidth);
	// Set #slideInner width equal to total width of all slides
	$('#sliderInnerHolder').css('width', conwidth);
	// Hide left arrow control on first load
	manageControls(currentPos);
	$('.control').bind('mouseover',function(){
		// Determine new position
		currentPos = ($(this).attr('id')=='controlRight') ? currentPos+1 : currentPos-1;
		oldPosition = beforePosition;
		beforePosition = currentPos+1;
		// Hide / show controls
		manageControls(currentPos);
		// Move slideInner using margin-left
		$('#sliderInnerHolder').animate({
			'marginLeft' : slideWidth*(-currentPos)
		},4000);
	});
	function manageControls(position){
		// Hide left arrow if position is first slide
		if(position==0){ $('#controlLeft').hide() } else{ $('#controlLeft').show() }
		// Hide right arrow if position is last slide
		if(position==Math.ceil(numberOfSlides/3)-1){ $('#controlRight').hide() } else{ $('#controlRight').show() }
	}
	function manageContentControls(position){
		// Hide left arrow if position is first slide
		if(position==0){ $('#controltop').hide() } else{ $('#controltop').show() }
		// Hide right arrow if position is last slide
		if(position==numberOfconSlides-1){ $('#controlbot').hide() } else{ $('#controlbot').show() }
	}

	$('.nav-list li').hover(
		function () {
			$('ul', this).slideDown(100);
		},
		function () {
			$('ul', this).slideUp(100);
		}
	);
});
