/* ----------------------------------------------------------
	title		  : HFC Framework
	created		  : 9/1/09
	last updated  : 9/24/09
---------------------------------------------------------- */
jQuery.noConflict();     
jQuery(document).ready(function($){


//create controls
$('#feature-txt').append('<div id="feature-controls"></div>');
$('#feature-controls').append('<ul></ul>');

	//get images
	$.ajax({
		type: "GET",
		url: "/Websites/hic/templates/fertilityTheme/feature.xml",
		dataType: "xml",
		success: function(xml) {
			var imgs = $(xml).find('img');

			
			$(imgs).each(function(i){
				var dirPath = $(this).parent().attr('lgPath');
				var imgPath = $(this).attr('src');			
				var linkPath = $(this).attr('link');
				var thumbPath = $(this).attr('thumb');			
				var mainFullPath = dirPath + imgPath;
				var thumbFullPath = dirPath + thumbPath;
				
				// Main Images				
				if (linkPath == '#' || linkPath == '' || linkPath == null) {
							var newImg = '<img src="' + mainFullPath + '" alt="" id="slide-' + i + '" style="position:absolute; z-index:'+ (i+1) +';" />';						
							} else {
							var newImg = '<img src="' + mainFullPath + '" alt="" />';
							newImg = '<a href="' + linkPath + '" id="slide-' + i + '" style="position:absolute; z-index:'+ (i+1) +';">'+ newImg + '</a>';
							}
								
				$(newImg).appendTo('#feature-img');
					
					
				//Thumb Nav	
				var thumbImg = '<li id="thumb-slide-' + i + '"><img src="' + thumbFullPath + '" alt="" /></li>';	
					
				$(thumbImg).appendTo('#feature-controls ul');	
			});
			
			
			// hide features
			$('#feature-img').children().hide();
			
			// hookup the rotation
			$('#feature-controls ul li').click(function(){rotateMagic(this);});
			//initiate first click
			$('#thumb-slide-1').click();
			
			
			//hover awesomeness
			$('#feature-controls ul li img').css({
				'width':'75%',
				'height' : '75%'
				}).hover(function(){
					$(this).animate({
					width:'100%',
					height : '100%',
					marginLeft : '0',
					border : '4px solid #e9a6af'
					});
					}, function(){
					$(this).animate({
					width:'75%',
					height : '75%',
					marginLeft : '18px',
					border : '3px solid #e9a6af'
					});
					});
					
			
		} //end success
	}); //end ajax



function rotateMagic (thumbElem) {
	var thumbID = $(thumbElem).attr('id');
	
	//update nav
	var activeImg = $('#feature-controls ul li.active img');
	
	$(activeImg).css({
		width:'100%',
		height : '100%',
		marginLeft : '0',
		border : '4px solid #e9a6af'
		});
		
	$('#feature-controls ul li.active').removeClass('active');
	
	$(activeImg).animate({
		width:'75%',
		height : '75%',
		marginLeft : '18px',
		border : '3px solid #e9a6af'
		});
	
	$(thumbElem).addClass('active');
	
	//update feature area
	var featSelector = thumbID.replace(/thumb-/gi, '');
	var features = $('#feature-img').children();
	
	$(features).fadeOut(100);
	$('#'+featSelector).fadeIn(1500);
	
	}










});//end doc ready
