jQuery.noConflict();

// Innitiate Main Menu
jQuery(document).ready(function() { 
	jQuery('#menu-wrapper .menu').superfish(); 
}); 

//Homepage boxes
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
jQuery(document).ready(function() {
	equalHeight(jQuery(".equalize"));
});


//News Scroller (Widget)
jQuery(document).ready(function() {
 
 	jQuery('.news-scroller').cycle({ 
	    fx: 'scrollVert',
		speed: 1000,
		rev: true,
		timeout: 10000,
		next: '.news-next', 
	    prev: '.news-previous'
	 });      
 
});


// Social Drop Down Panel 
jQuery(document).ready(function() {
	jQuery(".btn-slide").click( function() {
		if (jQuery("#openCloseIdentifier").is(":hidden")) {
			jQuery("#social").animate( {top: "0"} , 650 );
			jQuery(this).addClass("active");
			jQuery("#openCloseIdentifier").show();
		} else {
			jQuery("#social").animate( {top: "-46px"} , 650 );
			jQuery(this).removeClass("active");
			jQuery("#openCloseIdentifier").hide();
		}
	});  
});

//Contact Form
jQuery(document).ready(function() {

	//Define URL to PHP mail file
	url = jQuery("meta[name=template_url]").attr('content') + "/sendmail.php";
	
	//Activate jQuery form validation
	jQuery("#jaybich-contact").validate({
	
		submitHandler: function() {
		
			//Define data string
			var datastring = jQuery("#jaybich-contact").serialize();
			
			//Submit form
			jQuery.ajax({
				type: "POST",
				url: url,
				data: datastring,
				success: function(){
					jQuery('#jaybich-contact').slideUp();
					jQuery('#sent').fadeIn();
				}
			});
		}
	
	});
			
});

//Comments Form
jQuery(document).ready(function() {
	
	//Activate jQuery form validation
	jQuery(".comments-form").validate();
			
});

//Portfolio thumbnail
jQuery(document).ready(function(){
	
	jQuery('.portfolio-box a.thumb').each(function(){
	    if(this.href.match(/\.(jpe?g|png|bmp|gif|tiff?)$/i)){
	        jQuery(this).addClass('image');
	    } else {
	    	jQuery(this).addClass('video');
	    }
	});

	jQuery('.portfolio-box a').hover(function() {
		
		//Show darkenned hover over thumbnail image
		jQuery(this).find('img').stop(true, true).animate({opacity:0.5},400);

	}, function() {
		
		//Hide darkenned hover over thumbnail image
		jQuery(this).find('img').stop(true, true).animate({opacity:1},400);
			
	});

});

//Wordpress Gallery Lightbox Integration
jQuery(document).ready(function(){
	
	jQuery('.gallery-item a').each(function(){
	    if(this.href.match(/\.(jpe?g|png|bmp|gif|tiff?)$/i)){
	        jQuery(this).attr('rel','lightbox');
		}
	});

});

//Innititate Pretty Photo
jQuery(document).ready(function(){
	jQuery("a[rel^='lightbox']").prettyPhoto({theme:'light_rounded'});
});

//Cufon text
Cufon.replace('h1', { fontFamily: 'Myriad Pro Bold', hover: true });
Cufon.replace('h2', { fontFamily: 'Myriad Pro Bold', hover: true });
Cufon.replace('h3', { fontFamily: 'Myriad Pro Regular', hover: true });
//Cufon.replace('h2, h3');

//Twitter Widget
(function(jQuery) {
	/*
		jquery.twitter.js v1.5
		Last updated: 08 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
	*/

	jQuery.fn.getTwitter = function(options) {

		jQuery.fn.getTwitter.defaults = {
			userName: null,
			numTweets: 5,
			loaderText: "Loading tweets...",
			slideIn: true,
			slideDuration: 750,
			showHeading: true,
			headingText: "Latest Tweets",
			showProfileLink: true,
			showTimestamp: true
		};

		var o = jQuery.extend({}, jQuery.fn.getTwitter.defaults, options);

		return this.each(function() {
			var c = jQuery(this);

			// hide container element, remove alternative content, and add class
			c.hide().empty().addClass("twitted");

			// add heading to container element
			if (o.showHeading) {
				c.append("<h2>"+o.headingText+"</h2>");
			}

			// add twitter list to container element
			var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
			c.append(twitterListHTML);

			var tl = jQuery("#twitter_update_list");

			// hide twitter list
			tl.hide();

			// add preLoader to container element
			var preLoaderHTML = jQuery("<p class=\"preLoader\">"+o.loaderText+"</p>");
			c.append(preLoaderHTML);

			// add Twitter profile link to container element
			if (o.showProfileLink) {
				var profileLinkHTML = "<p class=\"profileLink\"><a href=\"http://twitter.com/"+o.userName+"\">http://twitter.com/"+o.userName+"</a></p>";
				c.append(profileLinkHTML);
			}

			// show container element
			c.show();

			jQuery.getScript("http://twitter.com/javascripts/blogger.js");
			jQuery.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
				// remove preLoader from container element
				jQuery(preLoaderHTML).remove();

				// remove timestamp and move to title of list item
				if (!o.showTimestamp) {
					tl.find("li").each(function() {
						var timestampHTML = jQuery(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						jQuery(this).attr("title", timestamp);
					});
				}

				// show twitter list
				if (o.slideIn) {
					// a fix for the jQuery slide effect
					// Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
					var tlHeight = tl.data("originalHeight");

					// get the original height
					if (!tlHeight) {
						tlHeight = tl.show().height();
						tl.data("originalHeight", tlHeight);
						tl.hide().css({height: 0});
					}

					tl.show().animate({height: tlHeight}, o.slideDuration);
				}
				else {
					tl.show();
				}

				// add unique class to first list item
				tl.find("li:first").addClass("firstTweet");

				// add unique class to last list item
				tl.find("li:last").addClass("lastTweet");
			});
		});
	};
})(jQuery);
 
