
	var $anim = Array( 'rl', 'bt', 'lr', 'tb', 'rl');
	var $count = 0;
	var $flipState = false;
	var $t;

function doFlip(){
	$("#flipBox").flip({ 
		direction: $anim[$count%$anim.length], 
		color: '#a8adb3', 
		content: $comment[$count], 
		onEnd: function(){$count = ++$count%$comment.length; if($count == 0){$flipState = false;} if($flipState){ $t = setTimeout("doFlip()",6000);} } 
	}); 
}

function doForm($log){
	
	if($('div#hide_button').is(':hidden')){
		$("div#panel").animate({ height: "350px"});
		$("div.panel_button").toggle();
		if($log){
			// pageTracker
		}
	}
	else{
		$("div#panel").animate({height: "0px"}, "fast");
		$("div.panel_button").toggle();
	}
}

$(document).ready(function()
{
	slide("#nav", 25, 15, 180, .6);
	//changeContent($default);
	
	$("#services").ticker({
 		rate:        10,
 		delay:       3000
	}).trigger("play");

	
	$("div.panel_button").click(function(){
			doForm("boxClick");
	});	
	
   $("div#hide_button").click(function(){
		$("div#panel").animate({height: "0px"}, "fast");
   });	

	$("#flipBox").click(function(){
			if($flipState){
				$flipState = false;
				clearTimeout($t);
			}
			else{
				$flipState = true;
				doFlip();
			}
	});
	
	$("#contact").click(function(){
		doForm("menuClick");
	});

});

function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		$(this).css("margin-left","-820px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "0" }, timer*4);
		$(this).animate({ marginLeft: "15px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});
	});
}


