$(window).load(function() {
	
	// add a last class to the 3rd item from each row
	$("#latest_work li:nth-child(3n)").addClass("last");
	
	var lis = $("#latest_work li");
	$("#latest_work li").hover(
	  function () {
		$(this).find('.description-overlay').animate({top:'20px'}, 300, 'easeOutExpo');
	  },
	  function () {
		$(this).find('.description-overlay').animate({top:'140px'}, 200, 'easeOutExpo');
	  }
	);
	
	// portfolio item animation
	var portfolio_items = $("#portfolio_items .tab_content li");
	var portfolio_items_height = $("#portfolio_items .tab_content li").css('height');

	portfolio_items.each(function(el){
		$(this).find('.description-overlay').css({'height':portfolio_items_height,'top':portfolio_items_height});
	})
	
	portfolio_items.hover(
	  function () {
		$(this).find('.description-overlay').animate({top:0}, 300, 'easeOutExpo');
	  },
	  function () {
		$(this).find('.description-overlay').animate({top: portfolio_items_height}, 200, 'easeOutExpo');
	  }
	);
	
	// add a plus to the services & clients lists
	$('#sidebar ul.menu li, .newsletter li').prepend("<span>+</span>");
	
	// display random testimonial
	var list = $(".testimonials ul li").toArray();
	var elemlength = list.length; 
	var randomnum = Math.floor(Math.random()*elemlength);
	var randomitem = list[randomnum];
	$(randomitem).css("display", "block");

	//initialize the menu
	$(function($){ $("ul.sf-menu").supersubs({minWidth:13, maxWidth:30, extraWidth:0}).superfish({hoverClass:'sfHover', pathClass:'sf-active', pathLevels:0, delay:500, animation:{height:'show'}, speed:'def', autoArrows:1, dropShadows:0}) });

	// initialize colorbox
	$("a[rel='colorbox']").colorbox();
	$("a[rel='samples']").livequery(function(){
		$(this).colorbox({iframe:true, width:700, height:395});
	});
	$(".video").livequery(function(){
		$(this).colorbox({iframe:true, width:650, height:450}); 
	});
	$(".page-image").livequery(function(){
	  $(this).colorbox({iframe:true, width:800, height:600}); 
	});

	// initialize infield labels
	$("#newsletter_form label, #header_form label, .searchbox label, #commentform label, #contact-form label ").inFieldLabels();
	
	// FAQ Code
	$('#faqs h3').each(function() {
		var tis = $(this), state = false, answer = tis.next('div').hide().css('height','auto').slideUp();
		tis.prepend("<span>+</span> ")
		tis.click(function() {
		  state = !state;
		  answer.slideToggle(state);
		  tis.toggleClass('active',state);
		  if(tis.hasClass('active')) {
			  tis.find('span').text('→');
		  } else {
			  tis.find('span').text('+');
		  }
		});
});
	$('#key_people h3').each(function() {
		var tis = $(this), state = false, answer = tis.next('div').hide().css('height','auto').slideUp();
		tis.prepend("<span>+</span> ")
		tis.click(function() {
		  state = !state;
		  answer.slideToggle(state);
		  tis.toggleClass('active',state);
		  if(tis.hasClass('active')) {
			  tis.find('span').text('-');
		  } else {
			  tis.find('span').text('+');
		  }
		});
	}); // end each faqs
	
// Zoom frame ----------------------------------------------------------
        $(".media-image,.media-link,.media-video").live("mouseover mouseout", function(event) {
            var thisItem = $(this);
            var width = thisItem.width();
            var height = thisItem.height();

            // Check if element has zoom frame and append if has not
            thisItem.not(':has(.zoom-frame)')
                   .css({position: "relative"})
                   .append("<span class='zoom-frame'><span class='zoom-frame-icon' /></span>");

            // Set zoom frame dimentions
            var zoomFrame = thisItem.find(".zoom-frame");
            var zoomFrameIcon = thisItem.find(".zoom-frame-icon");

            zoomFrame.width(thisItem.width() - 10).height(thisItem.height() - 10);

            // Animation
            if (event.type == "mouseover") {
                 zoomFrame.stop().fadeTo("slow", 1);
                 zoomFrameIcon.stop().animate({top: "50%"});
            } else {
                zoomFrame.stop().fadeTo("slow", 0);
                zoomFrameIcon.stop().animate({top: "70%"});
            }
        });
	
	//twitter
	$("#twitter").getTwitter({
		// change here the Twitter username
		userName: "BeholderPro",
		numTweets: 2,
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true
	});
})

// Google Map

  google.load("feeds", "1");

  function feedLoaded(result) {
    if (!result.error) {
      var older = document.getElementById("oldercontent");

      for (var i = 0; i < result.feed.entries.length; i++) {
        var entry = result.feed.entries[i];
        var div = document.createElement("div");
        var li = document.createElement("li");

        var link = entry.link;
		var month=new Array(12);
		  month[0]="January";
		  month[1]="February";
		  month[2]="March";
		  month[3]="April";
		  month[4]="May";
		  month[5]="June";
		  month[6]="July";
		  month[7]="August";
		  month[8]="September";
		  month[9]="October";
		  month[10]="November";
		  month[11]="December";
       
        var entrydate=new Date(entry.publishedDate) //get date of entry
        var entrydatestr=' '+month[entrydate.getMonth()]+"&nbsp;"+entrydate.getDate()+",&nbsp;"+entrydate.getFullYear()
        
        var title = entry.title;
        var post = entry.content;

        li.innerHTML = '<a href="' + link + '">' + title + '</a><br /><span>Posted on ' + entrydatestr + '</span>';
        older.appendChild(li);
      }
    }
  }
  function OnLoad() {
    var feed = new google.feeds.Feed("http://feeds.feedburner.com/BeholderProductions");
    feed.setNumEntries(4);
    feed.load(feedLoaded);

  }
  google.setOnLoadCallback(OnLoad);
