$(function(){
    /**
     * http:// link regexp.
     */
    String.prototype.linkify = function(){
        return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m){
            return m.link(m);
        });
    };
    
    /**
     * Twitter @-replay Regexp..
     */
    String.prototype.atify = function(){
        return this.replace(/@[\w]+/g, function(m){
            return "@<a href='http://www.twitter.com/" + m.replace('@', '') + "'>" + m.replace(/@/, '') + "</a>";
        });
    };
    
    /**
     * Hide body until page loads.
     */
    $('body').hide();
    /**
     * Show body when page loads.
     */
    $(window).load(function(){
        $('body').show();
    });
    
    /**
     * Menu hover function.
     */
    $('#nav > li').each(function(){
        var thisID = $(this).children().filter('a').children().filter('img').attr('id');
        var hoverState = $(this).children().filter('a').children().filter('img').attr('src').replace(/\.jpg/, '') + "2.jpg";
        $(this).children().filter('a').prepend('<img src=\'' + hoverState + '\' class=\'hoverState\' />');
        $(this).children().filter('a').children().filter('.hoverState').attr('id', thisID).css({
            opacity: 0,
            'position': 'absolute',
            zIndex: 2
        });
    });
    $('#nav > li').hover(function(){
        $(this).children().filter('a').children().filter('.hoverState').stop().animate({
            opacity: 1
        }, 150);
    }, function(){
        $(this).children().filter('a').children().filter('.hoverState').stop().animate({
            opacity: 0
        }, 750);
    });
    
    var regexp = /(\w|[-.])+$/
    str = document.URL
    a = regexp.exec(str)
    if (a != null) {
        var currentPage = a[0].replace(/\.html/, '');
    }
    else {
        var currentPage = 'home';
    }
    
    $('.hoverState').each(function(){
        if ($(this).attr('id') == currentPage) {
            $(this).css({
                opacity: 1
            }).removeClass('hoverState').addClass('curent');
        }
    });
    
    /**
     * Form input
     */
    var initFormVal = $('#email').val();
    $('#email').focus(function(){
        if ($('#email').val() == initFormVal) {
            $('#email').val('');
        }
    });
    $('#email').blur(function(){
        if ($('#email').val() == '') {
            $('#email').val(initFormVal);
        }
    });
    
    /**
     * Twitter API.
     */
    function relative_time(time_value){
        var parsed_date = Date.parse(time_value);
        
        var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
        var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
        
        if (delta < 60) {
            return 'less than a minute ago';
        }
        else 
            if (delta < 120) {
                return 'about a minute ago';
            }
            else 
                if (delta < (45 * 60)) {
                    return (parseInt(delta / 60)).toString() + ' minutes ago';
                }
                else 
                    if (delta < (90 * 60)) {
                        return 'about an hour ago';
                    }
                    else 
                        if (delta < (24 * 60 * 60)) {
                            return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
                        }
                        else 
                            if (delta < (48 * 60 * 60)) {
                                return '1 day ago';
                            }
                            else {
                                return (parseInt(delta / 86400)).toString() + ' days ago';
                            }
    }
    
    $.getJSON('http://twitter.com/status/user_timeline/thebearbot.json?count=7&callback=?', function(data){
        var totalHeight = 0;
		$.each(data, function(i, item){
			var tweet = $('<dd>' + item.text.linkify().atify() + '</dd>\n<dt>' + relative_time(item.created_at) + '</dt>');
			$('div#twitter > div#twitWrapper > dl').append(tweet);

        });
		var next = new Image(),
			prev = new Image();
		next.src = '/images/next.png';
		prev.src = '/images/prev.png';
		
		$('#twitWrapper').before(prev).after(next);
		
		var movetimer = null;
		
		function startUp() {
			movetimer = setInterval(function(){
				var distToBottom = $('div#twitWrapper > dl').height() - parseInt( $('div#twitWrapper > dl').css('bottom') );
				if(  distToBottom >= 0  ) {
					$('#twitWrapper > dl').animate({
					bottom: '+=' + 2 + 'px'
				}, 2);
				}
			},2);
		};
		
		function stopUp() {
			clearInterval(movetimer);
		};
		
		function startDown() {
			movetimer = setInterval(function(){
				var distToBottom = $('div#twitWrapper > dl').height() - parseInt( $('div#twitWrapper > dl').css('bottom') );
				if(  distToBottom <= $('div#twitWrapper').height()  ) {
					$('#twitWrapper > dl').animate({
					bottom: '-=' + 2 + 'px'
				}, 2);
				}
			},2);
		}
		
		function stopDown() {
			clearInterval(movetimer);
		}
		
		$(next).css({'cursor': 'pointer', marginTop: 225, marginLeft: 330, 'position': 'absolute'}).hover(function(){
			startUp();
		}, function(){
			stopUp();
		});
		
		$(prev).css({'cursor': 'pointer', marginTop: 225, marginLeft: -8, 'position': 'absolute'}).hover(function(){
			startDown();
		}, function(){
			stopDown();
		});
		
    });
    /**
     * Social tools.
     */
    $('ul#social > li').find('img').css({
        opacity: .5
    }).hover(function(){
        $(this).stop().animate({
            opacity: 1
        });
    }, function(){
        $(this).stop().animate({
            opacity: .5
        });
    });
    
    /**
     * Ajax paginate photo stream..
     */
    if ($('#imgWrapper').length > 0) {
        var prev = "<img src='/images/prev.png' id='prev' />", next = "<img src='/images/next.png' id='next' />", timeout = null, timeoutval = 10000;
        
        $('#paginate').show();
        
        var currentIndex = 0, emptyState = $('.paginate').attr('src'), selectedState = $('.paginate').attr('src').replace(/empty\.png/, 'selected.png');
        
        for (var i = 0; i < $('.paginate').length; i++) {
            $('.paginate').eq(i).attr('id', i);
        }
        
        function controlCurrentIndex(){
            if (currentIndex >= $('.paginate').length) {
                currentIndex = 0;
            }
            else 
                if (currentIndex < 0) {
                    currentIndex = $('.paginate').length - 1;
                }
        }
        
        function setCurrentIndex(index){
            currentIndex = index;
            controlCurrentIndex();
            updateImage(currentIndex);
        }
        var enlargedPhoto = new Image();
        
        function updateImage(q){
            if (timeout) 
                clearTimeout(timeout);
            timeout = setTimeout(function(){
                setCurrentIndex(currentIndex + 1);
            }, timeoutval);
            $('.paginate').attr('src', emptyState).removeClass('selected');
            $('.paginate').eq(q).attr('src', selectedState).addClass('selected');
            
            $.getJSON('/xml/photostream.php?q=' + $('.paginate').length, function(data){
                var newSrc = data[q].url.replace(/\.jpg/, '-205x205.jpg'), newAlt = data[q].title;
                enlargedSource = data[q].url;
                enlargedPhoto.src = enlargedSource;
                $('#currentPhoto').css({
                    width: 195,
                    height: 195
                }).attr('src', newSrc);
                ;
            });
            
        }
        
        timeout = setTimeout(function(){
            setCurrentIndex(currentIndex + 1)
        }, timeoutval);
        updateImage(0);
        
        $('#imgWrapper').prepend(prev).append(next);
        $('#prev').css({
            zIndex: 10,
            'position': 'absolute',
            top: 191 / 2 - 21 / 2,
            left: -5,
            'cursor': 'pointer'
        }).click(function(){
            setCurrentIndex(currentIndex - 1);
        });
        $('#next').css({
            zIndex: 10,
            'position': 'absolute',
            top: 191 / 2 - 21 / 2,
            left: 180 + 5,
            'cursor': 'pointer'
        }).click(function(){
            setCurrentIndex(currentIndex + 1);
        });
        
        $('.paginate').css({
            'cursor': 'pointer',
            opacity: .75
        }).click(function(){
            var c = parseInt($(this).attr('id'));
            setCurrentIndex(c);
        }).filter(':first').addClass('selected');
        $('.selected').attr('src', selectedState);
        
        $('#currentPhoto').css({
            'cursor': 'pointer'
        }).click(function(){
            if (timeout) 
                clearTimeout(timeout);
            var exitIcon = new Image();
            exitIcon.src = 'http://www.bearbotmusic.com/wp-content/themes/bearbot/images/close.png';
            $('body').prepend('<div id="screen"></div>');
            $('#screen').css({
                'position': 'absolute',
                width: '100%',
                height: '100%',
                backgroundColor: "#000",
                opacity: .75,
                zIndex: 9999
            }).hide().fadeIn().before(enlargedPhoto).before(exitIcon);
            $(exitIcon).css({
                'position': 'fixed',
                zIndex: 10001,
                marginLeft: $(window).width() / 2 + $(enlargedPhoto).width() / 2 - $(exitIcon).width() / 2,
                marginTop: $(window).height() / 2 - $(enlargedPhoto).height() / 2 - $(exitIcon).height() / 2,
                'cursor': 'pointer'
            });
            $(enlargedPhoto).css({
                'position': 'fixed',
                zIndex: 10000,
                marginTop: $(window).height() / 2 - $(enlargedPhoto).height() / 2,
                marginLeft: $(window).width() / 2 - $(enlargedPhoto).width() / 2,
                'border': '4px solid #fff'
            });
            $(exitIcon).click(function(){
                if (timeout) 
                    clearTimeout(timeout);
                timeout = setTimeout(function(){
                    setCurrentIndex(currentIndex + 1);
                }, timeoutval);
                $(enlargedPhoto).remove();
                $('#screen').remove();
                $(exitIcon).remove()
                imgTimer = updateImage(currentIndex);
            });
        });
    }
    
    /**
     * Video Player
     */
    if ($('#videoPlayer').length > 0) {
        $.getJSON('/xml/videostream.php', function(data){
            $.each(data, function(i, item){
                $('ul#videoList').append('<li id="' + item.id + '"><div id="' + i + '"><img src="' + item.thumbnail + '" /></div></li>');
                $('ul#videoList > li > div > img').eq(i).css({
                    left: -100,
                    top: -50
                });
            });
            
            function setVideoStage(id, itemid){
                vidID = id;
                selectID = id;
                $('ul#videoList > li > div').removeClass('selected');
                $('ul#videoList > li[id=' + itemid + ']').children().filter('div').addClass('selected');
                $('div#videoPlayer > .divider > h1').html(data[id].title);
                $('div#videoPlayer > p').html(data[id].description);
            };
            
            setVideoStage($('ul#videoList > li:first > div').attr('id'), $('ul#videoList > li:first').attr('id'));
            
            vidID = $('ul#videoList > li:first').attr('id');
            
            $('ul#videoList > li').css({
                'cursor': 'pointer'
            }).click(function(){
                $('#swfVideo')[0].setVideo($(this).attr('id'));
                setVideoStage($(this).children().filter('div').attr('id'), $(this).attr('id'));
            });
        });
    }
    
    /**
     * Featured album AJAX.
     */
    if ($('div#albumScroll').length > 0) {
        $.getJSON('http://www.bearbotmusic.com/xml/albumstream.php', function(data){
            var currentIndex = 0;
            
            function controlCurrentIndex(){
                if (currentIndex >= data.length) {
                    currentIndex = 0;
                }
                else 
                    if (currentIndex < 0) {
                        currentIndex = data.length - 1;
                    }
            }
            
            function updateData(){
                var thumbnail = data[currentIndex].thumbnail.replace(/\.jpg/, '-205x205.jpg');
                $('div#albumScroll').css({
                    'background': 'url("' + thumbnail + '")'
                });
                var currentView = currentIndex + 1;
                $('div#albumScroll > h1').text(data[currentIndex].title + " (" + currentView + "/" + data.length + ")");
            }
            
            function setCurrentIndex(index){
                currentIndex = index;
                controlCurrentIndex();
                updateData();
            }
            
            setCurrentIndex(currentIndex);
            
            function setAlbum(){
                $('div#featuredAlbumCover').hide().css({
                    'background': 'url("' + data[currentIndex].thumbnail.replace(/\.jpg/, '-205x205.jpg') + '")'
                }).fadeIn(1000).children().filter('h1').hide().text(data[currentIndex].title).fadeIn(1000);
                $('div#featuredAlbum > p').remove();
                $('div#featuredAlbum > ol').remove();
                $('div#featuredAlbumCoverBG').after('<p>' + data[currentIndex].excerpt + '</p>');
                $('div#featuredAlbum > p').hide().fadeIn(1000);
                $('div#featuredAlbum > p').after(data[currentIndex].content)
                $('div#featuredAlbum > ol').hide().fadeIn(1000);
                $('div#featuredAlbum > a').attr('href', data[currentIndex].url).hide().fadeIn(1000);
            }
            
            var prev = "<img src='/images/prev.png' id='prev' />", next = "<img src='/images/next.png' id='next' />";
            
            $('#albumScroll').before(prev).after(next);
            $('#prev').css({
                zIndex: 10,
                'position': 'absolute',
                top: 145,
                left: 0,
                'cursor': 'pointer'
            }).click(function(){
                setCurrentIndex(currentIndex - 1);
            });
            $('#next').css({
                zIndex: 10,
                'position': 'absolute',
                top: 145,
                left: 210,
                'cursor': 'pointer'
            }).click(function(){
                setCurrentIndex(currentIndex + 1);
            });
            
            $('div#albumScroll').css({
                'cursor': 'pointer'
            }).click(function(){
                setAlbum();
                setCurrentIndex(currentIndex + 1);
            });
        });
    }
    
    if ($('img#tracklistNext').length > 0) {
        $.getJSON('/xml/trackstream.php', function(data){
        
            var start = 0;
            var total = 9;
            var max = data.length - 1;
            
            function fillTracks(){
                $('img#tracklistNext').parent().parent().children().filter('ul').each(function(){
                    $(this).slideUp("slow", function(){
                        $(this).remove();
                    });
                });
                $.each(data, function(i, item){
                    if (i >= start && i < start + total) {
                        var listItem = $('<ul></ul>').addClass('event');
                        $(listItem).hide();
                        var downloadIcon = new Image();
                        downloadIcon.src = "http://www.bearbotmusic.com/wp-content/themes/bearbot/images/download.png"
                        
                        var songTitle = $('<li></li>').addClass('title').append('<span>' + (i + 1) + '</span> ' + item.title);
                        var songURL = $('<li></li>').addClass('download').append('<a href=' + item.url + '>DOWNLOAD <img src="' + downloadIcon.src + '" id="download" alt="download" /></a>');
                        
                        listItem.append(songTitle).append(songURL);
                        
                        $(listItem).css({
                            'cursor': 'pointer'
                        }).click(function(){
                            window.location.href = item.url;
                        });
                        
                        if (i % 2) {
                            listItem.addClass('odd')
                        }
                        else {
                            listItem.addClass('even');
                        }
                        
                        $('img#tracklistNext').parent().parent().append(listItem);
                        if (i = start + total - 1) {
                            $(listItem).slideDown();
                        }
                    }
                });
            };
            
            function checkIndex(){
                if (start >= max) {
                    start = 0;
                }
                else 
                    if (start < 0) {
                        start = max - max % total;
                    }
            }
            
            function setCurrentIndex(index){
                start = index;
                checkIndex();
                fillTracks();
            }
            
            setCurrentIndex(0);
            
            $('img#tracklistNext').css({
                'cursor': 'pointer'
            }).click(function(){
                setCurrentIndex(start + total);
            });
            
            $('img#tracklistPrev').css({
                'cursor': 'pointer'
            }).click(function(){
                setCurrentIndex(start - total);
            });
            
        });
    }
    
    /**
     * Media page.
     */
    if ($('#mediaStage').length > 0) {
        var maxPerStream = 5;
        var cat = 6;
        
        function setStagePhoto(title, url){
        
            var img = new Image();
            img.src = url;
            
            $(img).load(function(){
                var caption = $('<h1></h1>');
                $(caption).append(title).css({
                    width: img.width - 4,
                    marginTop: img.height - 30
                });
                
                var frame = $('<div></div>').hide();
                $(frame).css({
                    width: img.width,
                    height: img.height,
                    'background': 'url("' + img.src + '")',
                    marginLeft: 590 / 2 - img.width / 2 + 10,
					marginTop: 428/2 - img.height / 2
                })
                
                $(frame).append(caption);
                
                $('#mediaStage').children().remove();
                
                $('#mediaStage').append(frame);
                $(frame).fadeIn(1500);
            });
            
        }
        
        function setStageVideo(title, description){
			$('div#mediaStage > h1').html(title);
			$('div#mediaStage > p').html(description);    
        }
        
        function setStreamer(cat){
            if (cat == 7) {
                $('div#mediaStage').children().remove();
				var title = $('<h1></h1>'),
					description = $('<p></p>');
                var frame = $('<div id="flashstage"></div>');
                $(frame).css({
                    width: 590,
                    height: 230
                });
                $('div#mediaStage').append(title).append(frame).append(description);
                var videoflashvars = false, videoparams = {
                    allowScriptAccess: 'always',
                    wmode: 'opaque'
                }, videoattributes = {
                    id: 'flashVideo',
                    name: 'flashVideo'
                };
                swfobject.embedSWF('/videoPlayer.swf', 'flashstage', '550', '310', '9.0.0', false, videoflashvars, videoparams, videoattributes);
            }
            $.getJSON('/xml/mediastream.php?q=' + cat, function(data){
                var start = 0, max = 5, total = data.length, remainder = data.length % maxPerStream;
                
                function buildStream(){
                    $('#mediaStreamer > ul').remove();
                    var list = $('<ul></ul>');
                    $('#mediaStreamer').append(list);
                    $.each(data, function(i, item){
                        if (i >= start && i < start + max) {
                            var listItem = $('<li><li').addClass('mediaItem');
                            var thumbnail = new Image(111, 111);
                            if (cat == 6) {
                                thumbnail.src = item.url.replace(/\.jpg/, '-205x205.jpg');
                                $(thumbnail).css({
                                    'cursor': 'pointer'
                                }).click(function(){
                                    setStagePhoto(item.title, item.url);
                                });
                                if (i == 0) {
                                    setStagePhoto(item.title, item.url);
                                }
                            }
                            else 
                                if (cat == 7) {
                                    thumbnail.src = item.thumbnail.replace(/\.jpg/, '-205x205.jpg');
                                    thumbnail.id = item.id;
                                    $(thumbnail).css({
                                        'cursor': 'pointer'
                                    }).click(function(){
                                        $('#flashVideo')[0].setVideo($(this).attr('id'));
										setStageVideo(item.title, item.description);
                                    });
									if(i == 0){
										setStageVideo(item.title, item.description);
									}
                                }
                            
                            $(thumbnail).css({
                                opacity: .75
                            });
                            
                            $(thumbnail).hover(function(){
                                $(this).stop().animate({
                                    opacity: 1
                                });
                                $(this).css({
                                    'border-color': '#ffffff'
                                });
                            }, function(){
                                $(this).stop().animate({
                                    opacity: .75
                                });
                                $(this).css({
                                    'border-color': '#000000'
                                });
                            });
                            
                            var container = $('<li></li>');
                            $(list).append(container);
                            $(container).append(thumbnail);
                        }
                    });
                }
                
                function checkIndex(){
                    if (start >= total) {
                        start = 0;
                    }
                    else 
                        if (start < 0) {
                            start = (total - (total%max));
                        }
                }
                
                function setCurrentIndex(index){
                    start = index;
                    checkIndex();
                    buildStream();
                }
                
                setCurrentIndex(0);
                
                var prev = new Image(), next = new Image();
                
                prev.src = '/images/prev.png', next.src = '/images/next.png'
                
                $(prev).css({
                    zIndex: 10,
                    'position': 'absolute',
                    top: 135 / 2 - 10 / 2,
                    left: 20,
                    'cursor': 'pointer'
                }).click(function(){
                    setCurrentIndex(start - max);
                });
                
                $(next).css({
                    zIndex: 10,
                    'position': 'absolute',
                    top: 135 / 2 - 10 / 2,
                    left: 605,
                    'cursor': 'pointer'
                }).click(function(){
                    setCurrentIndex(start + max);
                });
                
                $('#mediaStreamer').append(prev).append(next);
                
            });
        }
        
        function setCat(q){
            cat = q;
			if(q==6){
				$('#divFull > h1').html('Bearbot <span>photography</span>.');
				$('#divMid > h1').html('Photo <span>stream</span>.');
			}else if(q==7){
				$('#divFull > h1').html('Bearbot <span>videography</span>.');
				$('#divMid > h1').html('Video <span>stream</span>.');
			}
            setStreamer(cat);
        }
        
        setCat(6)
        
        $('#photoBtn').css({
            'cursor': 'pointer'
        }).click(function(){
            setCat(6);
        });
        
        $('#videoBtn').css({
            'cursor': 'pointer'
        }).click(function(){
            setCat(7);
        });
    }
    
	/**
	 * Events.
	 */
	
	$('ul.eventLarge').css({height: 35, 'cursor': 'pointer', opacity: .5}).hover(function(){
		$(this).stop().animate({opacity: 1});
	},function(){
		if(!$(this).hasClass('selected'))
		{
			$(this).stop().animate({opacity: .5});
		}
	}).click(function(){
		$('ul.eventLarge').stop().animate({height: 35, opacity: .5}).removeClass('selected');
		$(this).stop().animate({height: 275, opacity: 1}).addClass('selected');
	});
	$('ul.eventLarge').eq(0).css({height: 275, opacity: 1}).addClass('selected');
	
	/**
	 * Store coming soon.
	 */
	var bubble = $('<div></div>').attr('id', 'management').css({height: 25, top: 0, left: 0, 'position': 'absolute', zIndex: 100, opacity: 0}).attr('enabled', 'disabled'),
		arrow = $('<div></div>').addClass('management-arrow').css({top: 15, left: -18}),
		arrowBorder = $('<div></div>').addClass('management-arrow-border').css({top: 15, left: -21});
	$(bubble).append('<h1>Store coming soon!</h1>').append(arrowBorder).append(arrow);
		
	$('#store').parent().parent().hover(function(){
		$('#store').parent().parent().append(bubble);
		$(bubble).css({
			top: -5,
			marginLeft: $('#store').width()-70
		}).stop().animate({
			marginLeft: '+=' + 20 + 'px',
			opacity: .75
		}, 1000);
	},function(){
		$(bubble).stop().animate({
			opacity: 0,
			marginLeft: '+=' + 20 + 'px'
		}, function(){
			$(bubble).remove();
		});
	});
	
	/**
	 * Media hovers.
	 */
	
	var mediabubble = $('<div></div>').attr('id', 'mediaHover').css({height: 25, top: 0, left: 0, 'position': 'absolute', zIndex: 100, opacity: 0}).attr('enabled', 'disabled'),
		mediaarrow = $('<div></div>').addClass('mediaHover-arrow').css({top: 15, left: -18}),
		mediaarrowBorder = $('<div></div>').addClass('mediaHover-arrow-border'),
		mediamessage = $('<h1></h1>');
	$(mediabubble).append(mediamessage).append(mediaarrowBorder).append(mediaarrow);
	
	function setBubble(obj) {
		$('body').append(mediabubble)
		$(mediaarrowBorder).css({
			top: -20,
			left: $(mediabubble).width()/2 - $(mediaarrow).width()/2
		});
		$(mediaarrow).css({
			top: -17,
			left: $(mediabubble).width()/2 - $(mediaarrow).width()/2
		});
		$(mediabubble).css({
			top: -5,
			marginLeft: $(obj).offset().left + $(obj).width()/2 - $(mediabubble).outerWidth()/2,
			marginTop: $(obj).offset().top + $(obj).height()
		}).stop().animate({
			marginTop: '+=' + 20 + 'px',
			opacity: .9
		}, 1000);
	}
		
	if($('#videoBtn').length>0 && $('#photoBtn').length>0)
	{
		
		$('#photoBtn').hover(function(){
			$(mediamessage).html('').append('Check out photos!');
			setBubble($(this));
		},function(){
			$(mediabubble).stop().animate({
				opacity: 0,
				marginTop: '+=' + 20 + 'px'
			}, function(){
				$(mediabubble).remove();
			});
		});
		
		$('#videoBtn').hover(function(){
			$(mediamessage).html('').append('Watch videos!');
			setBubble($(this));
		},function(){
			$(mediabubble).stop().animate({
				opacity: 0,
				marginTop: '+=' + 20 + 'px'
			}, function(){
				$(mediabubble).remove();
			});
		});
		
	}

	/**
	 * Donate hover.
	 */
	
	if($('#donate').length>0)
	{
		
		$('#donate').hover(function(){
			$(mediamessage).html('').append('Support Bearbot!');
			setBubble($(this));
		},function(){
			$(mediabubble).stop().animate({
				opacity: 0,
				marginTop: '+=' + 20 + 'px'
			}, function(){
				$(mediabubble).remove();
			});
		});
		
	}
});

