﻿/*
--------------------------------------------------------------------------------
 Holder for Misc $ Functions
--------------------------------------------------------------------------------
*/
function iif( b, v1, v2 )
{
	return ((b)? v1: v2);	
}

function mmButtons( iLayoutID, bLo, iCount, sClass )
{
	iCount = iif( iCount, iCount, -1)
	//$('#aj-buttons').html('Hello, World!');
	$('#aj-buttons').load('/custom/aja/mmbutton.asp', {id:iLayoutID, lo:iif(bLo,'1','0'), cnt:iCount, cls:sClass }, function(){
	
	});	
}

function mmButtonsTarget( iLayoutID, bLo, iCount, sClass, sTarget )
{
	iCount = iif( iCount, iCount, -1)
	
	$(sTarget).load('/custom/aja/mmbutton.asp', {id:iLayoutID, lo:iif(bLo,'1','0'), cnt:iCount, cls:sClass }, function(){
	
	});	
}


function startflownews()
{
	// select #flowplanes and make it scrollable. use circular and navigator plugins
	$("#flowpanes").scrollable({ circular: true, mousewheel: true }).navigator({

		// select #flowtabs to be used as navigator
		navi: "#flowtabs",

		// select A tags inside the navigator to work as items (not direct children)
		naviItem: 'a',

		// assign "current" class name for the active A tag inside navigator
		activeClass: 'current',

		// make browser's back button work
		history: true

	});
}

var ajCalWidth = 269;
var ajCalOwner = '%2fcals%2fdefault%2easp';

function loadCal( date )
{  
	jQuery('#aj-calloader').removeClass("hide");
	jQuery('#aj-calwrapper').fadeOut('fast').load('custom/0000/aja/calendar/smallcalendar.asp', {smalldate: date, width: ajCalWidth, owner: ajCalOwner }, function(){
		jQuery('#aj-calloader').addClass("hide");
		jQuery('#aj-calwrapper').fadeIn('fast');
	});	
}




/////////////////////////////////////////////////////////////
//
//   Jquery Slideshow made awesome by Stu
//
////////////////////////////////////////////////////////////
function initHomepage(date, width, owner) {
    if (width) ajCalWidth = width;
    if (owner) ajCalOwner = owner;
    loadCal(date);


    $('#slide-photo').load('/custom/aja/hp-slider.asp', { id: 5, cnt: -1 }, function () {
        slideShow();
    });

    $(".scrollable").scrollable().navigator();



    //	if($.support.opacity) // not i.e. currently
    //		$('#content div.overlay').fadeIn(1500);
    //	else
    //		$('#content div.overlay').show();
}

var galleryTimer = null;
var transition = false;

function slideShow() {

    //transition = true;
    $('a#slide-rt').click(function (e) {
        if (galleryTimer > 0) clearTimeout(galleryTimer);
        //alert('hello');
        e.preventDefault();
        if (!transition) galeryNext();
    });

    $('a#slide-lt').click(function (e) {
        if (galleryTimer > 0) clearTimeout(galleryTimer);
        //alert('hello');
        e.preventDefault();
        if (!transition) galeryPrev();
    });

    //Set the opacity of all images to 0
    $('#gallery a').css({ opacity: 0.0 });

    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({ opacity: 1.0 });

    //Set the caption background to semi-transparent
    $('#slide-wrapper .caption').css({ opacity: 0.8 });

    //Resize the width of the caption according to the image width
    //  $('#slide-wrapper .caption').css({ width: $('#gallery a').find('img').css('width') });

    //Get the caption of the first image from REL attribute and display it
    $('#slide-wrapper .content').html($('#gallery a:first').find('img').attr('rel'))
    //.animate({ opacity: 0.7 }, 400, "linear", function () { transition = false; });

    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    galleryTimer = setTimeout('galeryNext()', 6000);


}

function galeryNext() {
    transition = true;
    if (galleryTimer > 0) clearTimeout(galleryTimer);

    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show') ? $('#gallery a.show') : $('#gallery a:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#gallery a:first') : current.next()) : $('#gallery a:first'));

    //Get next image caption
    var caption = next.find('img').attr('rel');

    //Set the fade in effect for the next image, show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000, "linear", function () { transition = false; })
	.removeClass('show');

    //Set the opacity to 0 and height to 1px
    //$('#slide-wrapper .caption').animate({ opacity: 0.0 }, { queue: false, duration: 0 }).animate({ height: '1px' }, { queue: true, duration: 300 });

    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
    //$('#slide-wrapper .caption').animate({ opacity: 0.7 }, 100).animate({ height: '100px' }, 500);

    //Display the content
    $('#slide-wrapper .content').html(caption);

    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    galleryTimer = setTimeout('galeryNext()', 6000);

}