(function($) {
var getTransparent, parent, pBg;
getTransparent = function(el){
		for(var n=0;n<el.parents().length;n++){
		parent = el.parents().get(n);
		pBg = $.browser.safari ? $(parent).css("background") : $(parent).css("background-color");
		if(pBg!='' && pBg!='transparent'){
			return pBg;
		}
	}
}

function int_prop(fx){ 
	fx.elem.style[ fx.prop ] = parseInt(fx.now) + fx.unit; 
} 
jQuery.extend( jQuery.fx.step, {
  borderTopWidth : int_prop,
  borderBottomWidth : int_prop,
  borderLeftWidth: int_prop,
  borderRightWidth: int_prop
});
	
jQuery.fn.flip = function(settings){
	return this.each( function() {
		
		var $this, flipObj, cloneId, dirOptions, _self, newContent;
		
		$this = $(this);
		if($this.data('flipLock')){
			return false;
		} else {
			$this.data('flipLock',1);	
		};
		
		flipObj = {
			width: $this.width(),
			height: $this.height(),
			bgColor: settings.bgColor || $this.css("background-color"),
			fontSize: $this.css("font-size") || "12px",
			direction: settings.direction || "tb",
			toColor: settings.color || "#f00",
			speed: settings.speed || 500,
			top: $this.offset().top,
			left: $this.offset().left,
			target: settings.content || null,
			transparent: getTransparent($this) || '#fff',
			onBefore: settings.onBefore || function(){},
			onEnd: settings.onEnd || function(){},
			onAnimation: settings.onAnimation || function(){}			
		};
	
		cloneId = "flipClone_"+(new Date()).getTime();
		
		$this
			.css("visibility","hidden")
			.clone(true)
				.appendTo("body")
				.html("")
				.css({visibility:"visible",position:"absolute",left:flipObj.left,top:flipObj.top,margin:0,zIndex:9999}).attr("id",cloneId);
	
		dirOptions = {
			"tb": {
				"start": {fontSize:'0px',lineHeight:'0px',borderTopWidth:flipObj.height,borderLeftWidth:'0px',borderRightWidth:'0px',borderBottomWidth:'0px',borderTopColor:flipObj.bgColor,borderBottomColor:flipObj.transparent,borderLeftColor:flipObj.transparent,borderRightColor:flipObj.transparent,borderStyle:'solid',height:'0px',width:flipObj.width},
				"first": {borderTopWidth: '0px',borderLeftWidth: (flipObj.height/100)*15,borderRightWidth: (flipObj.height/100)*15,borderBottomWidth: '0px',borderTopColor: '#999',borderBottomColor: '#999',borderLeftColor: flipObj.transparent,borderRightColor: flipObj.transparent,top: (flipObj.top+(flipObj.height/2)),left: (flipObj.left-(flipObj.height/100)*15)},
				"second": {borderBottomWidth: flipObj.height,borderTopWidth: '0px',borderLeftWidth: '0px',borderRightWidth: '0px',borderTopColor: flipObj.transparent,borderBottomColor: flipObj.toColor,borderLeftColor: flipObj.transparent,borderRightColor: flipObj.transparent,top: flipObj.top,left: flipObj.left}
			},
			"bt": {
				"start": {fontSize:'0px',lineHeight:'0px',borderTopWidth:'0px',borderLeftWidth:'0px',borderRightWidth:'0px',borderBottomWidth:flipObj.height,borderTopColor:flipObj.transparent,borderBottomColor:flipObj.bgColor,borderLeftColor:flipObj.transparent,borderRightColor:flipObj.transparent,borderStyle:'solid',height:'0px',width:flipObj.width},
				"first": {borderTopWidth: '0px',borderLeftWidth: (flipObj.height/100)*15,borderRightWidth: (flipObj.height/100)*15,borderBottomWidth: '0px',borderTopColor: '#999',borderBottomColor: '#999',borderLeftColor: flipObj.transparent,borderRightColor: flipObj.transparent,top: (flipObj.top+(flipObj.height/2)),left: (flipObj.left-(flipObj.height/100)*15)},
				"second": {borderTopWidth: flipObj.height,borderLeftWidth: '0px',borderRightWidth: '0px',borderBottomWidth: '0px',borderTopColor: flipObj.toColor,borderBottomColor: flipObj.transparent,borderLeftColor: flipObj.transparent,borderRightColor: flipObj.transparent,top: flipObj.top,left: flipObj.left							
				}
			},
			"lr": {
				"start": {width:'0px',fontSize:'0px',lineHeight:'0px',borderTopWidth:'0px',borderLeftWidth:flipObj.width,borderRightWidth:'0px',borderBottomWidth:'0px',borderTopColor:flipObj.transparent,borderBottomColor:flipObj.transparent,borderLeftColor:flipObj.bgColor,borderRightColor:flipObj.transparent,borderStyle:'solid',height:flipObj.height},
				"first": {borderTopWidth: (flipObj.height/100)*10,borderLeftWidth: '0px',borderRightWidth: '0px',borderBottomWidth: (flipObj.height/100)*10,borderTopColor: flipObj.transparent,borderBottomColor: flipObj.transparent,borderLeftColor: '#999',borderRightColor: '#999',top: flipObj.top-(flipObj.height/100)*10,left: flipObj.left+(flipObj.width/2)},
				"second": {borderTopWidth: '0px',borderLeftWidth: '0px',borderRightWidth: flipObj.width,borderBottomWidth: '0px',borderTopColor: flipObj.transparent,borderBottomColor: flipObj.transparent,borderLeftColor: flipObj.transparent,borderRightColor: flipObj.toColor,top: flipObj.top,left: flipObj.left}
			},
			"rl": {
				"start": {width:'0px',fontSize:'0px',lineHeight:'0px',borderTopWidth:'0px',borderLeftWidth:'0px',borderRightWidth:flipObj.width,borderBottomWidth:'0px',borderTopColor:flipObj.transparent,borderBottomColor:flipObj.transparent,borderLeftColor:flipObj.transparent,borderRightColor:flipObj.bgColor,borderStyle:'solid',height:flipObj.height},
				"first": {borderTopWidth: (flipObj.height/100)*10,borderLeftWidth: '0px',borderRightWidth: '0px',borderBottomWidth: (flipObj.height/100)*10,borderTopColor: flipObj.transparent,borderBottomColor: flipObj.transparent,borderLeftColor: '#999',borderRightColor: '#999',top: flipObj.top-(flipObj.height/100)*10,left: flipObj.left+(flipObj.width/2)},
				"second": {borderTopWidth: '0px',borderLeftWidth: flipObj.width,borderRightWidth: '0px',borderBottomWidth: '0px',borderTopColor: flipObj.transparent,borderBottomColor: flipObj.transparent,borderLeftColor: flipObj.toColor,borderRightColor: flipObj.transparent,top: flipObj.top,left: flipObj.left}
			}
		};
		
		_self = $this;
		
		newContent = function(){
			var target = flipObj.target;
			return target && target.jquery ? target.html() : target;
		}
		
		function queue(_this,_self){			
			_this.queue(function(){
				flipObj.onBefore();
				_this.html('').css(dirOptions[flipObj.direction].start);
				_this.dequeue();
			});
			_this.animate(dirOptions[flipObj.direction].first,flipObj.speed);	
			_this.queue(function(){
				flipObj.onAnimation();
				_this.dequeue();
			});			
			_this.animate(dirOptions[flipObj.direction].second,flipObj.speed);
			_this.queue(function(){
				_self.css({
					backgroundColor: flipObj.toColor,
					visibility: "visible"
				});
				var nC = newContent();
				if(nC){_self.html(nC);}
				_this.remove();
				flipObj.onEnd();
				_self.removeData('flipLock');
				_this.dequeue();
			});
		}
		queue($("#"+cloneId),_self);
		
	});
  };
})(jQuery);


