// Extractable Custom JavaScript
var $j = jQuery.noConflict();

var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);

// Start Document Ready Calls
$j(document).ready(function(){
	
	$j('#iphone').hide();
	
	
	/*
	//if banner exists
	if ($j('#banner').length) {
		var index=0;
		
		//scale the awards
		$j('#awards li').each(function(){
			//var randomnumber=Math.floor(Math.random()*index)
			$j(this).delay(75*index).show("scale", {origin:['middle','center']}, 1500);
			index++;
		});
		
    }
	*/
	if ($j('#recentBlogPost').length) {
	$j.getJSON('/blog/?json=1&count=1', function(data) {
	  var blogPost = "";

	  var jsonPost = data.posts[0];
	  //alert(jsonPost.title);
	  blogPost+= "<h2><span>" + $j.format.date(jsonPost.date, "MM/dd/yyyy") + "</span><br/>" + jsonPost.title + "</h2><p>" + jsonPost.content.substring(0, 190) + "... <a class=\"arrow\" href=\"" + jsonPost.url +  "\"> Read More</a></p>";
	  $j('#recentBlogPost').html(blogPost);
/*
	  $('<ul/>', {
		'class': 'my-new-list',
		html: items.join('')
	  }).appendTo('body');*/
	});
	}
	
	
	/********************************************/
	//		Font Replacement
	/********************************************/
	Cufon.replace('.cufon');
	
	/**********************************/
	// Stretching the Background Image
	/**********************************/
	$j.backstretch("/common/css/img/ext-stretch.jpg", {speed: 150});
	
	/**********************************/
	//		Equal Heights Calls
	/**********************************/
	equalHeight($j(".equal"));
	equalHeight($j(".equalBox"));
	
	/**********************************/
	//		Case Studies Slide Show
	/**********************************/
	if ($j('.slideshow').length) {
		$j('.slideshow').cycle({
			fx: 'fade',
			speed:  1500,
			timeout: 5000
		});
	};
	
	/********************************************/
	//		Accessible Tabs
	/********************************************/
	if ($j('.tabs').length) {
		$j(".tabs").accessibleTabs({
			tabhead:"h3",
			fx:"fadeIn",
			autoAnchor:true
		});
	};
	
	/********************************************/
	//		LightBox (ColorBox)
	/********************************************/
	if ($j('.lightbox').length) {
		$j(".lightbox").colorbox();
	};
	if ($j('.video').length) {
		$j(".video").colorbox({iframe:true, innerWidth:600, innerHeight:338});
	};
	
	/**********************************/
	//		Portfolio Sliders
	/**********************************/
	$j(function() {
		$j('.homefoliocontainer').hover(function(){	
				$j(this).find('.foliopic').animate({"opacity":"0.6"},800); 
				$j(this).find('.foliotext').animate({"marginTop":"-129px", "height":"186px"},200); 
			}, function(){
				$j(this).find('.foliotext').animate({"marginTop":"0", "height":"57px"},300); 
				$j(this).find('.foliopic').animate({"opacity":"1"},800); 				
		});
	});
	
	/**********************************/
	//		Portfolio Sliders
	/**********************************/
	$j(function() {
		$j('.videocontainer').hover(function(){	
				$j(this).find('.videopic').animate({"opacity":"0.6"},800); 
				$j(this).find('.videotext').animate({"marginTop":"-125px", "height":"186px"},200); 
			}, function(){
				$j(this).find('.videotext').animate({"marginTop":"", "height":"57px"},300); 
				$j(this).find('.videopic').animate({"opacity":"1"},800); 				
		});
	});
		
});
// End Document Ready Calls

/////////////////////////////////////////////
//jQuery Accessible Tabs - DO NOT DELETE
/////////////////////////////////////////////
document.documentElement.className += " js";


////Messing around with some javascript
$j(window).load(function() {
	//$j('#iphone').fadeTo(0, 1000).delay(3000).animate({"top": "+=1200"},{duration:1500, easing:"easeInOutQuart"}); 
	
	$j('#iphone').delay(1000).fadeIn('slow');
});

/////////////////////////////////////////////

//Equal Heights with JavaScript

/////////////////////////////////////////////

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $j(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

/////////////////////////////////////////////

//Current Page Menu Highlight

/////////////////////////////////////////////

function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();               
}

function setActiveMenu(arr, crtPage)
{
	for (var i=0; i<arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].className = "current";
				arr[i].parentNode.className = "current";
			}
		}
	}
}

function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;

	if (document.getElementById("gridWrap")!=null)
		setActiveMenu(document.getElementById("gridWrap").getElementsByTagName("a"), extractPageName(hrefString));
}