function galeryPrev() {
    transition = true;
    if (galleryTimer > 0) clearTimeout(galleryTimer);

    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show') ? $('#gallery a.show') : $('#gallery a:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.prev().length) ? ((current.prev().hasClass('caption')) ? $('#gallery a:last') : current.prev()) : $('#gallery a:last'));


    //Get next image caption
    var caption = next.find('img').attr('rel');

    //Set the fade in effect for the next image, show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000, "linear", function () { transition = false; })
	.removeClass('show');

    //Set the opacity to 0 and height to 1px
    //$('#slide-wrapper .caption').animate({ opacity: 0.0 }, { queue: false, duration: 0 }).animate({ height: '1px' }, { queue: true, duration: 300 });

    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
    //$('#slide-wrapper .caption').animate({ opacity: 0.7 }, 100).animate({ height: '100px' }, 500);

    //Display the content
    $('#slide-wrapper .content').html(caption);

    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    galleryTimer = setTimeout('galeryPrev()', 6000);

}
///////////////////
//End of Slideshow
//////////////////






function initNivo()
{
	
	$('#slider-wrap').load('/custom/aja/nivo-slide.asp', {id: 5, cnt:-1 }, function(){
		//alert('hello');
		$('#slider').nivoSlider({
			effect:'sliceDown', //Specify sets like: 'fold,fade,sliceDown'
			slices:15,
			animSpeed:500, //Slide transition speed
			pauseTime:6000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:true, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:false, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	
	});	
}



function initGlobalVillageHome(iMediaID) {

    $('#slider-wrap').load('/custom/aja/nivo-slide.asp', { id: iMediaID, cnt: -1 }, function () {
        //alert('hello');
        $('#slider').nivoSlider({
            effect: 'sliceDown', //Specify sets like: 'fold,fade,sliceDown'
            slices: 15,
            animSpeed: 500, //Slide transition speed
            pauseTime: 6000,
            startSlide: 0, //Set starting Slide (0 index)
            directionNav: true, //Next & Prev
            directionNavHide: true, //Only show on hover
            controlNav: false, //1,2,3...
            controlNavThumbs: false, //Use thumbnails for Control Nav
            controlNavThumbsFromRel: false, //Use image rel for thumbs
            controlNavThumbsSearch: '.jpg', //Replace this with...
            controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
            keyboardNav: true, //Use left & right arrows
            pauseOnHover: true, //Stop animation while hovering
            manualAdvance: false, //Force manual transitions
            captionOpacity: 0.8, //Universal caption opacity
            beforeChange: function () { },
            afterChange: function () { },
            slideshowEnd: function () { } //Triggers after all slides have been shown
        });

    });
}




// init Homepage
function initLibraryHomepage( date, width, owner )
{
	if( width )	ajCalWidth = width;
	if( owner ) ajCalOwner = owner;
	loadCal( date );
	

	$('#slider-wrap').load('/custom/aja/nivo-slide.asp', {id:9, cnt:-1 }, function(){
		$('#slider').nivoSlider({
				effect:'random', //Specify sets like: 'fold,fade,sliceDown'
				slices:15,
				animSpeed:500, //Slide transition speed
				pauseTime:8000,
				startSlide:0, //Set starting Slide (0 index)
				directionNav:true, //Next & Prev
				directionNavHide:true, //Only show on hover
				controlNav:false, //1,2,3...
				controlNavThumbs:false, //Use thumbnails for Control Nav
				controlNavThumbsFromRel:false, //Use image rel for thumbs
				controlNavThumbsSearch: '.jpg', //Replace this with...
				controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
				keyboardNav:true, //Use left & right arrows
				pauseOnHover:true, //Stop animation while hovering
				manualAdvance:false, //Force manual transitions
				captionOpacity:0.8, //Universal caption opacity
				beforeChange: function(){},
				afterChange: function(){},
				slideshowEnd: function(){} //Triggers after all slides have been shown
			});
	
	});	

	$(".scrollable").scrollable().navigator();
	


//	if($.support.opacity) // not i.e. currently
//		$('#content div.overlay').fadeIn(1500);
//	else
//		$('#content div.overlay').show();
}

// init Fire Homepage
function initFireHomepage( date, width, owner )
{
	if( width )	ajCalWidth = width;
	if( owner ) ajCalOwner = owner;
	loadCal( date );
	

	$('#slider-wrap').load('/custom/aja/nivo-slide.asp', {id:11, cnt:-1 }, function(){
		$('#slider').nivoSlider({
				effect:'random', //Specify sets like: 'fold,fade,sliceDown'
				slices:15,
				animSpeed:500, //Slide transition speed
				pauseTime:4000,
				startSlide:0, //Set starting Slide (0 index)
				directionNav:true, //Next & Prev
				directionNavHide:true, //Only show on hover
				controlNav:false, //1,2,3...
				controlNavThumbs:false, //Use thumbnails for Control Nav
				controlNavThumbsFromRel:false, //Use image rel for thumbs
				controlNavThumbsSearch: '.jpg', //Replace this with...
				controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
				keyboardNav:true, //Use left & right arrows
				pauseOnHover:true, //Stop animation while hovering
				manualAdvance:false, //Force manual transitions
				captionOpacity:0.8, //Universal caption opacity
				beforeChange: function(){},
				afterChange: function(){},
				slideshowEnd: function(){} //Triggers after all slides have been shown
			});
	
	});	

	$(".scrollable").scrollable().navigator();
	


//	if($.support.opacity) // not i.e. currently
//		$('#content div.overlay').fadeIn(1500);
//	else
//		$('#content div.overlay').show();
}


function initCatalogSearch()
{
	$("#content .spanish").hide();

	// select #flowplanes and make it scrollable. use circular and navigator plugins
	$("#content a.cat-espanol").click( function(){
		//if(event.preventDefault) event.preventDefault();
		$("#content .english").hide();
		$("#content .spanish").show();
	
	});

	$("#content a.cat-english").click( function(){
		//if(event.preventDefault) event.preventDefault();
		$("#content .english").show();
		$("#content .spanish").hide();
	});

	$("#content a.kid-espanol").click( function(){
		//if(event.preventDefault) event.preventDefault();
		$("#content .english").hide();
		$("#content .spanish").show();
	
	});

	$("#content a.kid-english").click( function(){
		//if(event.preventDefault) event.preventDefault();
		$("#content .english").show();
		$("#content .spanish").hide();
	});

}


function initAlertMarque()
{

	// on DOM ready
	//$(document).ready(function (){
	//alert( 'initMarque' );

	// on DOM ready
		$(".marquee").marquee({
			loop: -1
			// this callback runs when the marquee is initialized
			, init: function ($marquee, options){
				debug("init", arguments);
				// shows how we can change the options at runtime
				if( $marquee.is("#marquee2") ) options.yScroll = "bottom";
			}
			// this callback runs before a marquee is shown
			, beforeshow: function ($marquee, $li){
				debug("beforeshow", arguments);

				// check to see if we have an date in the message (used in #marquee6)
				var $date = $li.find(".date");
				// move date from the item marquee-date layer and then fade it in
				if( $date.length ){
					$("#marquee-date").html("<span style='display:none;'>" + $date.html() + "</span>").find("> span").fadeIn(850);
				}
			}
			// this callback runs when a has fully scrolled into view (from either top or bottom)
			, show: function (){
				debug("show", arguments);
			}
			// this callback runs when a after message has being shown
			, aftershow: function ($marquee, $li){
				debug("aftershow", arguments);

				// find the date
				var $date = $li.find(".date");
				// hide the date
				if( $date.length ) $("#marquee-date").find("> span").fadeOut(250);
			}
		});
	//});

}

function FadeInBigPicture( spd, opp )
{
	// set the div to document height and fade in to create a nice effect
	
	$('div#big-picture').height($(document).height()).fadeTo(spd, opp);
}

function ResizeInnerData( sObj )
{
	//AddTosjQueryFunctions("$('td#" & sMyContentStyle & " div.inner-data').height( $('td#" & sMyContentStyle & "').height()-44);")
	var ih = $( sObj + ' div.inner-data').height();
	var oh = $( sObj).height()-40;
	
	//alert( ih + ' ' + oh )

	if(oh > ih) {
		$( sObj + ' div.inner-data').height(oh);
	}
	
}

function initSignup(sDefault)
{
	$('#newsletter-signup #frmEmailSignup').validate({
			debug: false,
			showErrors: function(errorMap, errorList){
				var i, length = errorList.length;
				var el;
				
				if( length > 0 ) {
					$('#newsletter-signup div.indicator').removeClass('yes');
					$('#newsletter-signup div.indicator').addClass('no');
					$('#newsletter-signup input:text:visible:first').focus();
				}
				else {
					$('#newsletter-signup div.indicator').removeClass('no');
					$('#newsletter-signup div.indicator').addClass('yes');
				}
				
        
			}
		});
			
	$('#newsletter-signup a.send').click( function(event) {
		event.preventDefault();
		$('#newsletter-signup #frmEmailSignup').submit();
	});
	$('#newsletter-signup #frmEmailSignup input[name=email-setup]').focus( function(event) {
			event.preventDefault();
			if( $(this).val() == sDefault ){
				$(this).val('');
			}
	});

}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

var use_debug = false;

function debug(){
	//if( use_debug && window.console && window.console.log ) console.log(arguments);
	//alert(arguments);
}


