
$(document).ready(function(){ 
	Cufon.replace('#slider_data .title', { fontWeight: '400' });
	Cufon.replace('#content h2', { fontWeight: '400' });
	Cufon.replace('#content_right h2', { fontWeight: '400' });
	Cufon.replace('#content h3', { fontWeight: '400' });
	Cufon.replace('#header-nav', { fontWeight: '400' });
	Cufon.replace('.work-headline', { fontWeight: '400' });
	//alignGrid("photoset", 3, 7, 7, 1);
	$(document).pngFix();
	$("a[href^=http://]").not("a[href^=http://clearmpls.com]").attr("target", "_blank");
	$("a[href^=http://]").not("a[href^=http://clearmpls.com]").attr("rel", "external");
	
	var cookie = $.cookie("kilo");
	if (!cookie){
		//launchKiloModal(); // sets cookie if modal is closed, but not if you just come back a 2nd time
	}	
	
	Shadowbox.init({
    	players: ['img', 'flv', 'mp4'],
       	fadeDuration: .7
	});
	Shadowbox.setup("a.videoplayer");
	
	$("a[rel*='external']").click(function(){
		pageTracker._trackPageview('/outgoing/'+ $(this).attr('href'));
	});	
});

function launchKiloModal() {
	var popID = $('#kilo-modal');
	Cufon.replace('#kilo-modal h1', { fontWeight: '400' });
	
	popID.fadeIn().prepend('<a href="#" class="close closeIt">close</a>');	
	var popMargTop = (popID.height() / 2) + 100;
	var popMargLeft = popID.width() / 2;
	// margin
	popID.css({ 
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});
	
	$('body').append('<div id="fade"></div>');
	$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
	
	$('a.closeIt, #fade').live('click', function() {
		$.cookie("kilo", "shown", { expires: 1 });
	  	$('#fade, #kilo-modal').fadeOut(function() {
			$('#fade, .close').remove();  
		});
		return false;
	});	
}

function moveCloseLink() { 
	    cb=document.getElementById( 'sb-nav-close' ); 
	    tb=document.getElementById( 'sb-title' ); 
	
	    if( tb ) 
	        tb.appendChild(cb); 
	} 

function getFlashMovie(movieName) {
  	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		if(document[movieName].length != undefined){
			return document[movieName][1];
		}
		return document[movieName];
	}
}

function triggerVideo(assetPath, titleVar, wid, hei){
	var vidWidth = 640;
	var vidHeight = 480;
	if (wid){
		vidWidth = wid;
	}
	if (hei){
		vidHeight = hei;
	}
	Shadowbox.open({
        player:     'flv',
        title:      titleVar,
        content:    assetPath,
        width:      vidWidth,
		height:     vidHeight
    });
}

function alignGrid(/*string*/ id, /*int*/ cols, /*int*/ cellWidth, /*int*/ cellHeight, /*int*/ padding) {
	var x = 0;
	var y = 0;
	var count = 1;
	jQuery("#" + id).each(function() {1
	    jQuery(this).css("position", "relative");2
	    jQuery(this).children("div").each(function() {3
	        jQuery(this).css("width", cellWidth + "em");
	        jQuery(this).css("height", cellHeight + "em");
	        jQuery(this).css("position", "absolute");
	        jQuery(this).css("left", x + "em");
	        jQuery(this).css("top", y + "em");
	        if ((count % cols) == 0) {4
	            x = 0;
	            y += cellHeight + padding;
	        } else {
	            x += cellWidth + padding;
	        }
	        count++;
	    });
	});
}

function workImageFadeInit() {
	$('#slider ul li').css({opacity: 0.0});
	$('#slider ul li:first').animate({opacity: 1.0}, 700).addClass('show').css({"display":"block"});
	var current = $('#slider ul li:first');
	var next = $('#slider ul li:second');
	$('#slider ul li').click(function(e){
		e.preventDefault();
		nextImage();
	});
}

function nextImage() {
	var current = ($('#slider ul li.show')?  $('#slider ul li.show') : $('#slider ul li:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#slider ul li:first') :current.next()) : $('#slider ul li:first'));	
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 700).css({"display":"block"});
	current.animate({opacity: 0.0}, 700).removeClass('show');
	/*
current.animate({opacity: 0.0}, 300, function() { 
			current.removeClass('show');
			next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 300);
		});
*/
}


