function toggleBio(a)
{
  if($('.bio-'+a).css('display')=='block')
  {
    $('.link-'+a).html('Read More');
  }
  if($('.bio-'+a).css('display')=='none')
  {
    $('.link-'+ a).html('Hide');
  }
  $('.bio-'+a).slideToggle();
}
function updateSelector() {
  var value = $('#the-select option:selected').val();
  $('#select-cover').html(value);
}

function toggleYear(a)
{
  if(a>0)
  {
    $('.news-article').hide();
    $('.year-'+a).show();
  }
  if(a==0)
  {
    $('.news-article').show();
  }
}

function toggleProject(a)
{
  if(a!=0)
  {
    $('.project').hide();
    $('.project-type-'+a).show();
  }
  if(a==0)
  {
    $('.project').show();
  }
}
function filtersOver(a,b)
{
  $('#'+a).css('background','url("/media/'+b+'.png") repeat scroll 0 0 transparent');
}
function blogsOver(a)
{
  $('#'+a).css('background','none repeat scroll 0 0 #000000');
  $('#'+a).css('color','#FFFFFF');
}
function blogsOut(a)
{
  $('#'+a).css('background','none repeat scroll 0 0 #FFFFFF');
  $('#'+a).css('color','#000000');
}
function filtersOver2(a,b)
{
  $('#'+a).css('background','url("/media/'+b+'.jpg") repeat scroll 0 0 transparent');
}


/* Photo Gallery
------------------------------------------------------- */

function carousel(totalperpage,spacing,containerwidth) {
  
  $('.the-carousel-gallery').each(function()
  {
    //Carousel
    var total = $(this).find('.item').length;
    var items = $(this).find('.item');
    var itemsperpage = totalperpage;
    var total2 = Math.ceil(total / itemsperpage);
    var slideshow_width =  containerwidth || $(this).find('.navigation').width();
    var total_width = total2 * slideshow_width;
    var first = $(this).find('.item:first');
    var npos = 0;
    var padding = spacing || 0;
    var n = 0;
    var p = 0;

    //Create carousel thumbnails
    if($(this).find(".small").length) {
       $(this).find(".thumb,.thumb-link").each(function(i){   
           $(this).css("cssText","background:url("+$(this).find('.small').attr('src').replace(/ /g,"%20").replace(/'/g,"%27").replace("(","%28").replace(")","%29")+") no-repeat 50% 50%");
       });  
    }
    
    $(this).find(".screen").css("width","20000em");   
    
    //Add a wrapper every X items
    if($(this).parent(".ma-gallery").length) {
       for(var i = 0; i < total; i+=itemsperpage) {
          items.slice(i, i+itemsperpage).wrapAll("<div class='wrapper'></div>");
       } 
    }
    
    //Navigation for thumbnails
    $(this).find('.prev').unbind('click').bind('click',function(e) {
      e.preventDefault();
      npos--;
      if(npos < 0) npos = 0;
      (!Modernizr.csstransitions)?$(this).parents('.the-carousel-gallery').find('.screen').stop().animate({left:npos * -(slideshow_width+padding)}, 350):$(this).parents('.the-carousel-gallery').find('.screen').css({"left":npos * -(slideshow_width+padding)});
    });
    
    $(this).find('.next').unbind('click').bind('click',function(e) {
      e.preventDefault();
      npos++;
      if(npos >= total2) npos = total2-1;
      (!Modernizr.csstransitions)?$(this).parents('.the-carousel-gallery').find('.screen').stop().animate({left:npos * -(slideshow_width+padding)}, 350):$(this).parents('.the-carousel-gallery').find('.screen').css({"left":npos * -(slideshow_width+padding)});
    });
    
    //Navigation for image pane
    $(this).find('.next-pane').unbind('click').bind('click',function() {
         p = 0;
         $(this).parent().find(".thumb.active").parent().next().find(".thumb").click();
         if(n==1) {      
           $(this).parent().find(".next").click();
           $(this).parent().find(".thumb.active").parents(".wrapper").next().find(".thumb:first").click();
           n=0;
         }
         $(this).parent().find(".wrapper").each(function() {
           ($(this).find(".thumb:last").hasClass("active"))?n=1:false;
         });
    });
    $(this).find('.prev-pane').unbind('click').bind('click',function() {
         n = 0;
         $(this).parent().find(".thumb.active").parent().prev().find(".thumb").click();
         if(p==1) {      
           $(this).parent().find(".prev").click();
           $(this).parent().find(".thumb.active").parents(".wrapper").prev().find(".thumb:last").click();
           p=0;
         }
         $(this).parent().find(".wrapper").each(function() {
           ($(this).find(".thumb:first").hasClass("active"))?p=1:false;
         });

    });
   
    //Update gallery pane on click
    $(this).find(".thumb").unbind('click').bind('click',function(e) {
       e.preventDefault();

       $(this).parents(".navigation").prev().find("img").fadeOut().load(function() {
            $(this).fadeIn();
       }).attr("src",$(this).find("img").attr("url"));
       
       //text
       $(this).parents(".the-carousel-gallery").find(".info-pane h2").html($(this).find("img").attr("alt"));
       $(this).parents(".the-carousel-gallery").find(".info-pane span").html($(this).find("img").attr("desc"));

       $(this).parents(".the-carousel-gallery").find(".thumb").removeClass("active");
       $(this).addClass("active");
      
    });  
    
    //Init
    //$(this).parent().find(".info-pane h2").html($(this).find(".item img:first").attr("alt"));
    //$(this).parent().find(".info-pane span").html($(this).find(".item img:first").attr("desc"));
    //$(this).find(".thumb:first").addClass("active");
    $(this).find(".thumb:first").click();
    
  //end each()  
});  

}


var openPopup = window.open;

function show_msg(msg) { alert(msg); }

function validateForm() {
	missing_required = 0;

	for (i = 0; i < arguments.length; i++) {
		if(arguments[i] == '') {
			missing_required = 1;
		}
	}

	if(missing_required) {
		alert("A required form field is missing.");
		return false;
	} else {
		return true;
	}
}

function expCustomLink(myURL) {
	location.href = myURL;
}

function setUrl(path) {
	document.location.href = path;
}

function expArticleLink(sectionId, articleId) {
	location.href = '/index.php?section_id=' + sectionId + '&section_copy_id=' + articleId;
}

function expPopupWindow(url, widthVal, heightVal, resizableVal, scrollbarsVal, toolbarVal, locationVal, directoriesVal, statusVal, menubarVal, copyHistoryVal) {

	var attributes = "width="  	 	 + widthVal       +
				 	 ",height=" 	 + heightVal      +
				 	 ",resizable="  + resizableVal  +
				 	 ",scrollbars="  + scrollbarsVal  +
				 	 ",toolbar=" 	 + toolbarVal 	  +
				 	 ",location=" 	 + locationVal 	  +
				 	 ",directories=" + directoriesVal +
				 	 ",status=" 	 + statusVal 	  +
				 	 ",menubar=" 	 + menubarVal 	  +
				 	 ",copyhistory=" + copyHistoryVal;

	window.open(url, 'WindowName', attributes);
}

function xprLog(msg) {
    if (window.console) console.log(msg);
}

if (document.addEventListener) {  
    document.addEventListener("DOMContentLoaded", function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); }, false);
} else if (document.attachEvent) {  
    document.attachEvent('DOMContentLoaded', function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); });
}  

