﻿
function initFilter(){

	init(); //thing
	if( document.cookie.indexOf("Preview_currFilter")!=-1 ){
		filter = getCookie("Preview_currFilter");
	}
	if( document.cookie.indexOf("Preview_currPage")!=-1  ){
		page = getCookie("Preview_currPage");
	}
	//remember prior position if cookie is set
	if( page!=1 ) eval( "StoryPacks_"+filter+".moveTo(0,"+(((page-1)*649)*-1)+")" );
	
	setFilter( filter, page, false );
	
}

function setFilter( filter, page, resetAll ){

	//set filter cookie, reset page cookie
	document.cookie = 'Preview_currFilter='+filter;
	document.cookie = 'Preview_currPage='+page;
	//set tabs
    clearFilterTabs();
   
    $(filter+"Filter").addClass('blogNavItemOn');
    
    if( resetAll ){
		for( var i=0; i<tabs.length; i++ ){ //reset all StoryPacks_ divs
			tabName = eval( "StoryPacks_" +tabs[i]);
			tabName.moveTo(0,0);
			
		}
    }
	//show features
	callNewTrackEvent(filter);
	showFeatures( filter, page );
	return false;
}


function showFeatures( filter, page ){
	for( var i=0; i<tabs.length; i++ ){ //hide all StoryPacks_ divs
		myTab = eval( "StoryPacks_" +tabs[i]);
		myTab.hide();	
	}
	
	eval( "StoryPacks_" + filter + ".show()" )    
	writePagination( filter, page );
	
    return false;
}

function writePagination( filter, page ){

	var numMatches = parseInt(tabCounts[getTabPos(filter)],10);

	page = parseInt(page,10);

	
	var olderOn = '<a href="#older" class="older" onclick="return paginate(\'' + filter + '\',\'' + (page+1) + '\')">' + blogNavOlder + '</a>';
    var newerOn = '<a href="#newer" class="newer" onclick="return paginate(\'' + filter + '\',\'' + (page-1) + '\')">' + blogNavNewer + '</a>';
    var older = ( page >= numMatches/4 ) ? '<a class="older olderOff">' + blogNavOlder + '</a>' : olderOn;
    var newer = ( page == 1 ) ? '<a class="newer newerOff">' + blogNavNewer + '</a>' : newerOn;
    $("blogPagination").innerHTML = '' + older + newer;
}

function getTabPos( filter ){
	var pos = null;
	for( var i=0; i<tabs.length; i++ ) if( tabs[i] == filter ) pos = i;
	return pos;
}

function paginate( filter, page ){
	page = parseInt(page,10);
	if( page == 0 ) page = 1;
    document.cookie = 'Preview_currPage=' + page;
    writePagination( filter, page );
    eval("StoryPacks_" + filter + ".slideTo( 0,(649*(page-1))*-1, 10, 80, 10 );");
    return false;
}

function clearFilterTabs(){

    for( var i=0; i<tabs.length; i++ ){
        el = $(tabs[i]+"Filter");
        if( el.className != "blogNavItem" ) el.className = "blogNavItem";
        $(tabs[i]+"Filter");
    }
}

