/* ---------------------------------------------------
	SIFR Config
----------------------------------------------------*/

var GothamLight = { src: 'http://www.ardentmc.com/_lib/swf/GothamRndLight.swf' };

sIFR.activate(GothamLight);

sIFR.replace( GothamLight, {
  selector: 'h1.subpg',
  wmode: 'transparent',
  css: [   '.sIFR-root { background-color: #FFFFFF; color: #414144; leading: 1; letter-spacing: 0 }'
      		,'a { text-decoration: none; }'
      		,'a:link { color: #393836; }'
      		,'a:hover { color: #746a5f; }'
	]
});

sIFR.replace( GothamLight, {
  selector: 'h1.pghdr',
  wmode: 'transparent',
  css: [   '.sIFR-root { background-color: #FFFFFF; color: #ffffff; leading: 0; letter-spacing: 0 }'
      		,'a { text-decoration: none; }'
      		,'a:link { color: #393836; }'
      		,'a:hover { color: #746a5f; }'
	]
});


$(document).ready(function() {

	buildHomePageSlider();
	
	
	
	/* fma rotator */
	
	$('#fma-slides').cycle({
		fx:     'fade',
		timeout: 0,
		speed:   500,
		cleartype:  1,
		pager:  '#fma-nav',
		before:	onBefore

	});
	
	/*$('ul#slideshow').animate({
				    height: (optionTexts[slideID-1])+'px'
				  }, 400, function() {
				    q_auth.hide().filter('#auth_' + slideID).show();
				  });
*/
	
	function onBefore(curr, next, opts, fwd) {
		var index = opts.currSlide;
		//$('#prev,#prev2,#prev3,#prev4,#prev5')[index == 0 ? 'hide' : 'show']();
		//$('#next,#next2,#next3,#next4,#next5')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		//get the height of the current slide
		var $ht = $(this).height();
		//set the container's height to that of the current slide
		$(this).parent().animate({height: $ht });
	}
	
	$('#sitenav li.dm').hover(
		function () {
			// show submenu
			$(this).addClass('active');
			$('ul', this).slideDown(125);

		}, 
		function () {
			// hide submenu
			$('ul', this).stop(true, true);
			$(this).removeClass('active');
			$('ul', this).slideUp(125);			
		}
	);
	
	$('a.solmenu').click(function(e){
	
		e.preventDefault();
	
	})
	
	// valid external link
	$('.extlink').attr('target','_blank');
	
	
	var cmPrev = '';
	
	// clear input on focus
	$('.cmFocus').focus(function() {
		if($(this).val()==$(this).attr('title')) {
			cmPrev = $(this).val();
			$(this).val('');
		}
	});
	// if field is empty afterward, add text again
	$('.cmFocus').blur(function() {
		if($(this).val()=='') {
			$(this).val(cmPrev);
		}
	});
	
	$('#commentform').validate();
});



function buildHomePageSlider(){
	var onHome = $('#slide-images');
		if(onHome){
	        $('.slideshow').each(function(index) {
	        $(this).cycle({
				fx:     'scrollUp',
				timeout: 11000,
				speed:   1000,
				sync:    1,
				pauseOnPagerHover: 1,
				before:	 homeGallerySifrTrigger,
				pager:  '#slidenav',
				pagerAnchorBuilder: function(i) {
					if (index == 0) 
						return '<a href="#">'+(i+1)+'</a>';
						return '#slidenav a:eq('+i+')';
	        		}
			});
			
			$('.crotator').cycle({
				fx:     'fade',
				timeout: 4000,
				speed:   1000
			});
			
	    });
	    $('#slide-msgs').hover(
	    	function() { 
	    		$('#slide-msgs').cycle('pause');
	    		$('#slide-images').cycle('pause');
			},
			function () {
				$('#slide-msgs').cycle('resume');
	    		$('#slide-images').cycle('resume');			
			}
		);
		
		var snPos = $('#slide-images img').size();
		snPos = ((snPos*14)/2) + 146;
		$('#slidenav').css({'top' : snPos+'px'});
	}
}



function homeGallerySifrTrigger(curr,next,opts) {
	
    var $slide = $(next);
    	$slide.show();
    	
    sIFR.replace( GothamLight, {
   			selector: 'h2.slidehdr',
   			wmode: 'transparent',
   			css: [ '.sIFR-root { background-color: #FFFFFF; color: #ffffff; leading: -1; letter-spacing: 0 }'
     		,'a { text-decoration: none; }'
     		,'a:link { color: #393836; }'
     		,'a:hover { color: #746a5f; }' ]
     		});
}
