Learn how to use jQuery at the Blog

Impulse Studios « visit

  • Added 6 months ago
  • 318 Lines of Code shown
  • 1 Links of Interest
http://impulsestudios.ca
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Impulse Studios - http://impulsestudios.ca

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function yOffset() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

$(document).ready(function() {
	$.preloadImages("/images/icons/expand.png", "/images/icons/close.png");
	t = setTimeout ( "rotateNext()", 15000 );
	$('.hide').animate({ 
		opacity: 0
	  }, 1 );
	
	shadowFix();
    $('ul#filter a').click(function() {  
        $(this).css('outline','none');  
        $('ul#filter .current').removeClass('current');  
        $(this).parent().addClass('current');  
          
        var filterVal = $(this).text().toLowerCase().replace(' ','-');  
                  
        if(filterVal == 'all') {  
            $('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');  
        } else {  
            $('ul#portfolio li').each(function() {  
                if(!$(this).hasClass(filterVal)) {  
                    $(this).fadeOut('normal').addClass('hidden');  
                } else {  
                    $(this).fadeIn('slow').removeClass('hidden');  
                }  
            });  
        }  
          
        return false;  
    });
});

//Lightbox

$('#portfolio li a, a.portfolioItem').click(
	function(){
		imgTypes = ['png', 'jpg', 'jpeg', 'gif'];
		$src = $(this).attr("href");
		pageTracker._trackPageview($src);
		$('#lbBackground').fadeIn();
		$top = $(this).offset().top + 50;
		$left = $(this).offset().left + 150;
		$height=672;
		$width=877;
		imgRegExp = imgTypes.join('|');
    	imgRegExp = new RegExp('\.' + imgRegExp + '$', 'i');
		
		$fTop = yOffset() + (($(window).height() - $height + 60) / 2);
		if ($src.match(imgRegExp)) {
			$('#lbImage')
			.attr('src', $src)
			.load(function(){
				var lbImage = new Image();
				lbImage.src = $src;
				$height = lbImage.height;
				$width = lbImage.width;
				
				if($(window).width() > $width) {
					$fLeft = ($(window).width() - $width - 60) / 2;
				}else{
					$fLeft = 10;	
				}
				$('#lbImage, #lightbox, #close').show(); 
				$('#lightbox').css({ 
					top:$top, 
					left:$left 
				}).animate({
					top:$fTop,
					left:$fLeft,
					width:$width,
					height:$height
				});
				
			});
			
		}else{	
			if($(window).width() > $width) {
				$fLeft = ($(window).width() - $width - 60) / 2;
			}else{
				$fLeft = 10;	
			}
			$('#galleryFrame').attr({src:$src});
			$('#galleryFrame, #lightbox, #close').show();
			$('#lightbox').css({ 
				top:$top, 
				left:$left 
			}).animate({
				top:$fTop,
				left:$fLeft,
				width:$width,
				height:$height
			});

		}
		return false;
	});

$('#lbBackground, #close').click(
	function(){
		$('#lightbox').animate({
			top:$top,
			left:$left,
			width:10,
			height:10
		}, function(){ $('#lightbox, #close, #galleryFrame, #lbImage').hide(); })
		$('#lbBackground').fadeOut();
		return false;
	});

//Portfolio Hovers
$(".portfolioItem, #portfolio li a").hover(
  function () {
	$(this).children('.hover').fadeIn('slow');
	$(this).append('<img class="plus" src="/images/icons/expand.png" alt="enlarge" \/>');
	if (jQuery.fn.pngFix) $(document).pngFix();
  }, 
  function () {
	$('.hover').fadeOut('slow');  
	$('.plus').remove();

  }
);

//Carousel
var current ='#rotate1';
var c = current;
var nextFrame = this.hash;