window.addEvent('load', function() {
	
	var ffHeight = 180;
	var ieHeight = 174;
    var myEffect = new Fx.Morph('hotlineCalendar', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
    var myEffect2 = new Fx.Morph('hotline', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
    
    if($('hotlineCalendar')) var newHeight = $('hotlineCalendar').scrollHeight; 
    var outerNewHeight = newHeight+200;    
    
	$('moreButton').addEvent('click',function(event) {
		event = new Event(event).stop();
	    if(Browser.Engine.trident){
			myEffect.start({
				'height': [174, newHeight] //Morphs the 'height' style from 190px to new height.
			});
		}else{
			myEffect.start({
				'height': [180, newHeight] //Morphs the 'height' style from 190px to new height.
			});
		}
         myEffect2.start({
            'height': [newHeight, outerNewHeight] //Morphs the 'height' style from 360px to new height.
        });
        $('moreButton').setStyle('display', 'none');
        $('lessButton').setStyle('display', '');
	});

	
	$('lessButton').addEvent('click',function(event) {
		event = new Event(event).stop();
		if(Browser.Engine.trident){
			myEffect.start({
				'height': [newHeight, 184] //Morphs the 'height' style from 190px to new height.
			});
		}else{

			myEffect.start({
				'height': [newHeight, 190] //Morphs the 'height' style from 190px to new height.
			});
		}
        myEffect2.start({
            'height': [outerNewHeight, 300] //Morphs the 'height' style from 10px to 100px.
        });
        $('moreButton').setStyle('display', '');
        $('lessButton').setStyle('display', 'none');
	});
 

 


});

		
 function showGallery( show, src ){
    var screen = document.getElementById("screen");
    var gallery = document.getElementById("gallery");
    var galleryFrame = document.getElementById("galleryFrame");
    if( show ){
        galleryFrame.src = src;
        gallery.style.top = document.body.scrollTop + 30;
        screen.style.visibility = 'visible';
        gallery.style.visibility = 'visible';
    }
    else{
        gallery.style.visibility = 'hidden';
        galleryFrame.src = 'about:blank';
        screen.style.visibility = 'hidden';
    }
    return false;
}

function getCookie(c_name){

    if (document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1){ 
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}


/* thing... */
var JS_PATH = "/js/";

/********************************************************************************

	Misc. User Agent setup and debug functions

********************************************************************************/
//	use( string )includes ancilliary thing class files that aren't loaded by default:
//	thing.clip, thing.mouse, thing.sequence, thing.slide, thing.unroll, thing.write
function use( what ){
	what = what.toLowerCase();
	if( ! usedFiles[what] )
		document.write( '<script language="javascript" src="' + JS_PATH + what + '.js"></script>\n' );
	usedFiles[ what ] = true;
}
var usedFiles = new Array();    

window.origInit = window.init;
if( window.origInit == null ) window.origInit = function(){}
init = function( fcn ){
	if( ! window.initFunctions )
		window.initFunctions = new Array();
	if( typeof(fcn) == "string")
		window.initFunctions[ window.initFunctions.length ] = fcn;
	else{
		origInit();
		for( var i=0; i<window.initFunctions.length; i++ ){
			eval(window.initFunctions[i]);
		}
	}
}
onload=init


function Is(){
	var appName = navigator.appName;
	var version = navigator.appVersion;
	
	this.ns = ( appName == "Netscape" );
	this.ns4 = this.ns && version.indexOf("4.")!=-1;
	this.ns5 = this.ns && version.indexOf("5.")==0;
	this.ns6 = ( this.ns5 || (this.ns && version.indexOf("6.")!=-1) );

	this.ie = ( appName == "Microsoft Internet Explorer" );
	this.ie4 = this.ie && version.indexOf("MSIE 4.")!=-1;
	this.ie5 = this.ie && version.indexOf("MSIE 5.")!=-1;
	this.ie6 = this.ie && version.indexOf("MSIE 6.")!=-1;
	this.ie7 = this.ie && version.indexOf("MSIE 7.")!=-1;
	
	var userAgent = navigator.userAgent.toLowerCase()
	this.mac = ( userAgent.indexOf( "mac" ) != -1 )
	this.win = ( userAgent.indexOf( "windows" ) != -1 )
	this.linux = ( userAgent.indexOf( "linux" ) != -1 )
}
Is.prototype.toString = function(){
	var s = ''
	for( var i in this ){
		s += i + ': ' + this[i] + '\n'
	}
	return s;
}
var is = new Is();

//resize fix for netscape 4
function resize(){
		if ( scrW != window.innerWidth || scrH != window.innerHeight )
			location.reload()
}
if ( is.ns4 ){
	var scrW = window.innerWidth;
	var scrH = window.innerHeight;
	onresize=resize;
}

/********************************************************************************

	Point Objects

********************************************************************************/
function Point( /* x,y or p */ ){
	if( Point.isPoint(arguments[0]) ){
		this.x = arguments[0].x;
		this.y = arguments[0].y;
	}
	else{
		this.x = arguments[0];
		this.y = arguments[1];
	}
}
Point.isPoint = function(what){
	return ( what.constructor == Point );
}
Point.prototype.getArgs = function( /* [[x,y]] or [[p]] */ ){
	return new Point( arguments[0][0], arguments[0][1] )
}

Point.prototype.add = function( /* x,y or p */ ){
	var that = this.getArgs( arguments )
	return new Point( this.x + that.x, this.y + that.y );
}
Point.prototype.sub = function( /* x,y or p */ ){
	var that = this.getArgs( arguments )
	return new Point( this.x - that.x, this.y - that.y );   
}
Point.prototype.mult = function( mult ){    
	return new Point( mult * this.x, mult * this.y);
}
Point.prototype.perp = function(){
	return new Point( - this.y, this.x )
}
Point.prototype.distTo = function( /* x,y or p */ ){
	var that = this.getArgs( arguments )
	var dx = this.x - that.x;
	var dy = this.y - that.y;
	if( dx == 0 ) return Math.abs(dy);
	if( dy == 0 ) return Math.abs(dx);
	return Math.sqrt( dx*dx + dy*dy );
}
Point.prototype.size = function(){
	var p = new Point(0,0);
	return this.distTo( p )
}
Point.prototype.toString = function(){
	return '(' + this.x + ', ' + this.y + ')';
}
Point.prototype.isInRect = function( t, r, b, l ){
	return ( this.y > t && this.x < r && this.y < b && this.x > l );
}

function Rect( t, r, b, l ){
	this.t = t; 
	this.r = r;
	this.b = b;
	this.l = l;
}
Rect.prototype.toString = function(){
	return "(" + this.t + ", " + this.r + ", " + this.b + ", " + this.l + ")";
}


/********************************************************************************

	Thing Class

	Initialization
		Thing.init()                  -- looks through document & gets all divs ending in "Div"
	                                     adds that to the Thing.all array without the "Div"
	Member Variables
		myThing.name                   -- "myThing"
		myThing.id                     -- "myThingDiv"
		myThing.div                    -- the actual html object
		myThing.style                  -- the style of the object
		myThing.position               -- a Point with the thing's position
		myThing.size                   -- a Point with the thing's size

********************************************************************************/
init( "Thing.init()" ); 

function Thing( div ){

	this.id = div.id;
	this.name = div.id.replace(/ThingDiv/, "");
	

	this.div = div;
	this.style = ( is.ns4 ) ? this.div : this.div.style;

	this.position = this.getPosition();
	this.size = this.getSize();
}

Thing.add = function( div ){
	var name = div.id.slice(0, -8);
	if( div.id == name + "ThingDiv" ){
		Thing.all[ name ] = new Thing( div );
		eval( name + " = Thing.all." + name );
	}
}
Thing.all = new Array();
Thing.init = function( doc ){
	this.isLoaded = true;
	if( document.layers ){
		if( doc == null ) doc = document;
		for( var i=0; i<doc.layers.length; i++ ){
			Thing.add( doc.layers[i] );
			Thing.init( doc.layers[i].document );
		}
		return true;
	} 

	
	var allD = false;
	if( is.ie4 ) allD = document.all.tags("DIV")
	else if( is.ie5 || is.ie6 || is.ie7 ) allD = document.getElementsByTagName("DIV");
	else if( is.ns6 ) allD = document.getElementsByTagName("DIV");
	
	if( allD ){
		for( var i=0; i<allD.length; i++ )
			Thing.add( allD[i] );
		return true;
	}
	return false;
}

/********************************************************************************

	Style Initialization

		Point      myThing.getPosition();   -- set this.position and return it
		Point      myThing.getSize();       -- set this.size and return it
		
********************************************************************************/
if( is.ns4 )
	Thing.prototype.getPosition = function(){
		this.position = new Point(
			parseInt(this.style.left),
			parseInt(this.style.top)
		);
		return this.position;
	}
else
	Thing.prototype.getPosition = function(){
		this.position = new Point(
			parseInt(this.div.offsetLeft),
			parseInt(this.div.offsetTop)
		);
		return this.position;
	}
	
if( is.ns4 )
	Thing.prototype.getSize = function(){
		this.size = new Point(
			this.div.document.width,
			this.div.document.height 
		);
		return this.size;
	}
else if( is.ie4 )
	Thing.prototype.getSize = function(){
		this.size = new Point(
			parseInt( this.div.scrollWidth ), 
			parseInt( this.div.scrollHeight )
		);
		return this.size;
	}
else
	Thing.prototype.getSize = function(){
		this.size = new Point(
			parseInt(this.div.offsetWidth),
			parseInt(this.div.offsetHeight)
		);
		this.style.offsetWidth = this.size.x;
		this.style.offsetHeight = this.size.y;
		return this.size;
	}

/********************************************************************************

	Position Manipulation
	
		myThing.setPosition()          -- updates the html object to match the position
		                                  called by moveTo, moveBy, etc
		myThing.moveTo(p)              -- move to point
		myThing.moveTo(x,y)            -- move to specified location
		myThing.moveBy(p)              -- move by point values
		myThing.moveBy(x,y)            -- move by specified increments

********************************************************************************/
	Thing.prototype.setPosition = function(){
		this.style.left = this.position.x;
		this.style.top = this.position.y;
	}
	Thing.prototype.moveTo = function( /*x,y or p*/ ){
		this.position = new Point( arguments[0], arguments[1] )
		this.setPosition();
	}
	Thing.prototype.moveBy = function( /*x,y or p*/ ){
		this.position = this.position.add( arguments[0], arguments[1] )
		this.setPosition();
	}

/********************************************************************************

	Visibility Manipulation
	
		myThing.show()                 -- show the div
		myThing.hide()                 -- hide the div
		myThing.isVisible()            -- return true if visible, false if not
		myThing.toggle()               -- hide if visible, show if not
		
********************************************************************************/

	Thing.prototype.show = function(){
		this.style.visibility = "visible";
		this.style.display = "";
	}
	Thing.prototype.hide = function(){
		this.style.visibility = "hidden";
		this.style.display="none";
	}
	Thing.prototype.isVisible = function(){
		return ( this.style.visibility.indexOf("d") == -1 );
	}
	Thing.prototype.toggle = function(){
		return ( this.isVisible() ) ? this.hide() : this.show();
	}
	
/********************************************************************************

	Miscellaneous Manipulation
	
		myThing.setBackground( color ) -- set the bgcolor to "color"		

		myThing.getZindex()            -- get the zIndex
		myThing.setZindex( n )         -- set the zIndex to n

********************************************************************************/
if ( is.ns4 )   
	Thing.prototype.setBackground = function( color ){
		this.div.document.bgColor=color;
	}
else
	Thing.prototype.setBackground = function( color ){
		this.style.backgroundColor = color;
	}
	
	Thing.prototype.setZindex = function( n ){
		this.style.zIndex = n;
	}

/********************************************************************************	
 	Image Flip usage : 
 		Change OFF_SUFFIX and ON_SUFFIX to match image names.
 		
 		For each image which is to be flipped, document.onload should call
 			flip.myFlipName = new Flip( myImageName, myImageSource )
 		To turn image on, call 
 			flip.myFlipName.on()
 		To turn image off, call
 			flip.myFlipName.off()
********************************************************************************/
init( "Flip.init()" )
var IMAGE_OFF_SUFFIX = ".gif"
var IMAGE_ON_SUFFIX = "_on.gif"

var flip = new Array();
function Flip( imgName, imgSrc, doc ){
	this.docImg = getDocImg(imgName, doc);
	if( this.docImg ){
		this.imgOff = new Image( this.docImg.width, this.docImg.height )
		this.imgOffsrc = this.imgOff.src = this.docImg.src;
		
		this.imgOn = new Image ( this.docImg.width, this.docImg.height )
		this.imgOnsrc = this.imgOn.src = ( imgSrc != null ) ? imgSrc : this.docImg.src.replace( IMAGE_OFF_SUFFIX, IMAGE_ON_SUFFIX )	}
	else{
		this.imgOff = this.imgOn = new Image();
		this.imgOffSrc = this.imgOnSrc = '';
	}
}

Flip.prototype.on = function(force){
	if( force ){
		this.imgOn.src = "";
		this.docImg.src = this.imgOnsrc;
	}
	else if( this.imgOn.src ){
			this.docImg.src = this.imgOn.src;
	}
	if ( this.status )
		window.status = this.status;
	return true;
}

Flip.prototype.off = function(force){
	if( force ){
		this.imgOff.src = "";
		this.docImg.src = this.imgOffsrc;
	}
	else if( this.imgOff.src ){
		this.docImg.src = this.imgOff.src;
	}
	window.status = "";
	return true;
}
Flip.prototype.killFlip = function( newSrc ){
	var fixedImgSrc
	if ( newSrc == "on" )
		fixedImgSrc = this.imgOn.src
	else if ( newSrc == "off" )
		fixedImgSrc = this.imgOff.src
	else
		fixedImgSrc = newSrc
	this.imgOff.src = this.imgOn.src = this.docImg.src = fixedImgSrc;
}
Flip.prototype.resurect = function(){
	this.imgOff.src = this.imgOffsrc;
	this.imgOn.src = this.imgOnsrc;
	this.docImg.src = this.imgOffsrc;
}
function getDocImg(name, d){
	d = ( d == null ) ? document : d; //set d to be the document if empty
	var img = d.images[name];
	if (img) return img; //found it
	
	if ( ! document.layers ) return null; //in ie, we die here
	
	for ( var i=0; i < d.layers.length; i++ ) 
		if ( d.layers[i].id ){
			img = getDocImg( name, d.layers[i].document )  //recursive call
				if (img) return img; //found it
		}
	return null; //did not find it
}
function mouseover(name){
	if (flip[name])
		flip[name].on()
}
function mouseout(name){
	if (flip[name])
		flip[name].off()
}
Flip.init = function( d ){
	if( d == null ) d = document;
	for ( var i = 0; i < d.images.length; i++ ){
		var src = d.images[i].src
		if ( d.images[i].name ){
			if ( src.indexOf( IMAGE_OFF_SUFFIX ) != -1 ){
				flip[ d.images[i].name ] = new Flip( d.images[i].name, null, d )
			}
		}
	}
	if ( !document.layers ) return;
	for ( var i=0; i < d.layers.length; i++ ) 
		Flip.init( d.layers[i].document )  //recursive call
}
/********************************************************************************

	write   

********************************************************************************/
Thing.prototype.write = function(meat){ 
	if (is.ns4) {
		tableOpen = '<table border="0" cellpadding="0" cellspacing="0" width="'+ this.size.x +'"><tr valign="top"><td>';
		tableClose = '</td></tr></table>';
		this.div.document.open();
		this.div.document.write(tableOpen + meat + tableClose);
		this.div.document.close();
	} else {
		this.div.innerHTML = meat;
	}
}   

/********************************************************************************
    
	slide

********************************************************************************/
var SLIDE_DEFAULT_DT = 15;
var SLIDE_DEFAULT_CURVE = 0;
var SLIDE_DEFAULT_SPEED = 8;

Thing.prototype.slideTo = function( x, y, speed1, speed2, speed3, dt, curve ){
	if( x == null || y == null ) return;
	this.pEnd = new Point( x,y );
	this.dt = (dt) ? dt : SLIDE_DEFAULT_DT;
	this.curve = (curve) ? curve : SLIDE_DEFAULT_CURVE;
	
	var direction = this.pEnd.sub(this.position);
	this.totDist = direction.size();

	this.speed1 = ( speed1 != null ) ? speed1 : SLIDE_DEFAULT_SPEED;
	
	if( speed2 != null ){
		if( speed3 != null ){ 
			//gave all three
			this.speed2 = speed2;
			this.speed3 = speed3;
		}
		else{
			//gave 1 & 2
			this.speed3 = speed2;
			this.speed2 = (this.speed1 + this.speed3)/2;
		}
	}
	else{
		// gave only 1
		if( this.speed1 == 0 ){
			this.moveTo( pEnd );
			this.onSlideEnd();
		}
		else{
			this.speed3 = this.speed2 = this.speed1;
		}
	}
	this.slideStep();
}
Thing.prototype.slideBy = function( dx, dy, speed1, speed2, speed3, dt, curve ){
	this.slideTo( this.position.x + dx, this.position.y + dy, speed1, speed2, speed3, dt, curve  )
}
Thing.prototype.slideStep = function(){

	var direction = this.pEnd.sub(this.position);
	var dist = direction.size();
	direction = direction.mult( 1/dist );
	
	// figure out speed
	var progress = 2 * ( this.totDist - dist ) / this.totDist;
	var perp = direction.perp();
	
	if( progress < 1 ){
		var speed = this.speed1 * (1 - progress) + this.speed2 * (progress);
		perp = perp.mult( (progress) * this.curve )
	}
	else if( progress < 2 ){
		progress = progress - 1
		var speed = this.speed2 * (1 - progress) + this.speed3 * (progress);
		perp = perp.mult( (1 - progress) * this.curve )		
	}
	if( progress > 2 || speed >= dist || dist < 3 ){
		this.moveTo( this.pEnd );
		return this.onSlideEnd();	
	}
	direction = direction.mult( speed );
	this.moveBy( direction.add(perp) );
	
	this.slideTimeout = setTimeout( "Thing.all." + this.name + ".slideStep()", this.dt )
}
Thing.prototype.killSlide = function( finish ){
	clearTimeout( this.slideTimeout );
	if( finish ) this.moveTo( this.pEnd )
}
// overwrite me
Thing.prototype.onSlideEnd = function(){}