// jquery.ticker.js
// 0.9.1 - beta
// Stephen Band
//
// Project and documentation site:
// http://webdev.stephband.info/jticker/
//
// Dependencies:
// jQuery 1.2.3 - (www.jquery.com)
//
// Instantiate and play with:
// jQuery(element).ticker({options}).trigger("play");


(function(jQuery) {

// VAR

var name = "ticker";   // Name of the plugin

// FUNCTIONS

function indexify(i, length) {
    return (i >= length) ? indexify(i-length, length) : ((i < 0) ? indexify(i+length, length) : i) ;
}

function advanceItem(elem) {
    var data = elem.data(name);
    var length;
    for (var i=0; i<200; i++) {
        if (!data.content[i]) {length = i; break;} 
    }
    data.nextItem      = indexify((data.nextItem || 0), length);
    data.currentItem   = data.nextItem;
    data.elemIndex     = [data.currentItem];
    data.charIndex     = 0;
    data.nextItem++;
}

function makeFamily(elem) {
    var obj = {elem: elem.clone().empty()};
    var children = elem.children();
    if (children.length) {
        children.each(function(i){
            obj[i] = makeFamily(jQuery(this));
        });
        return obj;
    }
    else {
        obj.text = elem.text()
        return obj;
    }
}

function checkFamily(content, index) {
    var newIndex;
    if (content[index[0]]) {
        if (content[index[0]].text) {return content[index[0]];}
        else if (index.length == 1) {return true;}
        else {
            newIndex = jQuery.makeArray(index);
            return checkFamily(content[newIndex[0]], newIndex.splice(1, newIndex.length));
        }
    }
    else {return false;}
}  

function incrementIndex(index) {
    if (index.length > 1)   {index[index.length-1]++;
                             return index;}
    else                    {return false;}
}

function buildIndex(content, index) {
    if (index === false)    {return false;}
    var obj = checkFamily(content, index);
    if (obj === false)      {return buildIndex(content, incrementIndex(index.slice(0, index.length-1)));}
    else if (obj === true)  {index[index.length] = 0;
                             return buildIndex(content, index);}
    else                    {return index;}
}

function buildFamily(elem, content, index, data) {
    var newIndex, newElem;
    var child = elem.children().eq(index[0]);
    
    if (!index.length) {
        return {
            readout: elem,
            text: content.text
        };
    }
    else if (child.length)  {newElem = child;}
    else                    {newElem = content[index[0]].elem.appendTo(elem);}
    
    newIndex = jQuery.makeArray(index).slice(1, index.length);
    return buildFamily(newElem, content[index[0]], newIndex, data);
}

function initElem(elem) {
    var data = elem.data(name);
    jQuery("*", elem).empty();
    elem.empty();
    data.start = 0;
    data.sum = 0;
    if (data.cursorIndex) {cursorIndex = 0;}
}

function initChild(elem) {
    var data = elem.data(name);
    data.start = data.sum;
}

function ticker(elem, threadIndex, data) {
    var index, letter;
    
    // Switch cursor
    if (data.cursorIndex !== false)  {data.cursorIndex = indexify(data.cursorIndex+1, data.cursorList.length);
                                      data.cursor.html(data.cursorList[data.cursorIndex]);}
    else                             {data.cursor.html(data.cursorList);}

    // Add character to readout
    index = data.charIndex - data.start;
    letter = data.text.charAt(index-1);
    data.cursor.before(letter);
    
    if (data.charIndex >= data.sum) {
        data.cursor.remove();
        data.elemIndex = incrementIndex(data.elemIndex);
        return tape(elem, threadIndex);
    }
    else {
        return setTimeout(function(){
            if (data.eventIndex == threadIndex) {
                data.charIndex++;
                ticker(elem, threadIndex, data);
            }
            threadIndex = null;
        }, data.rate);   
    }
}

function tape(elem, threadIndex) {
    var data = elem.data(name);

    if (data.eventIndex == threadIndex) {
        
        data.elemIndex = buildIndex(data.content, data.elemIndex);
        //console.log('INDEX '+data.elemIndex);
        
        if (data.elemIndex === false) {
            return setTimeout(function(){
                if (data.running && (data.eventIndex == threadIndex)) {
                    advanceItem(elem);
                    return tape(elem, threadIndex);
                }
                threadIndex = null;
            }, data.delay);
        }
        else if (!data.charIndex)                       {initElem(elem);}
        else                                            {initChild(elem);}

        jQuery.extend(data, buildFamily(elem, data.content, data.elemIndex));
        data.sum = data.sum + data.text.length;
        data.readout.append(data.cursor);
        return ticker(elem, threadIndex, data);
    }
}

// PLUGIN DEFINITION

jQuery.fn[name] = function(options) {

    // Add or overwrite options onto defaults
    var o = jQuery.extend({}, jQuery.fn.ticker.defaults, options);

    // Iterate matched elements
    return this.each(function() {

        var elem = jQuery(this);
        
        elem
        .data(name, {
            rate:           o.rate,
            delay:          o.delay,
            content:        makeFamily(elem),
            cursor:         o.cursor,
            cursorList:     o.cursorList,
            cursorIndex:    (typeof(o.cursorList) == "object") ? 0 : false,
            nextItem:       0,
            eventIndex:     0
        })
        .bind("stop", function(e){
            var data = elem.data(name);
            data.running = false;           
        })
        .bind("play", function(e){
            var data = elem.data(name);
            data.eventIndex++;
            data.running = true;
            data.nextItem = (e.item || data.nextItem);
            advanceItem(elem);
            tape(elem, data.eventIndex);
        })
        .bind("control", function(e){
            var data = elem.data(name);
            jQuery().extend(data, {
                nextItem:   e.item,
                rate:       e.rate,
                delay:      e.delay
            });
        })
        .children()
        .remove();
    });
};

// PLUGIN DEFAULTS

jQuery.fn[name].defaults = {
    rate:           40,         // Speed to print message.
    delay:          1700,       // Pause to read message.
    cursorList:     "_",        // A string or an array of strings or jQuery objects. If an array, the cursor loops through the array.
    cursor:         jQuery('<span class="cursor" />')
}

})(jQuery);

