/**
 * jCarouselLite - jQuery plugin to navigate images/any content in a carousel style widget.
 * @requires jQuery v1.2 or above
 *
 * http://gmarwaha.com/jquery/jcarousellite/
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.0.1
 * Note: Requires jquery 1.2 or above from version 1.0.1
 */

/**
 * Creates a carousel-style navigation widget for images/any-content from a simple HTML markup.
 *
 * The HTML markup that is used to build the carousel can be as simple as...
 *
 *  <div class="carousel">
 *      <ul>
 *          <li><img src="image/1.jpg" alt="1"></li>
 *          <li><img src="image/2.jpg" alt="2"></li>
 *          <li><img src="image/3.jpg" alt="3"></li>
 *      </ul>
 *  </div>
 *
 * As you can see, this snippet is nothing but a simple div containing an unordered list of images.
 * You don't need any special "class" attribute, or a special "css" file for this plugin.
 * I am using a class attribute just for the sake of explanation here.
 *
 * To navigate the elements of the carousel, you need some kind of navigation buttons.
 * For example, you will need a "previous" button to go backward, and a "next" button to go forward.
 * This need not be part of the carousel "div" itself. It can be any element in your page.
 * Lets assume that the following elements in your document can be used as next, and prev buttons...
 *
 * <button class="prev">&lt;&lt;</button>
 * <button class="next">&gt;&gt;</button>
 *
 * Now, all you need to do is call the carousel component on the div element that represents it, and pass in the
 * navigation buttons as options.
 *
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev"
 * });
 *
 * That's it, you would have now converted your raw div, into a magnificient carousel.
 *
 * There are quite a few other options that you can use to customize it though.
 * Each will be explained with an example below.
 *
 * @param an options object - You can specify all the options shown below as an options object param.
 *
 * @option btnPrev, btnNext : string - no defaults
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev"
 * });
 * @desc Creates a basic carousel. Clicking "btnPrev" navigates backwards and "btnNext" navigates forward.
 *
 * @option btnGo - array - no defaults
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      btnGo: [".0", ".1", ".2"]
 * });
 * @desc If you don't want next and previous buttons for navigation, instead you prefer custom navigation based on
 * the item number within the carousel, you can use this option. Just supply an array of selectors for each element
 * in the carousel. The index of the array represents the index of the element. What i mean is, if the
 * first element in the array is ".0", it means that when the element represented by ".0" is clicked, the carousel
 * will slide to the first element and so on and so forth. This feature is very powerful. For example, i made a tabbed
 * interface out of it by making my navigation elements styled like tabs in css. As the carousel is capable of holding
 * any content, not just images, you can have a very simple tabbed navigation in minutes without using any other plugin.
 * The best part is that, the tab will "slide" based on the provided effect. :-)
 *
 * @option mouseWheel : boolean - default is false
 * @example
 * $(".carousel").jCarouselLite({
 *      mouseWheel: true
 * });
 * @desc The carousel can also be navigated using the mouse wheel interface of a scroll mouse instead of using buttons.
 * To get this feature working, you have to do 2 things. First, you have to include the mouse-wheel plugin from brandon.
 * Second, you will have to set the option "mouseWheel" to true. That's it, now you will be able to navigate your carousel
 * using the mouse wheel. Using buttons and mouseWheel or not mutually exclusive. You can still have buttons for navigation
 * as well. They complement each other. To use both together, just supply the options required for both as shown below.
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      mouseWheel: true
 * });
 *
 * @option auto : number - default is null, meaning autoscroll is disabled by default
 * @example
 * $(".carousel").jCarouselLite({
 *      auto: 800,
 *      speed: 500
 * });
 * @desc You can make your carousel auto-navigate itself by specfying a millisecond value in this option.
 * The value you specify is the amount of time between 2 slides. The default is null, and that disables auto scrolling.
 * Specify this value and magically your carousel will start auto scrolling.
 *
 * @option speed : number - 200 is default
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      speed: 800
 * });
 * @desc Specifying a speed will slow-down or speed-up the sliding speed of your carousel. Try it out with
 * different speeds like 800, 600, 1500 etc. Providing 0, will remove the slide effect.
 *
 * @option easing : string - no easing effects by default.
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      easing: "bounceout"
 * });
 * @desc You can specify any easing effect. Note: You need easing plugin for that. Once specified,
 * the carousel will slide based on the provided easing effect.
 *
 * @option vertical : boolean - default is false
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      vertical: true
 * });
 * @desc Determines the direction of the carousel. true, means the carousel will display vertically. The next and
 * prev buttons will slide the items vertically as well. The default is false, which means that the carousel will
 * display horizontally. The next and prev items will slide the items from left-right in this case.
 *
 * @option circular : boolean - default is true
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      circular: false
 * });
 * @desc Setting it to true enables circular navigation. This means, if you click "next" after you reach the last
 * element, you will automatically slide to the first element and vice versa. If you set circular to false, then
 * if you click on the "next" button after you reach the last element, you will stay in the last element itself
 * and similarly for "previous" button and first element.
 *
 * @option visible : number - default is 3
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      visible: 4
 * });
 * @desc This specifies the number of items visible at all times within the carousel. The default is 3.
 * You are even free to experiment with real numbers. Eg: "3.5" will have 3 items fully visible and the
 * last item half visible. This gives you the effect of showing the user that there are more images to the right.
 *
 * @option start : number - default is 0
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      start: 2
 * });
 * @desc You can specify from which item the carousel should start. Remember, the first item in the carousel
 * has a start of 0, and so on.
 *
 * @option scrool : number - default is 1
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      scroll: 2
 * });
 * @desc The number of items that should scroll/slide when you click the next/prev navigation buttons. By
 * default, only one item is scrolled, but you may set it to any number. Eg: setting it to "2" will scroll
 * 2 items when you click the next or previous buttons.
 *
 * @option beforeStart, afterEnd : function - callbacks
 * @example
 * $(".carousel").jCarouselLite({
 *      btnNext: ".next",
 *      btnPrev: ".prev",
 *      beforeStart: function(a) {
 *          alert("Before animation starts:" + a);
 *      },
 *      afterEnd: function(a) {
 *          alert("After animation ends:" + a);
 *      }
 * });
 * @desc If you wanted to do some logic in your page before the slide starts and after the slide ends, you can
 * register these 2 callbacks. The functions will be passed an argument that represents an array of elements that
 * are visible at the time of callback.
 *
 *
 * @cat Plugins/Image Gallery
 * @author Ganeshji Marwaha/ganeshread@gmail.com
 */

