// Preload Slideshow Images
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
$.preloadImages("/images/portfolio/aeventures.jpg", "/images/portfolio/forta.jpg","/images/portfolio/tdesignstudio.jpg");

// Forcing New Window Links
function setLinks() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  if (links.length == 0) return false;
  for (var i = 0; i < links.length; i++) {
    var relation = links[i].getAttribute("rel");
    if (relation == "external") {
      links[i].onclick = function() {
        return !window.open(this.href);
      }
    }     
  }
}

// Highlight
jQuery.fn.clearDefault = function(options) {       
    
    settings = jQuery.extend({
        highlightClass: "highlight"
    }, options);
    
    return this.each(function() {
        jQuery(this).focus(function() {
            if( this.value == this.defaultValue )
                jQuery(this).attr("value", "").addClass(settings['highlightClass']);
        }).blur(function() {
            if( !this.value.length )
                jQuery(this).attr("value", this.defaultValue).removeClass(settings['highlightClass']);
        });        
    });
};

// Slideshow
$(document).ready(function() {
	if( $.browser.msie && $.browser.version < 7 )
		jQuery.fx.off = true;
	$('#portfolio').prepend('<a class="trigger" rel="generated" href="#">View Selected Projects <span>+ Open</span></a>');
	$("input[type=text]").clearDefault();
	$('#portfolio .slideshow').append('<div class="pager" rel="generated"></div>');
	$('#portfolio .slideshow').hide();
	$('#portfolio .trigger').click(function(event){
		event.preventDefault();
		$('.slideshow').slideToggle('fast',function(){
			if( $('#portfolio .slideshow').css('display') == 'none' ){
				$('.trigger span').html('+ Open');
			}else{
				$('.trigger span').html('- Close');
			}
		});
	});	
	if( $.browser.msie ){
		$('.slideshow ul').cycle({
			fx: 'fade',
			speed:1,
			pager:$('.pager')
		});
	}
	else{
		$('.slideshow ul').cycle({
			fx: 'fade',
			speed:500,
			pager:$('.pager')
		});	
	}
	
// Toggle Section Content
	$(".column img").hover(
		function() {
			this.src = this.src.replace(".png","Hover.png");
		},
		function() {
			this.src = this.src.replace("Hover.png",".png");
		}
	);
	
	$('.more').hide();
	$('a.about').click(function() {
	$('.first .more').slideToggle(100);
	return false;
	});
	$('a.work').click(function() {
	$('.second .more').slideToggle(100);
	return false;
	});
	$('a.expertise').click(function() {
	$('.third .more').slideToggle(100);
	return false;
	});
});