jQuery.fn.dropShadow = function(settings) {
	settings = jQuery.extend({
		shadowcolor: '#555656',
		ldistance: 0,
		tdistance: 1,
		iefix: false
	}, settings);
	
	if( $.browser.msie && settings.iefix){
		settings.tdistance -= 9;
	}
	
	$(this).css("position", "relative");
	var textcolor = $(this).css("color");
	var padding = $(this).css("paddingLeft");
	var lineHeight = $(this).css("line-height");
	$(this).css("color", settings.shadowcolor);
	$(this).append('<span class="the-shad">' + $(this).text() + '</span>');
		$(".the-shad", $(this) ).css({
			'left': settings.ldistance * -1,
			'top': settings.tdistance * -1,
			'position': 'absolute',
			'color': textcolor,
			'padding': padding,
			'line-height': lineHeight
		});
	
}

jQuery.fn.polaroid = function() {
	//setup for starting position
	var myPolaroid = this;
	var totalSlides = $(myPolaroid).children("li").length;
	$(this).css("width", totalSlides * 624);
	$(this).css("left",324);
	
	//alert( totalSlides + ", " + curSlide);
	//alert( $(this).css("left") );
	//alert( $(this).css("width") );
	var curSlide = 1;
	
	$("#prev").click( function() {
		if( curSlide > 1 ){
			$(myPolaroid).animate({"left": "+=624px"}, "slow");
			curSlide--;
			updateOpacity();
		}
		return false;
	});
	
	function runMe(ele) {
		$(ele).animate({"left": "+=30px"}, "slow", function(){
			$(ele).animate({"left": "-=30px"}, "slow", function() {
				runMe(ele);
			});
		});
	}
	
	function stopMe(ele, left) {
		$(ele).stop();
		$(ele).stop();
		$(ele).animate({"left": left}, "slow");
	}
	
	$("#next").click( function() {
		if( curSlide < totalSlides ){
			$(myPolaroid).animate({"left": "-=624px"}, "slow");
			curSlide++;
			updateOpacity();
		}
		return false;
	});
	
	$("#next").hover( function() {
		if( curSlide < totalSlides ){
			runMe(this);
		}
	}, function() {
		stopMe(this,860);
	});
	
	$("#prev").hover( function() {
		if( curSlide > 1 ){
			runMe(this);
		}
	}, function() {
		stopMe(this,280);
	});
	
	function updateOpacity() {
		$(myPolaroid).children("li").each( function() {
			if( $(myPolaroid).children("li").index($(this)) == curSlide - 1){
				$(this).animate({"opacity": 1}, "slow");
			}else{
				$(this).animate({"opacity": 0.5}, "slow");
			}
		});
	}
	
	$("#next").trigger("click");
	
}

$(document).ready( function() {
	//TEXT SHADOW!!! WOOOO!!!
	
	//banner header
	$("#head-banner h2").dropShadow({
		tdistance: 1,
		ldistance: 1,
		iefix: true
	});
	
	$("#recent-news h3 a").each( function() {
		$(this).dropShadow({
			tdistance: 5
		});
	});
	
	//white shadow (mac text :) )
	$(".wshadow, .cform ol li label").each( function() {
		$(this).dropShadow({
			shadowcolor: '#ffffff'
		});
	});
	
	//setup sweet scroll thingy
	$("#main-content #ourwork").polaroid();
	
});

$(function () {
        $('.bubbleInfo').each(function () {
            var distance = 0;
            var time = 250;
            var hideDelay = 250;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            if( $.browser.msie ){
				var info = $('.popup', this).css('display', 'none');
			}else{
				var info = $('.popup', this).css('opacity', 0);
			}


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;
					if( $.browser.msie ){
						info.css({
							top: -65,
							left: -32,
							display: 'block'
						});
						beingShown = false;
						shown = true;
					}else{
						info.css({
							top: -65,
							left: -32,
							display: 'block'
						}).animate({
							top: '-=' + distance + 'px',
							opacity: 1
						}, time, 'swing', function() {
							beingShown = false;
							shown = true;
						});
					}
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    if( $.browser.msie ){
						info.css({
							display: 'none'
						});
						shown = false;
					}else{
						info.animate({
							top: '-=' + distance + 'px',
							opacity: 0
						}, time, 'swing', function () {
							shown = false;
							info.css('display', 'none');
						});
					}

                }, hideDelay);

                return false;
            });
        });
    });