(function($) {                                          // Compliant with jquery.noConflict()
$.fn.jCarouselLite = function(o) {
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,

        speed: 200,
        easing: null,

        vertical: false,
        circular: true,
        visible: 3,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

        if(o.circular) {
            ul.prepend(tLi.slice(tl-v-1+1).clone())
              .append(tLi.slice(0,v).clone());
            o.start += v;
        }

        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

        if(o.btnPrev)
            $(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });

        if(o.btnNext)
            $(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });

        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    // >> rfigueiredo (patch especial que deve ser retirado e colocado no theme.js)
                    $('.node-type-pf-project .field > a').removeClass('curr');
                    $(val).addClass('curr');
                    // << rfigueiredo
                    return go(o.circular ? o.visible+i : i);
                });
            });

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto)
            setInterval(function() {
                go(curr+o.scroll);
            }, o.auto+o.speed);

        function vis() {
            return li.slice(curr).slice(0,v);
        };

        function go(to) {
            if(!running) {

                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
    });
};

function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery);;
jQuery(function($){
  var currPage = urlParam('page');
  var totalPages = $('.page-portfolio #block-system-main .item-list ul').find('li.pager-item').length + 1;
  var panel;
  var link;
  var toPage;
  var lastPage = currPage;
  var fromPage = false;

  // PORTFOLIO PAGE LOADING SCRIPT (TEMP LOCATION):
  addHandlers();
  
  function addHandlers(){
    $('.page-portfolio ul.pager li.pager-next a').bind('click', nextFunction);
    $('.page-portfolio ul.pager li.pager-previous a').bind('click', previousFunction);

    $('.page-portfolio ul.pager li.pager-item').each(function(index){
      $(this).find('a').bind('click', gotoPage)
    }); 
  }
  
  function removeHandlers(){
    $('.page-portfolio ul.pager li.pager-next a').unbind('click', nextFunction);
    $('.page-portfolio ul.pager li.pager-previous a').unbind('click', previousFunction);

    $('.page-portfolio ul.pager li.pager-item').each(function(index){
      $(this).find('a').unbind('click', gotoPage)
    });
    
    $('.page-portfolio ul.pager li.pager-next a').bind('click', function(){ return false; });
    $('.page-portfolio ul.pager li.pager-previous a').bind('click', function(){ return false; });

    $('.page-portfolio ul.pager li.pager-item').each(function(index){
      $(this).find('a').bind('click', function(){ return false; })
    });
  }

  function gotoPage(){
    toPage = ($(this).html() - 1); // For example, the second page's variable "page" has a value of "1"
    link = $(this).attr("href");
    fromPage = true;

    if (toPage < 0) toPage = 0;

    if (toPage > currPage){
      $('.page-portfolio ul.pager li.pager-next a').trigger('click');
    } else {
      $('.page-portfolio ul.pager li.pager-previous a').trigger('click');
    }
    
    return false;
  }

  function nextFunction(){
    removeHandlers();
  
    lastPage = currPage;

    if (fromPage == false){
      link = $(this).attr("href");
      currPage++;
    } else {
      currPage = toPage;
    }

    fromPage = false;
    panel = "slider" + currPage;

    if ( $('#' + panel).length == 0){
      $('.page-portfolio #block-system-main .portfolio-container').append('<div id="'+panel+'"><\/div>');
      $('#' + panel).html('<p><img src="http://www.loadinfo.net/images/preview/36_cycle_three_24.gif?1200916238" width="24" height="24" /><\/p>');
      $('#' + panel).load(link + ' #block-system-main .box');
    }
    $('#' + panel).css({'left': '930px', 'position':'absolute', 'width':'880px', 'height':'520px'});

    $('.page-portfolio #block-system-main .item-list').load(link + ' #block-system-main ul.pager', onCompleteRequest);
    animatePanelsRight(lastPage);

    return false;
  }

  function previousFunction(){
    removeHandlers();

    lastPage = currPage;

    if (fromPage == false){
      link = $(this).attr("href");
      currPage--;
    } else {      
      currPage = toPage;
    }

    panel = "slider" + currPage;    
    fromPage = false;

    if ( $('#' + panel).length == 0){
      $('.page-portfolio #block-system-main .portfolio-container').append('<div id="'+panel+'"><\/div>');
      $('#' + panel).html('<p><img src="http://www.loadinfo.net/images/preview/36_cycle_three_24.gif?1200916238" width="24" height="24" /><\/p>');
      $('#' + panel).load(link + ' #block-system-main .box');
    }

    $('#' + panel).css({'left': '-930px', 'position':'absolute', 'width':'880px', 'height':'520px'});

    $('.page-portfolio #block-system-main .item-list').load(link + ' #block-system-main ul.pager', onCompleteRequest);
    animatePanelsLeft(lastPage);

    return false;
  }

  function animatePanelsRight(id){
    var currentPanel = (id);

    $('#slider' + currentPanel).animate({"left": "-930px"}, {duration: 1000, queue: false });
    $('#' + panel).animate({"left": "0px"},{duration: 1000, queue: false});
  }

  function animatePanelsLeft(id){
    var currentPanel = (id);

    $('#slider' + currentPanel).animate({"left": "930px"}, {duration: 1000, queue: false });
    $('#' + panel).animate({"left": "0px"},{duration: 1000, queue: false});
  }

  function onCompleteRequest(response, status, xhr){
    if (status == "error") {
      var msg = "Sorry but there was an error: ";
      $("#error").html(msg + xhr.status + " " + xhr.statusText);
    }
    
    addHandlers();
  }

  function urlParam(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) { return 0; }
    return results[1] || 0;
  }
  
});;
/**
 * jQuery custom checkboxes
 * 
 * Copyright (c) 2008 Khavilo Dmitry (http://widowmaker.kiev.ua/checkbox/)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @version 1.3.0 Beta 1
 * @author Khavilo Dmitry
 * @mailto wm.morgun@gmail.com
**/

