// selected work on homepage
	$(document).ready(function(){
							   				      
		
		if ($("#imagecontrols").length > 0) {
			var imgs = new Array();
			var imageXML;
			var imageURL;
			var currImage = 0;
			var numImages = 4;
			/*$("#imagecontrols").css({'opacity':'0.5'});*/

			$.ajax({
				type: "GET",
				url: "images.xml",
				dataType: "xml",
				success: function(xml) {
					imageXML = xml;
					loadImage(1);
				},
				error: function(status) {
					// do nothing	
				}
			});
			function loadImage(imageNumber) {
				if (imageNumber != currImage) {
					$("#imagecontrols li a#btnimg"+currImage).removeClass('active');
					currImage = imageNumber;
					$("#imagecontrols li a#btnimg"+currImage).addClass('active');
					if (!(imgs[imageNumber])) {
						imgs[imageNumber] = new Image();
						img = imgs[imageNumber];
						
						$(img).load(function () {
							$("#work a.rotateLink").hide();
							$("#work a.rotateLink img").hide();
							$('<a href="'+imageURL+'" id="rotateLink'+imageNumber+'" class="rotateLink" target="_self"></a>').html(this).appendTo('#work').find('img').hide().fadeIn(2000);
						});
						$(img).attr('width', '660');
						$(img).attr('height', '360');
						$(img).attr('src', $(imageXML).find('pic:eq('+(imageNumber-1)+')').find('image').text());
						imageURL = $(imageXML).find('pic:eq('+(imageNumber-1)+')').find('link').text();
					} else {
						$("#work a.rotateLink").hide();
						$("#work a.rotateLink img").hide();
						$("#work a#rotateLink"+imageNumber).show();
						$("#work a#rotateLink"+imageNumber+" img").fadeIn(1000);
					}
				}
			}
			function nextImage() {
				if (currImage >= numImages) {
					loadImage(1);
				} else {
					loadImage(currImage+1);
				}
			}
			var i = setInterval(nextImage, 5000);
			$("#btnimg1").click(function () {
				clearInterval(i);
				loadImage(1);
				return false;
			});
			$("#btnimg2").click(function () {
				clearInterval(i);	
				loadImage(2);
				return false;
			});
			$("#btnimg3").click(function () {
				clearInterval(i);
				loadImage(3);
				return false;
			});
			$("#btnimg4").click(function () {
				clearInterval(i);
				loadImage(4);
				return false;
			});
		
		}
			
		
		
		/* showing and hiding full examples of work */
		$('.example').mouseover(function(){
			$(this).addClass('exampleHover');
			});
		
		$('.example').mouseout(function(){
			$(this).removeClass('exampleHover');
			});
		
		
		$('.example').click(function() {
			$('.examplefullContainer').hide('slow');
			$("[id*='plus']").html('+');
			
			if ($('#' + this.id + 'FullCont').is(':hidden')) {
				$('#' + this.id + 'FullCont').show('slow');
				$('#' + this.id + 'plus').html('&ndash;');
				//document.location.hash = (this.id + 'FullCont');
				//console.log(this.id + 'FullCont');
				}
			return false;

		});
		
/* hide example if clicked outside */

	 $('body').click(function() {
		$('.examplefullContainer').hide('slow');
		$("[id*='plus']").html('+');
	 });
	
	$('#portfolio').removeClass('hide-loading');
	 
 /* show and hide the contact form */
 
	 $('.contact').click(function() {
		if ($('#contactform').is(':visible')) {
		$('#contactform').slideToggle('slow');
			} else {
		$('#contactform').slideToggle('slow');
		}
	});
 
	$('#submit').click(function() {
		$('#contactform').slideToggle('slow')
		});
	$('#closebox').click(function() {
		$('#contactform').slideToggle('slow')
		});


/* FANCY BOX */	
	$("a#single_image").fancybox();
	
	/* Using custom settings */
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	/* apply fancybox to multiple items */
	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'hideOnContentClick': true
	});
	
	$("a.grouped_elements, a.grouped_elements2").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'hideOnContentClick': true,
		'titleShow'			: true,
		'showCloseButton'	: true,
		'titlePosition' 	: 'inside'
									 
		});
		
 });
