

	/**
	 *
	 * ww_imagecycle
	 * @author: Wido Widlewski <wido@websimplex.de>
	 *
	 *
	 */
var $j = jQuery.noConflict();


	$j(document).ready(function (){
	
		/* display the images to cycle */
		$j('.aniImages').show();
		
		var timeout_value = parseInt($j(document).find('div.ww_imagecycle_timeout').html());
		var refresh_value = 750;
		var speed_value = parseInt($j(document).find('div.ww_imagecycle_speed').html());
		var autostop_value = parseInt($j(document).find('div.ww_imagecycle_autostop').html());
		
		/* get the content for the zoom icon */
		var zoom_icon = '';
		zoom_icon = $j('#ww_imagecycle_zoom').html();
				
		/* get the content of the navigation */		
		var navigation = $j(document).find('#ww_imagecycle_navigation').html();
			
		/* if the navigation is not empty => navigation will be displayed */
		if (navigation != '')
		{
			/* navigation is hidden at the beginning via CSS, to avoid problem with deactivated JS */
			$j('#ww_imagecycle_navigation').show();
			
			/* get the number of images in the slideshow */
			var images = $j('#ww_imagecycle_container').find('img');
			
			/* get the image height to align the navigation to the bottom */
			var image_heights = (parseInt($j('#ww_imagecycle_container').find('img').height()) * (images.length - 1));
			var image_width = parseInt($j('#ww_imagecycle_container').find('img').width());
			
			var navigation_height = parseInt($j('#ww_imagecycle_navigation').height());
			var navigation_width = parseInt($j('#ww_imagecycle_navigation').width());
			
			var navigation_offset = $j('#ww_imagecycle_navigation').offset();
			
			var navigation_top = navigation_offset['top'];
			var navigation_left = navigation_offset['left'];
			
			/* IE calculates things somehow strange ?!?! ... */
			if($j.browser.msie)
			{
				var new_top = parseInt(navigation_top - image_heights - navigation_height - 11);
				var new_left = parseInt(navigation_left - navigation_width);			
			}
			else
			{
				var new_top = parseInt(navigation_top - image_heights - navigation_height - 2);
				var new_left = parseInt(navigation_left + image_width - navigation_width - 0);
			}
	
			$j('#ww_imagecycle_navigation').css('top', new_top + 'px');
			$j('#ww_imagecycle_navigation').css('left', new_left + 'px');
			
			/* append the imagecounter data to the prevnext div, initialize with 1/(images.length) */
			$j('#ww_imagecycle_prevnext').append('<div id="ww_imagecycle_counter"><p>1/' + images.length + '</p></div>');
			
			
			/* set an interval to display the current slideshow object number */
			refresh = window.setInterval(refresh_navigation, refresh_value);
		}
				
		/* the cycle function with some options */
		$j('#ww_imagecycle_container').cycle({
			fx: 'fade', 
			prev: '#ww_imagecycle_prev_link',
			next: '#ww_imagecycle_next_link',
			timeout: timeout_value, 
			speed: speed_value,
			autostop: autostop_value
		});
		
		
		
		
		/* refresh the navigation, to show the current slideshow object number and the zoom icon, if a big image exists */
		function refresh_navigation() {
		
			var counter = 0;
			var count_all = $j('#ww_imagecycle_container').children().length;
			var element = '';
			
			/* hide the zoome icon */
			$j('#ww_imagecycle_zoom').hide('');
						
			/* foreach slideshow elements */
			$j('#ww_imagecycle_container').children().each(function(){
				
				counter = counter + 1;
				
				if ($j(this).css('display') != 'none')
				{
					//element = $j(this);
					
					/* overwrite the counter data with the current element, x/y */
					$j('#ww_imagecycle_counter').find('p').html(counter + '/' + count_all);
					
					/* some content in the var zoom_icon => zoom icon will be shown, if big image exists */
					if (zoom_icon != '')
					{
						/* get the href */
						var href = '';
						
						/* slideshow object is a hyperlink */
						if ($j(this).attr('href'))
						{
							href = $j(this).attr('href');
						}
						
						/* if slideshow element is a hyperlink */
						if (href.length > 0)
						{
							/* loook for image extensions */
							url_string = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
							
							image_ext = href.toLowerCase().match(url_string);
							
							/* check, wheather element is a link and href points to an image */
							if (image_ext == '.jpg' || image_ext == '.jpeg' || image_ext == '.png' || image_ext == '.gif' || image_ext == '.bmp')
							{
								$j('#ww_imagecycle_zoom').show();
								
								/*
								$j('#ww_imagecycle_zoom').html('');
								
								// copy the link into the zoom_div 
								var link_copy = element.clone();
								// remove the slideshow image from the link
								link_copy.find('img').remove();
								// append the zoom_icon to the link
								link_copy.append(zoom_icon);
								
								$j('#ww_imagecycle_zoom').html(link_copy);
								*/
								
								/* simulate a click to the slideshow object */
								//$j('#ww_imagecycle_zoom').click(function(){
									
									//element.click();
									
								//});
								
								/*
								$j('#ww_imagecycle_zoom').mouseover(function(){
									$j(this).css('cursor', 'pointer');
								});
								
								$j('#ww_imagecycle_zoom').mouseout(function(){
									$j(this).css('cursor', '');
								});
								*/
								
							}
						}
						
					}
					
				}
		
			});
			
			
		} //function refresh_navigation
		
		
		
		/* if link is clicked, pause the cycle animation */
		$j('#ww_imagecycle_container').find('a').click( function(){
			
			$j('#ww_imagecycle_container').cycle('pause');
			
			/* clear the interval */
			if (navigation != '')
			{
				window.clearInterval(refresh);
			}
		
		});
		
		/* resume cycle animation, if mouse is over link */
		$j('#ww_imagecycle_container').find('a').mouseover(function(){
		
			$j('#ww_imagecycle_container').cycle('resume');
			
			/* set the interval */
			if (navigation != '')
			{
				refresh = window.setInterval(refresh_navigation, refresh_value);
			}
		
		});
		
	});