/**** adjust these two parameters to control how fast or slow
**** the iframes grow/shrink ****/
 
// how many milliseconds we should wait between resizing events
 
var resizeDelay = 10;
 
// how many pixels we should grow or shrink by each time we resize
 
var resizeIncrement = 5;
 
// this will hold information about the iframes we're dealing with
 
var iframeCache = new Object();
 
 
/**
The getCacheTag function just creates a (hopefully) unique identifier for
each <iframe> that we resize.
*/
 
function getCacheTag (iframeElement) {
return iframeElement.src + "~" + iframeElement.offsetLeft + "~" + iframeElement.offsetTop;
}
 
 
/**
We're using this as a class to hold information about the <iframe> elements
that we're manipulating.
*/
 
function cachediframe (iframeElement, increment) {
this.iframe = iframeElement;
this.cacheTag = getCacheTag(iframeElement);
this.originalSrc = iframeElement.src;
 
var h = iframeElement.height;
var w = iframeElement.width;
this.originalHeight = h;
this.originalWidth = w;
 
increment = (!increment) ? resizeIncrement : increment;
this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
}
 
 
/**
This is the function that should be called in the onMouseOver and onMouseOut
events of an <iframe> element. For example:
 
<iframe src='onesmaller.gif' onMouseOver='resizeiframe(this, 150, "onebigger.gif")' onMouseOut='resizeiframe(this)'>
 
The only required parameter is the first one (iframeElement), which is a
reference to the <iframe> element itself. If you're calling from onMousexxx, 
you can just use "this" as the value.
 
The second parameter specifies how much larger or smaller we should resize
the iframe to, as a percentage of the original size. In the example above,
we want to resize it to be 150% larger. If this parameter is omitted, we'll
assume you want to resize the iframe to its original size (100%).
 
The third parameter can specify another iframe that should be used as the
iframe is being resized (it's common for "rollover iframes" to be similar but
slightly different or more colorful than the base iframes). If this parameter
is omitted, we'll just resize the existing iframe.
*/
 
function resizeiframe (iframeElement, percentChange, newIframeURL) {
// convert the percentage (like 150) to an percentage value we can use
// for calculations (like 1.5)
var pct = (percentChange) ? percentChange / 100 : 1;
 
// if we've already resized this iframe, it will have a "cacheTag" attribute
// that should uniquely identify it. If the attribute is missing, create a
// cacheTag and add the attribute
var cacheTag = iframeElement.getAttribute("cacheTag");
if (!cacheTag) {
cacheTag = getCacheTag(iframeElement);
iframeElement.setAttribute("cacheTag", cacheTag);
}
 
// look for this iframe in our iframe cache. If it's not there, create it.
// If it is there, update the percentage value.
var cacheVal = iframeCache[cacheTag];
if (!cacheVal) {
iframeCache[cacheTag] = new Array(new cachediframe(iframeElement), pct);
} else {
cacheVal[1] = pct;
}
 
// if we're supposed to be using a rollover iframe, use it
if (newIframeURL)
iframeElement.src = newiframeURL;
 
// start the resizing loop. It will continue to call itself over and over
// until the iframe has been resized to the proper value.
resizeiframeLoop(cacheTag);
return true;
}
 
 
/**
This is the function that actually does all the resizing. It calls itself
repeatedly with setTimeout until the iframe is the right size.
*/
function resizeiframeLoop (cacheTag) {
// get information about the iframe element from the iframe cache
var cacheVal = iframeCache[cacheTag];
if (!cacheVal)
return false;
 
var cachediframeObj = cacheVal[0];
var iframeElement = cachediframeObj.iframe;
var pct = cacheVal[1];
var plusMinus = (pct > 1) ? 1 : -1;
var hinc = plusMinus * cachediframeObj.heightIncrement;
var vinc = plusMinus * cachediframeObj.widthIncrement;
var startHeight = cachediframeObj.originalHeight;
var startWidth = cachediframeObj.originalWidth;
 
var currentHeight = iframeElement.height;
var currentWidth = iframeElement.width;
var endHeight = Math.round(startHeight * pct);
var endWidth = Math.round(startWidth * pct);
 
// if the iframe is already the right size, we can exit
if ( (currentHeight == endHeight) || (currentWidth == endWidth) )
return true;
 
// increase or decrease the height and width, making sure we don't get
// larger or smaller than the final size we're supposed to be
var newHeight = currentHeight + hinc;
var newWidth = currentWidth + vinc;
if (pct > 1) {
if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
newHeight = endHeight;
newWidth = endWidth;
}
} else {
if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
newHeight = endHeight;
newWidth = endWidth;
}
}
 
// set the iframe element to the new height and width
iframeElement.height = newHeight;
iframeElement.width = newWidth;
 
// if we've returned to the original iframe size, we can restore the
// original iframe as well (because we may have been using a rollover
// iframe in the original call to resizeiframe)
if ((newHeight == cachediframeObj.originalHeight) || (newWidth == cachediframeObj.originalwidth)) {
iframeElement.src = cachediframeObj.originalSrc;
}
 
// shrink or grow again in a few milliseconds
setTimeout("resizeiframeLoop('" + cacheTag + "')", resizeDelay);
}
 

