/**
 * @author mkirk
 */
// configuration variables
	var URL_images = 'http://media.kentucky.com/static/moms/images/'; // URL of where the blank.gif image will live.

// jQuery code
	$(document).ready(function(){
		
		// initially pause the headlines shlideshow
			$('div#news div.slides ul').cycle('pause');
		// news headlines on homepage cycle function, builds pagination and sets transition
			$('div#news div.slides ul').cycle(
				{
					fx: 'scrollLeft',
					speed:1,
					timeout:6000,
					pause: 1,
					prev:'div#news span.prev a',
					next:'div#news span.next a',
					pager:'div#news span.pagination',
					pagerAnchorBuilder:function(idx,slide){
						return '<a href="#"><img src="http://media.kentucky.com/static/moms/images/blank.gif" alt=""><\/a>';
					}
				}
			);
			
		// tabs for main content box on homepage
			$('div#box-tabs li a').click(function(){
				$('div#box-tabs li a').each(function(){
					if($(this).hasClass('here')) {
						$(this).removeClass('here');
					}
				});
				
				$(this).addClass('here');
				
				var parentId = $(this).parent().attr('id');
				if(parentId =='news-tab'){
					$('#giveaways').hide();
					$('#join').hide();
					$('#news').show();
					$('div#news div.slides ul').cycle('resume');
				} else if(parentId =='join-tab'){
					$('#news').hide();
					$('div#news div.slides ul').cycle('pause');
					$('#giveaways').hide();
					$('#join').show();
				} else if(parentId =='giveaways-tab'){
					$('#news').hide();
					$('div#news div.slides ul').cycle('pause');
					$('#join').hide();
					$('#giveaways').show();
				}
			});
		

            
		
		
		// mini-slideshow cycle function, builds pagination and sets transition
			$('div#mini-slideshow div.slides ul').cycle(
				{
					fx: 'scrollHorz',
					speed:1,
					timeout:0,
					prev:'div#mini-slideshow span.prev a',
					next:'div#mini-slideshow span.next a',
					pager:'div#mini-slideshow span.pagination',
					pagerAnchorBuilder:function(idx,slide){
						return '<a href="#"><img src="http://media.kentucky.com/static/moms/images/blank.gif" alt=""><\/a>';
					},
					after: after
				}
			);
			
            function after(){
                var thisHeight = parseInt($('img', this).attr('height'));
                var calcHeight = parseInt(thisHeight)+230;
                var minidivHeight = parseInt(calcHeight)+43;
                $('#mini-slideshow').css('height',minidivHeight+'px');
                $('#mini-slideshow div.slides ul').css('height',calcHeight+'px');
                $('#mini-slideshow div.slides ul li').css('height',calcHeight+'px');
                //$('div.loading').removeClass('loading');
            }
			
			
		
        // big slideshows
            $('div#big-slideshow div.slides ul').cycle(
				{
					fx: 'fade',
					speed: 1,
					timeout:0,
					prev:'div#big-slideshow span.prev a',
					next:'div#big-slideshow span.next a',
					pager:'div#big-slideshow span.pagination',
					pagerAnchorBuilder:function(idx,slide){
						return '<a href="#"><img src="http://media.kentucky.com/static/moms/images/blank.gif" alt=""><\/a>';
					},
                    after: bigAfter
				}
			);
			
			function bigAfter(){
				//mistats_resend();
				//window.galleryad1.location.reload();
				var thisHeight = parseInt($('img', this).attr('height'));
				var calcHeight = parseInt(thisHeight)+170;
				$('#big-slideshow').css('height',calcHeight+'px');
				$('#big-slideshow div.slides ul').css('height',calcHeight+'px');
				$('#galleryad1').attr("src", function(){
					var url = location.href.toString();
					var i = url.indexOf('/',7);
					var surl = url.slice(i);
					var j = surl.indexOf('/',1);
					var first = surl.substr(0,j);
					var last = surl.slice(j);
					var ad = '/v-ad';
					var nurl = first+ad+last;
					return nurl;
				});
				$('#big-slideshow-loader').hide();
			}
            
            $('#big-slideshow div.controls a').focus(function(){ this.blur(); });
			
			
			// Comment Disclaimer
            $('a#disclaimer-link').click( function() {
                var id = this.id;
				if ($('div.'+id).is(":hidden")) {
					$('span.'+id).removeClass('icon-down');
					$('span.'+id).addClass('icon-up');
				}
				else {
					$('span.'+id).removeClass('icon-up');
					$('span.'+id).addClass('icon-down');
				}
				$('div.'+id).slideToggle("normal");
            });
            
            
            $('p#login-toggle').click( function(){
				if ($('div#login-form-wrap').is(":hidden")) {
					$(this).removeClass('login-down');
					$(this).addClass('login-up');
				}
				else {
					$(this).removeClass('login-up');
					$(this).addClass('login-down');
				}
                $('div#login-form-wrap').slideToggle();
            });
            
            $('p#account-toggle').click( function(){
				if ($('div#member-tools').is(":hidden")) {
					$(this).removeClass('account-down');
					$(this).addClass('account-up');
				}
				else {
					$(this).removeClass('account-up');
					$(this).addClass('account-down');
				}
                $('div#member-tools').slideToggle();
            });

	});

// added for promo rotator        
$(function () {
	$('.promo_rotate_static div').hide ();
	var promo_count = $('.promo_rotate_static div').length;
	var pick = Math.floor (Math.random () * promo_count);
	if( promo_count > 0 ) $($('.promo_rotate_static div')[pick]).show ();
});


