jQuery.noConflict();


jQuery(document).ready(function(){
		
	   
		call_lightbox_clone("auto");
		start_slideshow();
		


});
 
 function start_slideshow() //preloading images for the slideshow, then calling the slideshow
 {
	var $images = jQuery('.feature_image_container img');
	var $everything_loaded = true;
	
	
	$images.each(function(i)
	{
		if ($images[i].complete == false || $images[i].complete == undefined || $images[i].complete == null)
		{
		$everything_loaded = false;	
		} 
	});
	
	
	if($everything_loaded)
		{
			moth_slideshow();	
		}
		else
		{
			window.setTimeout('start_slideshow()',2000);
		}
}




function moth_slideshow()
{	
		
	if(jQuery("#feature_area").length == 0){
		active_rotation = setInterval(function(){},100000000); //fake_var
		return false} //check if this is starting page
	
	jQuery(".feature_thumbs").fadeIn(1400);
	
	
	var thumbs = jQuery(".feature_thumbs .moth_thumb");
	var articles = jQuery(".text_container");
	var autorotate = jQuery("meta[name=moth1]").attr('content');
	var autorotate_duration = jQuery("meta[name=moth2]").attr('content');
	
	if(thumbs.length > 1 && autorotate == 2) //check if rotation should be started?
	{ 
		active_rotation = setInterval(moth_autorotate,autorotate_duration); 
		//change the number for a different pause between slides, 
		//has to be at least 2000 if you have more than 6 slides
		
	}
	else
	{
		if(thumbs.length == 1)
		{
			jQuery(".feature_thumbs").css({display:"none"}); // if only one thumb hide it
		}
		active_rotation = setInterval(function(){},100000000); //fake_var
	}


	var transition_duration = 500;
	var transition_easing = "easeOutBack";
	var autorotate = 0;
	var current_thumb_pos = 0;
	var thumbsdisplayed = 9;
	var modifier = 1;
	var may_change = 1;
	
	jQuery(".feature_thumbs .moth_thumb").bind("click",amplify_rotation);
	
	if(thumbsdisplayed < thumbs.length){
		jQuery(".feature_image").prepend('<a href="" class="prev_thumbs">Prev</a><a href="" class="next_thumbs">Next</a>');
		
		jQuery(".next_thumbs").css({display:"none"}).fadeIn(2200).bind("click","next",moth_change_thumbs);
		jQuery(".prev_thumbs").css({display:"none"}).fadeIn(2200).bind("click","prev",moth_change_thumbs);
	}
	
	
	function moth_autorotate()
	{	
		autorotate = jQuery(".feature_thumbs .moth_thumb").length-1 <= autorotate? 0 : autorotate+1;
		jQuery(".feature_thumbs .moth_thumb:eq("+autorotate+")").trigger("click",["auto"]);
		
		if (autorotate+2 > thumbsdisplayed * modifier || autorotate+2 > jQuery(".feature_thumbs .moth_thumb").length)
		{	
			jQuery(".next_thumbs").trigger("click",["auto"]);
		}
		
	}
	
	function moth_change_thumbs(click_event, auto)
	{	
		if (auto != "auto"){
		clearInterval(active_rotation);	
			}
		thumbnails = jQuery(".feature_thumbs .moth_thumb_wrap");		
		show_segment = thumbsdisplayed * modifier;
		current_thumb_pos = show_segment - thumbsdisplayed;
		modifier = click_event.data == "next" ? modifier +1: modifier -1;
		
		if (modifier == 0){
			modifier = thumbnails.length/thumbsdisplayed;
			modifier = Math.ceil(modifier);			
			}
			
			
		if (modifier > Math.ceil(thumbnails.length/thumbsdisplayed)){
			modifier = 1;
			}
				
				
				
		thumbnails.slice(show_segment,thumbnails.length).css({display:"none"});
		thumbnails.slice(current_thumb_pos,show_segment).each(function(i)
		{
			jQuery(this).fadeOut(transition_duration,function()
			{
			show_segment = thumbsdisplayed * modifier;
			current_thumb_pos = show_segment - thumbsdisplayed;
			
			thumbnails.slice(current_thumb_pos,show_segment).fadeIn(transition_duration);
			});
	
		});
		
		current_thumb_pos += thumbsdisplayed;
	return false;	
	}
	
	
	function amplify_rotation(event, $auto)
	{	
	
		if (may_change == 0) return false;
		
		may_change = 0;
		if($auto != "auto")
		{
		clearInterval(active_rotation);
		}
				
		$image = jQuery(this);
		if ($image.hasClass("current_image")) {may_change = 1; return false};
		jQuery(".current_image").removeClass("current_image");
		$image.addClass("current_image");
		/*positioning of the soon to be cloned image*/
		$image_pos = $image.offset();
		$container = jQuery("#feature_area").offset();
		$new_pos_top  =  $image_pos.top - $container.top ;
		$new_pos_left =  $image_pos.left - $container.left;
		
		$imgwrap_y = jQuery(".imgwrap").height();
		$imgwrap_x = jQuery(".imgwrap").width();
		
		$animate_to = jQuery(".feature_image_container").offset();
		
		$own_center_y = $image.height()/2;
		$own_center_x = $image.width()/2;
		
		$animate_to_center_y = jQuery(".feature_image_container").height()/2;
		$animate_to_center_x = jQuery(".feature_image_container").width()/2;
		
		$step1 = $animate_to.top- $container.top + $animate_to_center_y - $own_center_y;
		$step2 = $animate_to.left - $container.left + $animate_to_center_x - $own_center_x;
		
		$step3 = $animate_to.top- $container.top +1; //+1 is a modifier because the new image does not have a border
		$step4 = $animate_to.left - $container.left +1;
		
		$number_of_image = $image.attr('id').replace(/moth_thumb_/,"");
				
				
		/*cloning image and apllying styles*/
		$slidingImage = $image.clone().appendTo(jQuery("#feature_area")).css(
		{
			position:"absolute",
			top:$new_pos_top,
			left:$new_pos_left,
			zIndex:12
		});
		
		//not used anymore, could be used with resizing script
		//$img = $slidingImage.find(".thumbwrap img");
		//$img.attr('src',$img.attr('alt'));
	
		
		/*changing text that is displayed*/
		jQuery('.text_container:visible').fadeOut(transition_duration,function()
		   {
		   		jQuery(this).addClass('hidden').css({display:"none"});
				jQuery("#text_container_"+$number_of_image).css({display:"none"}).removeClass('hidden').fadeIn(transition_duration/2);
		   });
		
		$slidingImage.animate(
		{
			top:$step1,left:$step2
		
		},transition_duration,transition_easing, 
		function()
	    {
			
	
			
			jQuery(this).css({zIndex:3}).animate(
			{
				top:$step3,
				left:$step4,
				width:$animate_to_center_x*2,
				height:$animate_to_center_y*2
			},
				transition_duration,transition_easing); 
			
				call_lightbox_clone($auto);
				

			
jQuery(this).addClass('noborder_padding').find(".thumbwrap").removeClass("nojava_resize").animate(
			{
				width:$imgwrap_x,
				height:$imgwrap_y
				},
				transition_duration,transition_easing, function()
				{
				var items = jQuery(".moth_thumb").not(".feature_thumbs .moth_thumb");	
				may_change = 1;
				if(items.length > 3){	
				items.slice(0,1).remove();
				}
				});
		   });
		
		return false;
	}
	
}



					
		
		





function call_lightbox_clone(action){
			if (action != "auto"){
			clearInterval(active_rotation);
			}
			jQuery("a[rel^='prettyPhoto'], a[rel^='lightbox']").not(".feature_thumbs .moth_thumb a").prettyPhoto({theme:'dark_rounded',padding: 40});
	}
	

 




/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 0.6;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 0.6;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
 
 