// JavaScript Document

	function setFlash() {
		if ( !$.support.htmlSerialize ) { /*If browser doesn't support htmlSerialize then use altHtml embed here */
	
			$('.videoBack object').each(function() {
				var checkVimeo = ($(this).html()).match('vimeo.com');
				if (checkVimeo == 'vimeo.com') {
					$(this).replaceWith($(this).attr('altHtml'));
				}
			});
			var embedTag;
		
			$('.audio_player embed, .photosetBack embed').each(function(e){
			embedTag = $(this).attr("outerHTML");
			if ((embedTag != null) && (embedTag.length > 0)){
				embedTag = embedTag.replace(/embed /gi, "embed wmode=\"transparent\" ");
				$(this).attr("outerHTML", embedTag);
			}
			else
			{
				$(this).wrap('<div></div>');
			}
		});
		}
	
		$('.videoBack embed').attr('wmode','transparent').wrap('<div></div>'); /* embed to trasparent */
		$('.audio_player embed').attr('wmode','transparent').wrap('<div></div>');
		$('.photosetBack embed').attr('wmode','transparent').wrap('<div></div>');
		$('.videoBack').each(function(){
			var tempEmbed = $(this).html();
			tempEmbed = tempEmbed.replace("</object>","<param name='wmode' value='transparent'></object>");
			$(this).html(tempEmbed); /* Firefox 3.6 needed object to have trasparent on it too */
		});
	}
	
	function panelSliders(panelWrap, panelButton){

	var panelSlider = $(panelWrap),
	panelButton = $(panelButton, panelSlider),
	w = (panelSlider).outerWidth();
		
	panelSlider.css('left', '-' + w + 'px');
	
	panelButton.toggle(
	
		function() {
			panelButton.hide();
				panelSlider.animate({left: 0}, 1000, 'easeOutBounce', function(){
				//askSlider.css('left', 0).show('slide', {easing: 'easeOutBounce'}, 1000, function(){
					panelButton.css('backgroundPosition','0px -68px' )
					.css('right', '-45px').fadeIn();
				});
			
		},
		function() {
			panelSlider.animate({left: '-' + w + 'px'}, 1000, 'easeOutBounce');
				panelButton.css('backgroundPosition','0px 0px' )
				.css('right', '-72px');
			
		});
		
	
	}
	
	function setTopSlider() {
		$('#sliderButton').fadeIn('fast',function() {
			(function topSlider() {
				var topSlider = $('#topWrapper').show(),
					sliderButton = $('#sliderButton', topSlider),
					closeButton = $('#closeButton', topSlider),
					h = topSlider.outerHeight(),
					leftW = (($(window).width()-820)/2);
					
					topSlider.css('top', '-' + h + 'px');
					sliderButton.css('left',leftW+'px');
					closeButton.css('left',leftW+'px');
											
					sliderButton.click(
						function() {
							sliderButton.fadeOut();
							topSlider.css('top', 0).show('slide',{direction: 'up', easing: 'easeOutBounce'}, 1000, function() {
								closeButton.show();
								if ($(window).width() <= 820) {
									closeButton.css('left','10px');
								}
								else
								{
									closeButton.css('left',(($(window).width()-820)/2)+'px');
								}
								closeButton.css('bottom', '-56px').show('slide',{direction: 'up', easing: 'easeOutBounce'}, 1000);						
							});
					});
					
					closeButton.click(
					function() {
							closeButton.fadeOut( function(){
								});
	
	
							topSlider.animate({top: '-' + h + 'px'}, 1000, 'easeOutBounce', function() {
								sliderButton.show();
								sliderButton.css('bottom', '-56px').show('slide',{direction: 'up', easing: 'easeOutBounce'}, 1000);
							});
					}
				);
			}());	
		});	
	}
	
	
	function resizeWindow() {
	    
		var topSlider = $('#topWrapper').show(),
			sliderButton = $('#sliderButton', topSlider),
			closeButton = $('#closeButton', topSlider),
			leftW = (($(window).width()-820)/2);
			if ($(window).width() <= 820) {
				sliderButton.css('left','10px');
				closeButton.css('left','10px');
			}
			else {
			sliderButton.css('left',leftW+'px');
			closeButton.css('left',leftW+'px');
			}	
	}
	
	//Load image into modal pop-up window
	
	function loadImg() {
	    $('#container .photo .post .postContent a.imageLink').live('click',function(e){
			e.preventDefault();
			var id = $(this).attr('href'),
			img = new Image();
			
			
			$('#overlay').fadeIn(function(){
				$('#modalImage').fadeIn();
				
			});
			
			$(img).load(function(){
				$(this).hide().addClass('mImage');
				$('#modalImage').removeClass('loader');
				$('#overlay').append(this);
				$(this).fadeIn(800,function(){
					var ih = $(this).outerHeight(),
					iw = $(this).outerWidth(),
					newH = ($(window).height()/10)*7,
					newW = ($(window).width()/10)*7;
					
					
					if (ih >= iw && ih >= newH) {
						$(this).css('height',newH + 'px');
						$(this).css('width', 'auto');
					}
					else if (ih >= iw && newH > ih) {
						$(this).css('height', ih + 'px');
						$(this).css('width', 'auto');
					}
					else if (iw > ih && iw >= newW) {
						if ((newW / (iw / ih)) > newH) {
							$(this).css('width', 'auto');
							$(this).css('height', newH + 'px');
						}
						else {
							$(this).css('width', newW + 'px');

							$(this).css('height', 'auto');
						}
						
					}
					else  {
						$(this).css('width', iw + 'px');
						$(this).css('height', 'auto');
					}
					
					var padW = ($(window).width() - $(this).outerWidth()) / 2, 
					padH = ($(window).height() - $(this).outerHeight()) / 2;
					
						$(this).css('top', padH);
					  $(this).css('left', padW);
					
					if($('#overlay').is(":visible") == true) {
						ih = ih + 4;
						$('<div id="xButton">x</div>').appendTo('#modalImage');
						if (padH >= 0) {
							$('#xButton').css('top', padH - 4).css('right', padW - 65);
						}
						else {
							$('#xButton').css('top', '20px').css('right', padW - 65);
						}
					}
				});
				
			}).attr('src', id);
		});
		$('#xButton, #modalImage, .browserClose').live('click', function(){
			$(this).hide();
			$('#overlay').fadeOut(function(){
				$('#browserWrap').remove();
				$('.mImage').css('top', '-9999px').remove();
				$('#xButton').remove();
				$('#modalImage').addClass('loader');
			});
		});	
	}
	
	/* Alt text in a tool tip to show blog names */
		
	function altTips(){
		$('#scrollContent img',$('#scrollContainer')).hover(function(e){
			var altText = $(this).attr('alt');
			$('#container').append('<div class="altText">' + altText + '</div>')
			.children('.altText').hide().fadeIn(400);
			$('.altText').css('top', e.pageY - 2).css('left', e.pageX + 20);
		}, function() {
			//mouse out remove altText
			$('.altText').remove();	
		});
		
		$('#scrollContent img').mousemove(function(e){
			$('.altText').css('top', e.pageY - 2).css('left', e.pageX + 20);
		});
		
	}
	
	function setFlash() {
		if ( !$.support.htmlSerialize ) { //If browser doesn't support htmlSerialize then use altHtml embed here 
	
			$('.videoBack object').each(function() {
				var checkVimeo = ($(this).html()).match('vimeo.com');
				if (checkVimeo == 'vimeo.com') {
					$(this).replaceWith($(this).attr('altHtml'));
				}
			});
			var embedTag;
		
			$('.audio_player embed, .photosetBack embed').each(function(e){
			embedTag = $(this).attr("outerHTML");
			if ((embedTag != null) && (embedTag.length > 0)){
				embedTag = embedTag.replace(/embed /gi, "embed wmode=\"transparent\" ");
				$(this).attr("outerHTML", embedTag);
			}
			else
			{
				$(this).wrap('<div></div>');
			}
		});
		}

		$('.videoBack embed').attr('wmode','transparent').wrap('<div></div>'); // embed to trasparent 
		$('.audio_player embed').attr('wmode','transparent').wrap('<div></div>');
		$('.photosetBack embed').attr('wmode','transparent').wrap('<div></div>');
		$('.videoBack').each(function(){
			var tempEmbed = $(this).html();
			tempEmbed = tempEmbed.replace("</object>","<param name='wmode' value='transparent'></object>");
			$(this).html(tempEmbed); // Firefox 3.6 needed object to have trasparent on it too 
		});
	}
	
	/* Check if the scrolling div is at the top or bottom and remove arrow */
	
	function checkImageTop() {
		if (current == 10) {
			$('#topClick').css('background-position','0px 0px');
		}
		else
		if (current > 10) {
			$('#topClick').css('background-position','0px -10px');
		}
	}
	
	function checkImageBot() {
		if (scrollH < current) {
			$('#bottomClick').css('background-position','0px 0px');
		}
		else
		if (scrollH > current) {
			$('#bottomClick').css('background-position','0px -20px');
		}
	}

    function newIeScreen() {
        if ( !$.support.htmlSerialize ) { /*If browser doesn't support htmlSerialize then use altHtml embed here */
				
			if (document.cookie.length>0) {
			c_start = document.cookie.indexOf('visited=');
				if (c_start==-1) {
					setCookie();
					(function(){
						$('#overlay').fadeIn(function(){
							$('#modalImage').fadeIn();	
						});
						$('<div id="browserWrap"><p class="browserHeader">Choose a smarter browser</p><div align="center"><table><tr><td style="text-align: center;"><p>Google Chrome</p></td><td width="30px"></td><td style="text-align: center;"><p>Firefox</p></td><td width="30px"></td><td style="text-align: center;"><p>Safari</p></td></tr><tr><td><a href="http://www.google.com/chrome" target="_blank"><img src="http://static.tumblr.com/52cqb6c/gYnl1bwis/chrome.png" alt="Chrome" border="0"></a></td><td width="30px"></td><td><a href="http://www.mozilla.com/en-US/firefox/firefox.html" target="_blank"><img src="http://static.tumblr.com/52cqb6c/hsFl1bwj8/firefox.png" alt="Firefox"  border="0"></a></td><td width="30px"></td><td><a href="http://www.apple.com/safari/download/" target="_blank"><img src="http://static.tumblr.com/52cqb6c/FMDl1bwjj/safari.png" alt="Safari"  border="0"></a></td></tr></table></div><p class="browserText">Eventhough your current browser will display this website correctly, you should consider moving to a more modern browser. These browsers provide added functionality to enhance your viewing experience of this website and countless other websites on the internet. Click on a image to go to the browsers\' download page. You can always click \'close\' to continue viewing this website on your current browser.</p><div class="browserClose">X CLOSE</div></div>')
						.appendTo($('#overlay'),function(){
							$('#modalImage').removeClass('loader');
							$(this).hide().appendTo('#overlay').fadeIn();
						});
					})();
				}
			}
		}
			setFlash();	
	}
	
	function funcDelay(){
		setTimeout(setFlash, 1000);
	}
