﻿/*
--------------------------------------------------------------------------------
 Holder for Misc $ Functions
--------------------------------------------------------------------------------
*/
function iif( b, v1, v2 )
{
	return ((b)? v1: v2);	
}
function bitset( b )
{
	return ((b) ? 1: 0);
}

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)
  var cb = (new Date).valueOf();
  //$(sTarget).html('loading...');
  //alert(cb);
	$(sTarget).load('/custom/aja/mmbutton.asp', {id:iLayoutID, lo:iif(bLo,'1','0'), cnt:iCount, cls:sClass, cb: cb }, function(){
	
	});	
}

function mmSocialLinks( iLayoutID, bLo, iCount, sClass, sTarget )
{
	iCount = iif( iCount, iCount, -1)
	$(sTarget).html('loading...');
	$(sTarget).load('/custom/aja/mmsociallinks.asp', {id:iLayoutID, lo:iif(bLo,'1','0'), cnt:iCount, cls:sClass }, function(){
	});	
}

function mmDescription( iLayoutID, bLo, iCount, sClass, sTarget )
{
	iCount = iif( iCount, iCount, 1)
	$(sTarget).load('/custom/aja/mmdescription.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 = 249;
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');
	});	
}

// init Homepage
function initHomepage( date, width, owner )
{
	if( width )	ajCalWidth = width;
	if( owner ) ajCalOwner = owner;
	loadCal( date );
}

// 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);
}


var use_debug = false;

function debug(){
	//if( use_debug && window.console && window.console.log ) console.log(arguments);
	//alert(arguments);
}


