
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



$(document).ready(function() {

    // When the collapse button is clicked:
    	$("#ribbonClose").click(function () {
			$('#beforeBranding').animate({height:"0px"},550);
    		$("#ribbonClose").slideUp("slow");
    		$("#ribbonOpen").slideDown("slow");

        $.cookie('leftCol', 'collapsed');
    });
    
    // When the expand button is clicked:
        $("#ribbonOpen").click(function () {
        	$('#beforeBranding').animate({height:"54px"},550);
    		$("#ribbonOpen").slideUp("slow");
    		$("#ribbonClose").slideDown("slow");
    		
        $.cookie('leftCol', 'expanded');
    });

// COOKIES

    // Left column state
    var leftCol = $.cookie('leftCol');

    // Set the user's selection for the left column
    if (leftCol == 'collapsed') {
    	$('#beforeBranding').css("height","0px");
        $('#ribbonClose').css("display","none");
        $('#ribbonOpen').css("display","block");

    };
    
    

 
});


jQuery(function() {
	jQuery('.ie7 .image-overlay a, .ie8 .image-overlay a, .ie9 .image-overlay a').hover(function(){jQuery(this).find('span').stop(false,true).fadeIn(300);},
    function(){jQuery(this).find('span').stop(false,true).fadeOut(300);});
});

	
	$(".ca-menu li").focus(function() { // Mouse over
   $(this)
      .stop().fadeTo(200, 1)
      .siblings().stop().fadeTo(200, 0.5);
      
      }, function() { // Mouse out
   $(this)
      .stop().fadeTo(200, 1)
      .siblings().stop().fadeTo(200, 1);
      
      });
     
 
 function setHover() {
    if ($('.ca-menu .active').next().length) {
        $('.ca-menu .active').next().addClass('active ca-iconi ca-maini').end().removeClass('active ca-iconi ca-main');
    } else {
        $('.ca-menu .active').removeClass('active ca-iconi ca-maini');
        $('.ca-menu li:first-child').addClass('active ca-iconi ca-maini');
    }
}

setInterval(setHover, 3000);


	$(document).ready(function() {
	$('.welcome-link').tipsy({live: true, gravity: 's'});
  	});    



/*******************************************************************************
 PORTFOLIO LOADING
*******************************************************************************/ 

$("body").ready(function () {
	$(".awesome-fix").slideUp();
    $("#portfolio").fadeIn("slow");
    });
    
    $("body").ready(function () {
    $("#welcomePort").fadeIn(400);
    });
    



$("#slider").ready(function () {
    $("img").fadeIn("slow");
    });
    
    
    jQuery(function () {
    
    
			jQuery('.image img').css("display","none");
		});
		var i = 0;
		var int=0;
		jQuery(window).bind("load", function() {
			var int = setInterval("loadImage(i)",200);
		});
		function loadImage() {
			var imgs = jQuery('.image img').length;
			if (i >= imgs) {
				clearInterval(int);
			}
			jQuery('.image img:hidden').eq(0).fadeIn(400);
			i++;
		}



/* ------------------------------------------------------------------------
Tabs - Type 1
* ------------------------------------------------------------------------- */

jQuery(document).ready(function () {


    doTabsType1();
    
});

function doTabsType1(){
    var tabs = jQuery('.tabs_type_1');
    if(tabs.length < 1){
        return;
    }
    
    tabs.append("<span class='tabs_type_1_arrow'></span>");
    tabs.each(function(){
        var self = jQuery(this);
        var handlers = self.children('#anchor');
        var tabContentBlocks = self.children('dd');
        var currentTab = tabContentBlocks.eq(0);
        var arrow = self.children('span').eq(0);
        var handlersWidth = handlers.eq(0).outerWidth();
        var firstHandlerY = handlers.eq(0).position().top + handlers.eq(0).outerHeight() - 17;
        arrow.css({'left': handlersWidth-17 + 'px', 'top': firstHandlerY + 'px'});
        handlers.click(function(){
            var self = jQuery(this);
            currentTab.prev().removeClass('current');
            currentTab.fadeOut('fast');
            currentTab = self.next();
            var minus = self.index() == 0 ? 17 : self.outerHeight()/2 + 17;
            arrowY = self.position().top + self.outerHeight() - minus;
            arrow.animate({'top':arrowY + 'px'});
            currentTab.fadeIn('slow');
            self.addClass('current');
        });
    });
}

$(function(){
  
  // Bind an event to window.onhashchange that, when the hash changes, gets the
  // hash and adds the class "selected" to any matching nav link.
  $(window).hashchange( function(){
    var hash = location.hash;
    
    
    // Iterate over all nav links, setting the "selected" class as-appropriate.
    $('a#anchor').each(function(){
      var that = $(this);
      that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'selected' );
    });
  })
  
  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).hashchange();
  
});