(function($){
	/* Little trick to remove event bubbling that causes events recursion */
	var CB = function(e)
	{
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	};
	
	$.fn.checkbox = function(options) {
		/* IE6 background flicker fix */
		try	{ document.execCommand('BackgroundImageCache', false, true);	} catch (e) {}
		
		/* Default settings */
		var settings = {
			cls: 'jquery-checkbox',  /* checkbox  */
			empty: Drupal.settings.openquest.themePath + '/a/empty.png'  /* checkbox  */
		};
		
		/* Processing settings */
		settings = $.extend(settings, options || {});
		
		/* Adds check/uncheck & disable/enable events */
		var addEvents = function(object)
		{
			var checked = object.checked;
			var disabled = object.disabled;
			var $object = $(object);
			
			if ( object.stateInterval )
				clearInterval(object.stateInterval);
			
			object.stateInterval = setInterval(
				function() 
				{
					if ( object.disabled != disabled )
						$object.trigger( (disabled = !!object.disabled) ? 'disable' : 'enable');
					if ( object.checked != checked )
						$object.trigger( (checked = !!object.checked) ? 'check' : 'uncheck');
				}, 
				10 /* in miliseconds. Low numbers this can decrease performance on slow computers, high will increase responce time */
			);
			return $object;
		};
		//try { console.log(this); } catch(e) {}
		
		/* Wrapping all passed elements */
		return this.each(function() 
		{
			var ch = this; /* Reference to DOM Element*/
			var $ch = addEvents(ch); /* Adds custom events and returns, jQuery enclosed object */
			
			/* Removing wrapper if already applied  */
			if (ch.wrapper) ch.wrapper.remove();
			
			/* Creating wrapper for checkbox and assigning "hover" event */
			ch.wrapper = $('<span class="' + settings.cls + '"><span class="mark"><img src="' + settings.empty + '" /></span></span>');
			ch.wrapperInner = ch.wrapper.children('span:eq(0)');
			ch.wrapper.hover(
				function(e) { ch.wrapperInner.addClass(settings.cls + '-hover');CB(e); },
				function(e) { ch.wrapperInner.removeClass(settings.cls + '-hover');CB(e); }
			);
			
			/* Wrapping checkbox */
			$ch.css({position: 'absolute', zIndex: -1, visibility: 'hidden'}).after(ch.wrapper);
			
			/* Ttying to find "our" label */
			var label = false;
			if ($ch.attr('id'))
			{
				label = $('label[for='+$ch.attr('id')+']');
				if (!label.length) label = false;
			}
			if (!label)
			{
				/* Trying to utilize "closest()" from jQuery 1.3+ */
				label = $ch.closest ? $ch.closest('label') : $ch.parents('label:eq(0)');
				if (!label.length) label = false;
			}
			/* Labe found, applying event hanlers */
			if (label)
			{
				label.hover(
					function(e) { ch.wrapper.trigger('mouseover', [e]); },
					function(e) { ch.wrapper.trigger('mouseout', [e]); }
				);
				label.click(function(e) { $ch.trigger('click',[e]); CB(e); return false;});
			}
			ch.wrapper.click(function(e) { $ch.trigger('click',[e]); CB(e); return false;});
			$ch.click(function(e) { CB(e); });
			$ch.bind('disable', function() { ch.wrapperInner.addClass(settings.cls+'-disabled');}).bind('enable', function() { ch.wrapperInner.removeClass(settings.cls+'-disabled');});
			$ch.bind('check', function() { ch.wrapper.addClass(settings.cls+'-checked' );}).bind('uncheck', function() { ch.wrapper.removeClass(settings.cls+'-checked' );});
			
			/* Disable image drag-n-drop for IE */
			$('img', ch.wrapper).bind('dragstart', function () {return false;}).bind('mousedown', function () {return false;});
			
			/* Firefox antiselection hack */
			if ( window.getSelection )
				ch.wrapper.css('MozUserSelect', 'none');
			
			/* Applying checkbox state */
			if ( ch.checked )
				ch.wrapper.addClass(settings.cls + '-checked');
			if ( ch.disabled )
				ch.wrapperInner.addClass(settings.cls + '-disabled');			
		});
	}
})(jQuery);
;
 /*
 * TipTip
 * Copyright 2010 Drew Wilson
 * www.drewwilson.com
 * code.drewwilson.com/entry/tiptip-jquery-plugin
 *
 * Version 1.3   -   Updated: Mar. 23, 2010
 *
 * This Plug-In will create a custom tooltip to replace the default
 * browser tooltip. It is extremely lightweight and very smart in
 * that it detects the edges of the browser window and will make sure
 * the tooltip stays within the current window size. As a result the
 * tooltip will adjust itself to be displayed above, below, to the left 
 * or to the right depending on what is necessary to stay within the
 * browser window. It is completely customizable as well via CSS.
 *
 * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($){
	$.fn.tipTip = function(options) {
		var defaults = { 
			activation: "hover",
			keepAlive: false,
			maxWidth: "200px",
			edgeOffset: 3,
			defaultPosition: "bottom",
			delay: 400,
			fadeIn: 200,
			fadeOut: 200,
			attribute: "title",
			content: false, // HTML or String to fill TipTIp with
		  	enter: function(){},
		  	exit: function(){}
	  	};
	 	var opts = $.extend(defaults, options);
	 	
	 	// Setup tip tip elements and render them to the DOM
	 	if($("#tiptip_holder").length <= 0){
	 		var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>');
			var tiptip_content = $('<div id="tiptip_content"></div>');
			var tiptip_arrow = $('<div id="tiptip_arrow"></div>');
			$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')));
		} else {
			var tiptip_holder = $("#tiptip_holder");
			var tiptip_content = $("#tiptip_content");
			var tiptip_arrow = $("#tiptip_arrow");
		}
		
		return this.each(function(){
			var org_elem = $(this);
			if(opts.content){
				var org_title = opts.content;
			} else {
				var org_title = org_elem.attr(opts.attribute);
			}
			if(org_title != ""){
				if(!opts.content){
					org_elem.removeAttr(opts.attribute); //remove original Attribute
				}
				var timeout = false;
				
				if(opts.activation == "hover"){
					org_elem.hover(function(){
						active_tiptip();
					}, function(){
						if(!opts.keepAlive){
							deactive_tiptip();
						}
					});
					if(opts.keepAlive){
						tiptip_holder.hover(function(){}, function(){
							deactive_tiptip();
						});
					}
				} else if(opts.activation == "focus"){
					org_elem.focus(function(){
						active_tiptip();
					}).blur(function(){
						deactive_tiptip();
					});
				} else if(opts.activation == "click"){
					org_elem.click(function(){
						active_tiptip();
						return false;
					}).hover(function(){},function(){
						if(!opts.keepAlive){
							deactive_tiptip();
						}
					});
					if(opts.keepAlive){
						tiptip_holder.hover(function(){}, function(){
							deactive_tiptip();
						});
					}
				}
			
				function active_tiptip(){
					opts.enter.call(this);
					tiptip_content.html(org_title);
					tiptip_holder.hide().removeAttr("class").css("margin","0");
					tiptip_arrow.removeAttr("style");
					
					var top = parseInt(org_elem.offset()['top']);
					var left = parseInt(org_elem.offset()['left']);
					var org_width = parseInt(org_elem.outerWidth());
					var org_height = parseInt(org_elem.outerHeight());
					var tip_w = tiptip_holder.outerWidth();
					var tip_h = tiptip_holder.outerHeight();
					var w_compare = Math.round((org_width - tip_w) / 2);
					var h_compare = Math.round((org_height - tip_h) / 2);
					var marg_left = Math.round(left + w_compare);
					var marg_top = Math.round(top + org_height + opts.edgeOffset);
					var t_class = "";
					var arrow_top = "";
					var arrow_left = Math.round(tip_w - 12) / 2;

                    if(opts.defaultPosition == "bottom"){
                    	t_class = "_bottom";
                   	} else if(opts.defaultPosition == "top"){ 
                   		t_class = "_top";
                   	} else if(opts.defaultPosition == "left"){
                   		t_class = "_left";
                   	} else if(opts.defaultPosition == "right"){
                   		t_class = "_right";
                   	}
					
					var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
					var left_compare = (tip_w + left) > parseInt($(window).width());
					
					if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){
						t_class = "_right";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left = -12;
						marg_left = Math.round(left + org_width + opts.edgeOffset);
						marg_top = Math.round(top + h_compare);
					} else if((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)){
						t_class = "_left";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left =  Math.round(tip_w);
						marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5));
						marg_top = Math.round(top + h_compare);
					}

					var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
					var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;
					
					if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){
						if(t_class == "_top" || t_class == "_bottom"){
							t_class = "_top";
						} else {
							t_class = t_class+"_top";
						}
						arrow_top = tip_h;
						marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset));
					} else if(bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)){
						if(t_class == "_top" || t_class == "_bottom"){
							t_class = "_bottom";
						} else {
							t_class = t_class+"_bottom";
						}
						arrow_top = -12;						
						marg_top = Math.round(top + org_height + opts.edgeOffset);
					}
				
					if(t_class == "_right_top" || t_class == "_left_top"){
						marg_top = marg_top + 5;
					} else if(t_class == "_right_bottom" || t_class == "_left_bottom"){		
						marg_top = marg_top - 5;
					}
					if(t_class == "_left_top" || t_class == "_left_bottom"){	
						marg_left = marg_left + 5;
					}
					tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"});
					tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class);
					
					if (timeout){ clearTimeout(timeout); }
					timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay);	
				}
				
				function deactive_tiptip(){
					opts.exit.call(this);
					if (timeout){ clearTimeout(timeout); }
					tiptip_holder.fadeOut(opts.fadeOut);
				}
			}				
		});
	}
})(jQuery);  	;
// $Id:
(function ($) {

Drupal.behaviors.themeinit = {
  attach: function (context, settings) {


    // HOMEPAGE'S SLIDESHOW:
    if($.browser.msie) {  // because IE is a terrible, terrible browser...
      var time1 = 0;
      var time2 = 0;
    }else{
      var time1 = 800;
      var time2 = 1800;
    }

    var site;
    var ti;
    var autoPlay = true;
    var currentLink = 0;
    var countLinks = $(".icons a").length;
    var xtime = setInterval(timeover, 8000);
    timeover();

    function timeover(nextLink){
      if (autoPlay){
       currentLink++; 
        if (currentLink > countLinks){
          currentLink = 1;
        }
      } else {
        currentLink = $(nextLink).attr('rel');      
      }

      $('.icons a').each (function(index, el){
        nextLink = el;

        if (index == (currentLink - 1)){
          $('.slideshow .slider:nth-child('+ currentLink +')').addClass('current').fadeIn(time2);
          site = $(".slideshow div.current a").attr("href");
          $(".icons + a").attr("href", site);
          $(nextLink).addClass('current');
        } else {          
          ti = (index + 1);
          $('.slideshow .slider:nth-child('+ ti +')').removeClass('current').fadeOut(time1);
          $(nextLink).removeClass('current'); 
        }
      });
    }

    $('.icons a').click(function() {      
      if(!$(this).hasClass('current')) {
        autoPlay = false;
        clearInterval(xtime);
        timeover($(this));
      }
      return false;
    });

    
    // WEBMAIL HOVER ANIMATION:
    $('#webmail a').hover(
      function () {
        $(this).stop().animate({ width: 52 },200);
      }, 
      function () {
        $(this).stop().animate({ width: 42 },300);
      }
    );


    // PORTFOLIO'S SLIDESHOW
    var n = 1;
    $('.node-type-pf-project .field-items img').each(function(index) {
      var title = $(this).attr('alt');
      $('#middle .field').append('<a href="#" class="' + n + '">'+ title +'<\/a>');
      n = n + 1;
    });
    $('.node-type-pf-project .field .field-box + a').addClass('curr');
    $(".node-type-pf-project #middle .field-items").jCarouselLite({
      btnGo: [".1", ".2", ".3", ".4", ".5", ".6"],
      visible: 2.64
    });


    //NEWSLETTER'S DEFAULT MESSAGE - SHOW/HIDE
    var def;
    if (def == undefined) def = 'inserir email';
    $("#footer #edit-email").val(def);
    $("#footer #edit-email").focusin(function() {
      var check = $("#footer #edit-email").val();
      if ( check == def ) {
        $("#footer #edit-email").val("");
      }
    });
    $("#footer #edit-email").focusout(function() {
      var check = $("#footer #edit-email").val();
      if ( check == "" ) {
        $("#footer #edit-email").val(def);
      }
    });


    // CLIENTS PAGE ACCORDION
    $(".customer-list").hide();
    //$('.line:first .customer-list').show();
    $('a.title').click(
      function() {
        var checkElement = $(this).parent().parent().find('.customer-list');
        if((checkElement.is('.customer-list')) && (checkElement.is(':visible'))) {
          $('.customer-list:visible').slideUp('normal');
          return false;
        }
        if((checkElement.is('.customer-list')) && (!checkElement.is(':visible'))) {
          $('.customer-list:visible').slideUp('normal');
          checkElement.slideDown('normal');
          return false;
        }
      }
    );


    // SELECT BOX STYLING PLUGIN (FOR THE FILTER MENU)
    $.fn.extend({     
      customStyle : function(options) {
        if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
        return this.each(function() {        
          var currentSelected = $(this).find(':selected');
          $(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
          var selectBoxSpan = $(this).next();
          var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
          var selectBoxSpanInner = selectBoxSpan.find(':first-child');
          selectBoxSpan.css({display:'inline-block'});
          selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
          var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
          $(this).height(selectBoxHeight).change(function(){
          selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
          });          
        });
        }
      }
    });
    $('#header .block-portfolio select').customStyle();


    // FILTER BLOCK REDIRECT FUNCTION
    $('#header .block-portfolio select').change(function() {
      var location = $('#header .block-portfolio #edit-location').val();
      var category = $('#header .block-portfolio #edit-category').val();
      var year = $('#header .block-portfolio #edit-year').val();
      if (location != "" || category != "" || year != "") {
        window.location = '?location=' + location + '&category=' + category + '&year=' + year + '';
      }else if(location == "" && category == "" && year == ""){
        window.location = 'portfolio';
      }
    });


    // SHOW CAPTCHA AFTER CLICKING ON THE CONTACT FORM
    if ( $('.page-contact fieldset.captcha').length > 0 ){
      $('.page-contact #edit-submit').bind('click', function() {
        if ( $('.page-contact fieldset.captcha').children("input").attr("id") != "submit-captcha" ){
          $('.page-contact fieldset.captcha').append('<input type="submit" value="' + send + '" name="op" id="submit-captcha">');
        }      
        $('<div />').addClass('lightbox-bg').appendTo('body').show(); // Make the overlay
        $('.page-contact fieldset.captcha').append("<a href='#' class='close'>close</a>");
        $(".close").bind('click', closeCaptcha);
        $('.lightbox-bg').bind('click', closeCaptcha);
        $('.page-contact fieldset.captcha').fadeIn(600);
        return false;
      });
    }
    function closeCaptcha(){
      $('.page-contact fieldset.captcha').fadeOut(300, function(){
        $('.lightbox-bg').remove();
        $('.close').remove();        
      });return false;
    }


    // SHOW CAPTCHA AFTER CLICKING ON THE CAREER FORM
    $("#webform-component-career").parent().addClass('jquery-career')
    if ( $('.jquery-career fieldset.captcha').length > 0 ){
      $('.jquery-career #edit-submit').bind('click', function() {
        if ( $('.jquery-career fieldset.captcha').children("input").attr("id") != "submit-captcha" ){
          $('.jquery-career fieldset.captcha').append('<input type="submit" value="' + send + '" name="op" id="submit-captcha">');
        }      
        $('<div />').addClass('lightbox-bg').appendTo('body').show(); // Make the overlay
        $('.jquery-career fieldset.captcha').append("<a href='#' class='close'>close</a>");
        $(".close").bind('click', closeCareerCaptcha);
        $('.lightbox-bg').bind('click', closeCareerCaptcha);
        $('.jquery-career fieldset.captcha').fadeIn(600);
        return false;
      });
    }
    function closeCareerCaptcha(){
      $('.jquery-career fieldset.captcha').fadeOut(300, function(){
        $('.lightbox-bg').remove();
        $('.close').remove();        
      });return false;
    }


    // CALL THE TOOLTIP PLUGIN "TIP TIP":
    $("#icons a").tipTip({delay: 100});


    // REPLACE THE NODE URL WITH THE DIRECT PDF LINK:
    $('.page-newsletters .field-name-field-thumb a').each(function(index) {
      var url = $(this).parents('.views-row').find('.field-name-field-pdf a').attr('href');
      $(this).attr('href', url);
    });
    
    // ANIMATE THE NEWSLETTER HOVER:
    $('.page-newsletters .views-row').hover(
      function () {
        $(this).find('.views-field-entity-id:hidden').slideDown(350);
      },
      function () {
        $(this).find('.views-field-entity-id:visible').slideUp(350);
      }
    );
    
    
    // CHECKBOX STYLING:
    $('.webform-client-form .webform-component-radios .form-radio').checkbox();
    
    
    // Questionary | Why us    
    var forms_list = ['webform-component-questionary--field-1', 'webform-component-questionary--field-1-1', 'webform-component-questionary--field-2',
                      'webform-component-questionary--field-a-3', 'webform-component-questionary--field-a-3-1', 'webform-component-questionary--field-a-4',
                      'webform-component-questionary--field-b-3', 'webform-component-questionary--field-b-3-1', 'webform-component-questionary--field-b-4',
                      'webform-component-questionary--form'];
    var forms_answer = [];
    var current_form = $(forms_list[0]);
    var form_index = 0;
    
    $(".webform-client-form #webform-component-questionary").parent().addClass('jquery-questionary').append("<a href='#' class='next-button'>seguinte</a>");
    $(".webform-client-form #webform-component-questionary > div").append("<span class='left-grad'></div><span class='right-grad'></div>");
    $(".webform-client-form .jquery-questionary .next-button").bind ('click', checkform);

    // Verify if have an error and redirect to Contact Form
    if ( $("#middle .error").length > 0){
      $(".webform-client-form > div").css("min-height","375px");
      $("#webform-component-questionary .next-button").css("display", "none");
      $("#webform-component-field-1").css("display","none");
      $("#webform-component-form").css({"left":"25px"});
      $("#number span").css("top","-624px");
      $("#complete").css("width","811px");
      $("#marker").css("background-position","-288px 0");
      $("#edit-actions").css({"left":"25px", "display":"block"});
      $(".webform-client-form .next-button").css("display","none");
      
      $("#webform-component-questionary .fieldset-wrapper fieldset").each ( function (index, ele){
        if ( $(ele).attr('id') == "webform-component-questionary--form" ) {
          $(ele).css("left", "25px");
        } else {
          $(ele).css("left", "-550px");
        }
      });
      return false;
    }

    function checkform(){
      forms_answer[form_index] = get_answers();
      var val = forms_answer[form_index];
      var old = 0;
      var final_pos = 52;
      var question = 0;
      
      switch (form_index) { 
        // Answer to Question 1
        case 0:
          old = form_index;
          if (val == undefined){ // Sem resposta            
            form_index = old;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            question = 0;
            return false;
          }
          if (val == 1){ // Não
            form_index += 2;
            final_pos = 241;
            question = 2;
          }
          if (val == 2){  // Sim
            form_index++;
            final_pos = 143;
            question = 1;
          }      

          break;
        
        // Answer to Question 1.1
        case 1:
          old = form_index;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 1;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          if (val == 1){ // Solução Simples
            form_index = (forms_list.length - 1);
            question = 6;
            final_pos = 811;
          }
          if (val == 2){ // Solução Sucesso
            form_index++;
            question = 2;
            final_pos = 241
          }
          break;

        // Answer to Question 2
        case 2:
          old = form_index;
          final_pos = 430;
          question = 3;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 2;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          if (val == 1) form_index = 3; // WEB 
          if (val == 2) form_index = 6; // APPLICATION          
          break;
          
        // Answer to Question 3 | WEB - A
        case 3:
          old = form_index;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 3;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          if (val == 1){ // Sim
            final_pos = 621;
            form_index+=2;
            question = 5;
          }
          if (val == 2){ // Não
            form_index++;
            final_pos = 525;
            question = 4;
          }          
          break;
          
        // Answer to Question 3.1 | WEB - A
        case 4:
          old = form_index;
          question = 5;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 4;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          if (val == 1){ // Sim
            question = 6;
            form_index = (forms_list.length - 1);
            final_pos = 811;
          }
          if (val == 2){ // Não
            form_index++;
            final_pos = 621
            question = 5;
          }
          break;

        // Answer to Question 4 | WEB - A | Go to form
        case 5:
          old = form_index;
          question = 6;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 5;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          form_index = (forms_list.length - 1);
          final_pos = 811;
          break;
        
        
        // Answer to Question 3 | APP - B
        case 6:
          old = form_index;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 3;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          if (val == 1){ // Sim
            final_pos = 621;
            form_index+=2;
            question = 5;
          }
          if (val == 2){ // Não
            form_index++;
            final_pos = 525;
            question = 4;
          }
          break;

        // Answer to Question 3.1 | APP - B
        case 7:
          old = form_index;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 4;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          if (val == 1){ // Sim
            form_index++;
            final_pos = 621
            question = 5;
          }
          if (val == 2){ // Não
            form_index = (forms_list.length - 1);
            final_pos = 811;
            question = 6;
          }
          break;

        // Answer to Question 4 | APP - B | Go to form
        case 8:
          old = form_index;
          question = 6;
          if (val == undefined){ // Sem resposta
            form_index = old;
            question = 5;
            $("#"+ forms_list[form_index] +" .form-radios").css('color', 'red');
            return false;
          }
          form_index = (forms_list.length - 1);
          final_pos = 811;
          break;
      }

      change_form (forms_list[old], forms_list[form_index], final_pos, question);
      //$("#"+ forms_list[form_index] +" .form-radios").css('color', 'black');
      return false;
    }
        
    function get_answers(){
      var result = 0;
      var current = $("#"+forms_list[form_index]).html();
      result = $(current).find('.jquery-checkbox-checked').parent().find('input').attr('value');

      return result; 
    }
        
    function change_form(old_form, new_form, progress, question){
      var image_pos = -(question * 104);
      var slide_pos = -(question * 550);

      $("#"+old_form).animate({
        "left":slide_pos
      }, 400);

      if (question == 6) $("#edit-actions").css('left', '25px')
      $("#"+new_form).animate({
        "left":25
      }, 400, function(){
        if (question == 6){
          $(".next-button").css("display", "none");
          $("#edit-actions").slideDown('slow');
          $("#webform-component-questionary > div").animate({
            "min-height":375
          }, 200);          
        }
      });

      $("#number span").animate({
        top: image_pos +"px"
      }, 400);

      $("#complete").animate({
        width: progress
      }, 800,
      function(){
        $(this).removeClass().addClass('s'+((form_index +1)));
      });

      $("#"+ new_form +" .form-radios input").bind('click', onInputChange);
      $("#"+ new_form +" .form-radios").css('color', 'black');
    }
    
    $("#"+ forms_list[form_index] +" .form-radios input").bind('click', onInputChange);
    function onInputChange(){
      $("#"+ forms_list[form_index] +" .form-radios").css('color', 'black');
    }


    // MAKE THE EXTRA "OTHER" FIELD APPEAR IN THE CAREER FORM:
    $('#webform-component-career').addClass('jquery');
    activeOthers ( $('#webform-component-career .form-item-submitted-career-job-4 input').attr('checked') );
    $('#webform-component-career .form-item-submitted-career-job-4 input').click(function(){
      activeOthers( $(this).attr('checked') );
    });    
    function activeOthers(value){
      if ( value){ 
        $("#webform-component-career.jquery #webform-component-career--other input").show();
      } else {
        $("#webform-component-career.jquery #webform-component-career--other input").hide();
      }
    }


  }
};

})(jQuery);;