function rotate(){
	$(current+" .background").animate({ 
		opacity: 0,
		marginRight: "-150%" 
	  }, 1500, function(){
			//$(c+" .background").addClass('hide');
			//$(c+" .background").attr('style','');
			$(c+" .background").css('marginLeft','-150%').css('marginRight','');
			var nav = $(nextFrame+" img").attr('src').replace('/images/rotator/bg', '');
			$('#nav .current').attr('style','background:url(/images/rotator/navBG'+nav+');');
			
		});
	current = nextFrame;

	$(nextFrame+" .background").animate({ 
		opacity: 1,
		marginLeft: "-50%" 
	  }, 1500 );
	
	clearTimeout(t)
	t = setTimeout ( "rotateNext()", 15000 );
}

$(".rotatorNav a").click(function(){
		c = current;
		nextFrame = this.hash;
		rotate();
		
		$(".rotatorNav a").removeClass('active');
		$(this).addClass('active');	
		return false;
	});

$(".arrowRight").click(function(){
		rotateNext();
		return false;
	});

function rotateNext(){
		c = current;
		nextFrame = '#rotate'+(parseInt(current.replace('#rotate', ''))+1);
		if(!$(nextFrame).length){
			nextFrame = '#rotate1';
		}	
		rotate();
		
		$(".rotatorNav a").removeClass('active');
		$(".rotatorNav a[href='"+current+"']").addClass('active');
	};

$(".arrowLeft").click(function(){
		c = current;
		nextFrame = '#rotate'+(parseInt(current.replace('#rotate', ''))-1);
		if(!$(nextFrame).length){
			nextFrame = '#rotate'+$('.bgWrapper').size();
		}
		rotate();
		
		$(".rotatorNav a").removeClass('active');
		$(".rotatorNav a[href='"+current+"']").addClass('active');
		return false;
	});

//Tipsy
(function($) {
    $.fn.tipsy = function(opts) {

        opts = $.extend({fade: false, gravity: 'n'}, opts || {});
        var tip = null, cancelHide = false;

        this.hover(function() {
            
            $.data(this, 'cancel.tipsy', true);

            var tip = $.data(this, 'active.tipsy');
            if (!tip) {
                tip = $('<div class="tipsy"><div class="tipsy-inner">' + $(this).attr('title') + '</div></div>');
                tip.css({position: 'absolute', zIndex: 100000});
                $(this).attr('title', '');
                $.data(this, 'active.tipsy', tip);
            }
            
            var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
            tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
            var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
            
            switch (opts.gravity.charAt(0)) {
                case 'n':
                    tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
                    break;
                case 's':
                    tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
                    break;
            }

            if (opts.fade) {
                tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 1});
            } else {
                tip.css({visibility: 'visible'});
            }

        }, function() {
            $.data(this, 'cancel.tipsy', false);
            var self = this;
            setTimeout(function() {
                if ($.data(this, 'cancel.tipsy')) return;
                var tip = $.data(self, 'active.tipsy');
                if (opts.fade) {
                    tip.stop().fadeOut(function() { $(this).remove(); });
                } else {
                    tip.remove();
                }
            }, 100);
            
        });

    };
})(jQuery);

$(function() { 
    $(".rotatorNav a").tipsy({gravity: 's'});
	$("#about-nav a").tipsy({gravity: 'n'});
     
  });

//Fix shadow on contact form
function shadowFix(){
	var pageHeight = $(document).height();
	if(yOffset() + $(window).height() > pageHeight - 207){
		$("#shadow").attr('style', 'height:'+(pageHeight-yOffset()-207)+'px;');
		$('#shadowCorner').show();
	}else if(yOffset() < 207){
		$("#shadow").attr('style','height:100%;');
		$('#shadowCorner').hide();
	}
}

$(window).scroll(function(){shadowFix()});

$('.contactUs').click(function(){
		pageTracker._trackPageview("/contact-us"); 					   
		if(!($.browser.msie && ($.browser.version.substring(0,1) == 6))) {
			$('#contactForm').animate({ 
				width: "439px" 
			  }, 500);
		
			return false;
		}
	});

$('.cancel, #contactClose').click(function(){
		$('#contactForm').animate({ 
			width: "0" 
		  }, 500);
		return false;
	});

$('#emailAddress').focus(function(){
		if(this.value=='email address'){
			this.value = '';	
		}
	});

$('#emailAddress').blur(function(){
		if(this.value==''){
			this.value = 'email address';	
		}
	});