﻿$(document).ready(function() {
// Highlight active path
var path = location.pathname;
if (path) {
$('a[href$="' + path + '"]').addClass('active').parents().filter("li").addClass("active");
}

$('#tabs').tabs();
//$("div.news-bubble").click(function() {
//.document.location.href = $(this).find("a:first").attr("href");
//});

initIntroAnim();
initMenuSizeChanger();
initWindowShade();
initTeam();
initWork();
initSlide();
$('.main-content a[href*="vimeo.com"]').each(function() {
// Grab video ID from the url
var videoID = $(this).attr('href').match(/vimeo\.com\/(.+)+/);
if (videoID.length) {
videoID = videoID[1];
$(this).replaceWith('<div id="vimeo-embed-' + videoID + '">You need Flash player 8+ to view this video.</div>');
var params = { allowScriptAccess: 'always', allowfullScreen: 'false', wmode: 'transparent' };
var attrs = { id: 'vimeo-video-' + videoID }
// Embed the youtube video using SWFObject script
swfobject.embedSWF('http://vimeo.com/moogaloop.swf?clip_id=' + videoID + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=D6E03D&amp;fullscreen=0', 'vimeo-embed-' + videoID, '527', '290', '9', null, null, params, attrs);
}
});
// Global Highslide settings
hs.graphicsDir = '/App_Themes/Default/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.dimmingOpacity = 0.4;
});

function initIntroAnim() {
// Settings are all the same
var flashvars = {};
var flashparams = { wmode: "transparent" };
var flashatts = {};

// If the full animation hasn't been seen, show it
var introAnim = $.cookie('introAnim2');
if ((introAnim == null) || (!introAnim.length))
{
swfobject.embedSWF("/Media/Flash/ABCintro.swf", "intro", "620", "320", "9.0.0", false, flashvars, flashparams, flashatts, null);
$.cookie("introAnim2", "seenIt", { path: '/' });
}
// Otherwise show the shorter, alternate version
else {
swfobject.embedSWF("/Media/Flash/ABCintro-Alt.swf", "intro", "620", "320", "9.0.0", false, flashvars, flashparams, flashatts, null);
}
}

function initWork() {
$(".center a", "#slider").click(function() {
$(".center a", "#slider").removeClass("active");
var className = $(this).attr("class");
if (className.length) {
$(this).addClass("active");
filterWork(className);
}
else {
window.status = "Filtering for: View All";
$("li.cover", "#gallery").fadeOut('slow');
}
return false;
}
);
$("#gallery > li div.highslide-gallery a.highslide").qtip(
{ show: 
{ delay: 0, effect: 
{ type: "slide", length: 0}
}, position: {
 corner: {
  target: 'topMiddle', tooltip: 'bottomMiddle'}
   }, style: { width: 250, background: '#D6D28E', border: { width: 2, radius: 4, color: "#A04235" }, tip: { corner: 'bottomMiddle', color: '#A04235'}} }
   );
   
   $("#Twitter a").qtip({ content: { prerender: true, text: '<div id="tweet"><img src="/Media/Images/Twitter-Bird?width=50" style="float: right;" /><h4>Follow us on Twitter</h4></div>' }, api: { onRender: function() { getTweets(); } }, show: { delay: 0, effect: { type: "slide", length: 0} }, hide: { fixed: true, delay: 100 }, position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle'} }, style: { width: 200, background: '#D6D28E', textAlign: 'center', border: { width: 2, radius: 4, color: "#A04235" }, tip: { corner: 'bottomMiddle', color: '#A04235'}} }).attr("title", "").css("opacity", 0.5).hover(function() { $(this).stop().animate({ opacity: 1.0 }) }, function() { $(this).stop().animate({ opacity: 0.5 }) });
   $("#LinkedIn a").qtip({ content: { prerender: true, text: '<h4>Find us on Linked In</h4><p><a href="http://www.linkedin.com/companies/57729/Aloysius+Butler+%26+Clark?trk=pro_other_cmpy&goback=.hom"><img src="/Media/Images/LinkedIn-Screenshot" border="0" /></a></p>' }, show: { delay: 0, effect: { type: "slide", length: 0} }, hide: { fixed: true, delay: 100 }, position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle'} }, style: { background: '#D6D28E', textAlign: 'center', border: { width: 2, radius: 4, color: "#A04235" }, tip: { corner: 'bottomMiddle', color: '#A04235'}} }).attr("title", "").css("opacity", 0.5).hover(function() { $(this).stop().animate({ opacity: 1.0 }) }, function() { $(this).stop().animate({ opacity: 0.5 }) });
   $("#Facebook a").qtip({ content: { prerender: true, text: '<h4>Be our Facebook fan</h4><p><a href="http://www.facebook.com/pages/Wilmington-DE/Aloysius-Butler-Clark/32183238287"><img src="/Media/Images/Facebook-Screenshot" border="0" /></a></p>' }, show: { delay: 0, effect: { type: "slide", length: 0} }, hide: { fixed: true, delay: 100 }, position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle'} }, style: { background: '#D6D28E', textAlign: 'center', border: { width: 2, radius: 4, color: "#A04235" }, tip: { corner: 'bottomMiddle', color: '#A04235'}} }).attr("title", "").css("opacity", 0.5).hover(function() { $(this).stop().animate({ opacity: 1.0 }) }, function() { $(this).stop().animate({ opacity: 0.5 }) });
   $("#Blog a").qtip({ content: { prerender: true, text: '<div id="blogpost">&amp; Another Thing (Blog)</div>' }, api: { onRender: function() { getBlogPosts(); } }, show: { delay: 0, effect: { type: "slide", length: 0} }, hide: { fixed: true, delay: 100 }, position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle'} }, style: { width: 330, background: '#D6D28E', textAlign: 'center', border: { width: 2, radius: 4, color: "#A04235" }, tip: { corner: 'bottomMiddle', color: '#A04235'}} }).attr("title", "").css("opacity", 0.5).hover(function() { $(this).stop().animate({ opacity: 1.0 }) }, function() { $(this).stop().animate({ opacity: 0.5 }) });
   $("#YouTube a").qtip({ content: { prerender: true, text: '<h4>View our YouTube channel</h4><p><a href="http://www.youtube.com/user/AloysiusButlerClark"><img src="/Media/Images/YouTube-Screenshot" border="0" /></a></p>' }, show: { delay: 0, effect: { type: "slide", length: 0} }, hide: { fixed: true, delay: 100 }, position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle'} }, style: { background: '#D6D28E', textAlign: 'center', border: { width: 2, radius: 4, color: "#A04235" }, tip: { corner: 'bottomMiddle', color: '#A04235'}} }).attr("title", "").css("opacity", 0.5).hover(function() { $(this).stop().animate({ opacity: 1.0 }) }, function() { $(this).stop().animate({ opacity: 0.5 }) });
   
   var qs = $.deparam.querystring();
   // var indFilter = $.query.get('ind');
   // var expFilter = $.query.get('exp');
   // var medFilter = $.query.get('med');
   var filterPrefix = "";
   var filterValue = "";
   if (qs["ind"]) {
   filterPrefix = "ind";
   filterValue = qs["ind"];
   }
   else if (qs["exp"]) {
   filterPrefix = "exp";
   filterValue = qs["exp"];
   }
   else if (qs["med"]) {
   filterPrefix = "med";
   filterValue = qs["med"];}
   if (filterValue != "") {
   setTimeout(function() {
   setInitialWorkFilter(filterPrefix, filterValue);
}, 1000);
}
}

function getTweets() {$("#tweet").tweet({username: "abcadvertising",join_text: "auto",avatar_size: 32,count: 1,auto_join_text_default: "we said,",auto_join_text_ed: "we",auto_join_text_ing: "we were",auto_join_text_reply: "we replied to",auto_join_text_url: "we were checking out",loading_text: "Loading latest tweet..."});
}

function getBlogPosts() {
jQuery.getFeed({
url: '/Utilities/Proxy.ashx?url=http://blog.a-b-c.com/feed',
success: function(feed) {
var text = "<h4><img src='/Media/Images/blog-lamp?width=75' style='float: right;' />&amp; Another Thing (Blog)</h4>";
for (var i = 0; i < feed.items.length && i < 1; i++) {
text += "<h5>" + feed.items[i].title + "</h5>";
text += "<p>" + feed.items[i].description + "</p>";
text += "<p><a href='" + feed.items[i].link + "'>Read at blog.a-b-c.com</a></p>";
$("#blogpost").html(text);
}
}
});
}

function setInitialWorkFilter(prefix, value) {
$("a."+ prefix + "-" + value).addClass("active").parents("div.block").slideDown({ duration: 500, easing: "easeOutBack" });
filterWork(prefix + "-" + value);
}
function filterWork(className) {
//window.status = "Filtering for: " + className;
$("li", "#gallery").each(function() {
if (!$(this).hasClass(className)) {
$(this).find(".cover").fadeIn('slow');
}
else {
$(this).find(".cover").fadeOut('slow');
}
});
}

function initWindowShade() {
var animLength = 250;
// Set up the window shade for e-mail updates
$("p.open-close a", "#shade").toggle(
function() 
{
$("#shade").addClass("active").animate({ top: "-90px" }, animLength, "easeOutBack");
$(this).find("span").text("Close");
},
function() {
$("#shade").removeClass("active").animate({ top: "-172px" }, animLength, "easeInBack");
setTimeout(function() {
$("#shade").find("p.open-close span").text("Stay in touch with e-mail updates.")}, animLength);
}
);
}
function initTeam() {
// Highlight questions when hovering over headshots
$("li", "#team-headshots").hoverIntent(function() {

var username = $(this).attr("id").match(/-(.+)/)[1];
$("a", "#team-questions").removeClass("active");
var question = $("a:first", "#question-" + username);
question.addClass("active");
question.parents().filter("li").highlightFade({ color: "#AFAC74", speed: 1000 });
$(".txt-area:first").stop().scrollTo(question, 250, { easing: "swing", offset: -75 });
}, function()
 {
// null
});
// Hookup Highslide to headshots
$("li a", "#team-headshots").each(function() {
this.onclick = function() {
return hs.htmlExpand(this, { objectLoad: 'after', align: 'center', outlineType: 'rounded-white', preserveContent: false, width: 530, height: 320, dimmingOpacity: 0.5, allowSizeReduction: false }
);
};
}).hover(function() {
$("img", "#team-headshots").removeClass("active");
}, function() {
});

// Hook up events to questions
$("li a", "#team-questions").click(function() {
var username = $(this).parents().filter("li:first").attr("id").match(/-(.+)/)[1];
$("a:first", "#thumb-" + username).click();
}).hoverIntent(function() {
var username = $(this).parents().filter("li:first").attr("id").match(/-(.+)/)[1];
$("img", "#team-headshots").removeClass("active");
$("img", "#thumb-" + username).addClass("active");
}, function() {
});
// Clear active state on questions
$("li", "#team-questions").hover(function() {
$("a", "#team-questions").removeClass("active");
});
// Scroll up
$("#arrow-prev").click
(function() {
$(".txt-area:first").scrollTo({ top: '-=345px', left: '0px' }, 250, { easing: "swing" });
return false;
});
// Scroll down
$("#arrow-next").click(function() {
$(".txt-area:first").scrollTo({ top: '+=345px', left: '0px' }, 250, { easing: "swing" });
return false;
});
}
function initMenuSizeChanger() {
// Main Nav
$("li ul li", "#nav").hover(function() {
if (!$(this).hasClass("active")) {
$(this).stop().css("fontSize", "12px").animate({ fontSize: "16px" }, 100);
}
}, function() {
$(this).stop().animate({ fontSize: "12px" }, 100);
});
$("#nav > li").hover(function() {
if (!$(this).hasClass("active"))
{
$(this).stop().css("fontSize", "15px").animate({ fontSize: "22px" }, 100);
}
}, function() {
$(this).stop().animate({ fontSize: "15px" }, 100);
});
// Sub Nav
$("#side-nav > li").hover(function() {
if (!$(this).hasClass("active")) {
$(this).stop().css("fontSize", "12px").animate({ fontSize: "18px" }, 100);
}
}, function() {$(this).stop().animate({ fontSize: "12px" }, 100);
});
$("li ul li", "#side-nav").hover(function() {
if (!$(this).hasClass("active")) {
$(this).stop().css("fontSize", "12px").animate({ fontSize: "16px" }, 100);
}
}, function()
 {
$(this).stop().animate({ fontSize: "12px" }, 100);
});
}
function initSlide() {
var _holder = $(".slider");
var _itemClass = "slide-block";
var _slideClass = "block";
var _durOut = 500;
var _durIn = 150;
_holder.each(function() {
var _item = $(this).find("." + _itemClass);
_item.not(".active").find("." + _slideClass).slideUp(0);
_item.each(function() {
var _link = $(this).find("a.open-close");
_link.click(function() {
if (!$(this).parents("." + _itemClass).hasClass("active")) {
_item.each(function() {
$(this).removeClass("active");
$(this).find("." + _slideClass).slideUp({ duration: _durIn, easing: "swing" });
});
$(this).addClass("selected");
$(this).parents("." + _itemClass).addClass("active");
$(this).parents("." + _itemClass).find("." + _slideClass).slideDown({ duration: _durOut, easing: "easeOutBack" });
};
return false;
});
})
});
}
function embedVideo(videoURL, previewContainer) {
//alert('fired');
if (videoURL.indexOf('youtube') >= 0) {
var videoID = youtubeIDextract(videoURL);
var content = '<div id="youtube-embed-' + videoID + '">You need Flash player 8+ to view this video.</div>';
$(previewContainer).html(content);
var params = { allowScriptAccess: 'always', allowfullScreen: 'false' };
var attrs = { id: previewContainer.id };
swfobject.embedSWF('http://www.youtube.com/v/' + videoID + '&enablejsapi=1&playerapiid=youtube-api-' + videoID, 'youtube-embed-' + videoID, '530', '319', '8', null, null, params, attrs);
}
}
function embedAudio(audioURL, previewContainer) {
//alert('fired');
if (videoURL.indexOf('youtube') >= 0) {
var params = { allowScriptAccess: 'always', allowfullScreen: 'false' };
var attrs = { id: previewContainer.id };
var vars = { soundFile: audioURL, playerID: 1 };
swfobject.embedSWF('/Media/Flash/player.swf', '530', '319', '8', null, vars, params, attrs);
}}
