$(document).ready(function() {
    if ($.browser.msie && ($.browser.version < 7)) { $("body").addClass("ie"); DD_belatedPNG.fix(".fix, li.fadeOut, li.fadeIn"); }
    //$("body").prepend('<span class="mouseposition" style="position: absolute; top: 0px; left: 0px; background: #FFF; color: #000;">asdasdasd</span>');
    
    $("section#wrapper").prepend('<div id="overlay"></div>')/*.draggable({ cursor: "move" })*/;
    
    /*if (navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad)/)) {
	$("#fancybox-overlay").css("position","absolute");
    }*/

    $("ul.listRelevante li span").each(function(){
	$val = $(this).text().split("%")[0];
	$size = (370 / 100) * $val;
	$(this).animate({ width: $size }, 7000);
    });

    $("ul.listPremios li span").each(function(){
	$val = $(this).text().split("%")[0];
	$size = 93 + (35 * $val);
	$(this).animate({ height: $size }, 3000);
    });

    $("ul.title li a").each(function(){
	$(this).attr("title", $(this).text());
    });

    $("span.engrenagem").each(function(){
	$orientation = ($(this).attr("rel")) ? $(this).attr("rel") : 1;
	$.rotateElement($(this),0,$orientation);
    });

    $(".ilustraBomba, .ilustraBombaEn").hover(function() {
	$(this).addClass("hover");
    }, function() {
	$(this).removeClass("hover");
    });

    $("a.fancybox").click(function(){
	$.fancybox({ 'href': $(this).attr("href"), 'centerOnScroll': true, 'titleShow' : false, 'transitionIn' : 'elastic', 'transitionOut' : 'elastic', 'easingIn' : 'easeOutBack', 'easingOut' : 'easeInBack', 'padding': 0, 'showCloseButton': false, 'overlayOpacity': 0.8, 'overlayColor': '#090216' });
	$path = $(this).attr("rel");
	_gaq.push(['_trackPageview', $path]);
	return false;
    });

    $("a.btnSocialMedia, a.btnMobile").click(function(){
	$val = ($(this).hasClass("btnSocialMedia")) ? 2 : 3;
	$("section#boxFormPalestra input[type='hidden']").val($val);
    });

    $("ul.listWorks li .item a").click(function(){
	$id = $(this).attr("href").split("#")[1];
	$desc = $(this).parents(".item").find("p.desc").text();
	$title = $(this).parents(".item").find("h2").text();
	$path = $(this).attr("rel");
	$.ajax({
	    type : "POST",
	    cache : false,
	    url : "../inc/cases.php",
	    data : "id=" + $id + "&title=" + $title + "&desc=" + encodeURIComponent($desc),  
	    success: function(data) {
		if($(data).find("li").size() > 0){
		    $.fancybox(data, { 'centerOnScroll': true, 'titleShow' : false, 'transitionIn' : 'elastic', 'transitionOut' : 'elastic', 'easingIn' : 'easeOutBack', 'easingOut' : 'easeInBack', 'padding': 0, 'showCloseButton': false, 'overlayOpacity': 0.8, 'overlayColor': '#090216' });
		    _gaq.push(['_trackPageview', $path]);
		    $("#boxCases").casesAction();
		}
	    }
	});
	return false;
    });

    $(".carouselWorks").jcarousel({ scroll: 1, wrap: 'circular' });

    $("ul.listWorks li .item:even").addClass("even");

    //$("ul.listWorks li .item").prepend('<span class="bomba"></span>');

    $(".tb a.btnFechar").live("click", function(){
	$.fancybox.close();
	$(this).parent().find(".form").val("").removeClass("error").end().find(".msgSuccess").fadeOut(function(){
	    $(this).parent().find("fieldset").show().end().parent().find(".msgError").hide();
	})
	return false;
    });
    
    $("form.formContato").each(function(){
	$(this).validate({ errorContainer: $(this).find(".msgError"), errorLabelContainer: $(this).find(".msgLabelError"),
	    submitHandler: function() {
		$.ajax({
		    type: 'POST',
		    data: $("form.formContato").serialize(),
		    dataType: "json",
		    url: '../inc/proccessForm.php?callback=?',
		    success: function(json) {
			if(json.msg == 'ok'){
			    $("form.formContato").find("fieldset").hide().end().find(".msgSuccess").fadeIn();
			}else{
			    //error
			}
		    }
		});
	    }
	});
    });

    $("form.formPalestra").each(function(){
	$(this).validate({ errorContainer: $(this).find(".msgError"), errorLabelContainer: $(this).find(".msgLabelError"),
	    submitHandler: function() {
		$type = ($("section#boxFormPalestra input[type='hidden']").val() == 2) ? 'social-media': 'mobile';
		$.ajax({
		    type: 'POST',
		    data: $("form.formPalestra").serialize(),
		    dataType: "json",
		    url: '../inc/proccessForm.php?callback=?',
		    success: function(json) {
			if(json.msg == 'ok'){
			    $("form.formPalestra").find("fieldset").hide().end().find(".msgSuccess").fadeIn().end().find("input,select,textarea").removeClass("error");
			    _gaq.push(['_trackPageview', '/agendar-palestra/' + $type + '/sucesso']);
			}else{
			    _gaq.push(['_trackPageview', '/agendar-palestra/' + $type + '/erro']);
			}
		    }
		});
	    }
	});
    });

    $("form.formTrabalhar").each(function(){
	$(this).validate({ errorContainer: $(this).find(".msgError"), errorLabelContainer: $(this).find(".msgLabelError"),
	    submitHandler: function() {
		$.ajax({
		    type: 'POST',
		    data: $("form.formTrabalhar").serialize(),
		    dataType: "json",
		    url: '../inc/proccessForm.php?callback=?',
		    success: function(json) {
			if(json.msg == 'ok'){
			    $("form.formTrabalhar").find("fieldset").hide().end().find(".msgSuccess").fadeIn().end().find("input,select,textarea").removeClass("error");
			    _gaq.push(['_trackPageview', '/tabalhe-na-lov/sucesso']);
			}else{
			    _gaq.push(['_trackPageview', '/tabalhe-na-lov/erro']);
			}
		    }
		});
	    }
	});
    });

    $("#portifolioFile").uploadify({
		width : 142, height : 26, wmode : 'window', bgcolor: '#333333', buttonImg: '../img/btn-encontrarArquivo.gif',
		fileExt		: '*.pdf;*.doc;*.docx',
		fileDesc	: 'Formatos (*.pdf, *.doc, *.docx)',
		uploader	: '../swf/uploadify.swf',
		script		: '../inc/uploadify.php',
		folder		: 'upload',
		cancelImg	: '../img/cancel.png',
		queueID		: 'fileQueue',
		auto		: true,
		multi		: false,
		onComplete:	function(event, queueID, fileObj, response, data) {
			$("input[name='portifolioLink']").focus().val(fileObj.name).attr("title", fileObj.name).inputHintOverlay(2, 2);
		}
    });
    $("#portifolioFileEn").uploadify({
		width : 142, height : 26, wmode : 'window', bgcolor: '#333333', buttonImg: '../img/btn-encontrarArquivoEn.gif',
		fileExt		: '*.pdf;*.doc;*.docx',
		fileDesc	: 'Formatos (*.pdf, *.doc, *.docx)',
		uploader	: '../swf/uploadify.swf',
		script		: '../inc/uploadify.php',
		folder		: 'upload',
		cancelImg	: '../img/cancel.png',
		queueID		: 'fileQueue',
		auto		: true,
		multi		: false,
		onComplete:	function(event, queueID, fileObj, response, data) {
			$("input[name='portifolioLink']").focus().val(fileObj.name).attr("title", fileObj.name).inputHintOverlay(2, 2);
		}
    });

    $("#curriculoFile").uploadify({
		width : 142, height : 26, wmode : 'window', bgcolor: '#333333', buttonImg: '../img/btn-encontrarArquivo.gif',
		fileExt		: '*.pdf;*.doc;*.docx',
		fileDesc	: 'Formatos (*.pdf, *.doc, *.docx)',
		uploader	: '../swf/uploadify.swf',
		script		: '../inc/uploadify.php',
		folder		: 'upload',
		cancelImg	: '../img/cancel.png',
		queueID		: 'fileQueue',
		auto		: true,
		multi		: false,
		onComplete:	function(event, queueID, fileObj, response, data) {
			$("input[name='curriculoLink']").focus().val(fileObj.name).attr("title", fileObj.name).inputHintOverlay(2, 2);
		}
    });

    $("#curriculoFileEn").uploadify({
		width : 142, height : 26, wmode : 'window', bgcolor: '#333333', buttonImg: '../img/btn-encontrarArquivoEn.gif',
		fileExt		: '*.pdf;*.doc;*.docx',
		fileDesc	: 'Formatos (*.pdf, *.doc, *.docx)',
		uploader	: '../swf/uploadify.swf',
		script		: '../inc/uploadify.php',
		folder		: 'upload',
		cancelImg	: '../img/cancel.png',
		queueID		: 'fileQueue',
		auto		: true,
		multi		: false,
		onComplete:	function(event, queueID, fileObj, response, data) {
			$("input[name='curriculoLink']").focus().val(fileObj.name).attr("title", fileObj.name).inputHintOverlay(2, 2);
		}
    });

    $("a.btnVejaCases, a.btnVejaCasesEn").click(function() {
	    var target = ($.browser.opera) ? 'html' : 'html,body';
	    if($("#wrapper").css("left") != 0){
	    $("#wrapper").css({ "top": "0px", "left": "0px"});
	}
	$(target).animate({scrollTop: $(".boxOurWork").offset().top, scrollLeft: $(".boxOurWork").offset().left}, 1500);
	$path = $(this).attr("rel");
	_gaq.push(['_trackPageview', $path]);
	return false;
    });

    $("ul.listConhecimentos").each(function(){
	$(this).append('<li class="fadeOut"></li><li class="fadeIn"></li>');
	$.rotateBg($(this),0);
    });

    $("a[rel]").live("click", function(){
	$path = $(this).attr("rel");
	_gaq.push(['_trackPageview', $path]);
    }); 
    
    $("a.btnDelicious").each(function(){
	$title = $("title").text();
	$url = document.location.href;
	$(this).attr("href", "http://api.addthis.com/oexchange/0.8/forward/delicious/offer?title="+ $title +"LOV&url=" + $url);
    });
    
    $(".number").keypress(function(e){ 
	if(e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)){
	    return false;
	}
    });
    
    $(".tb").inputHintOverlay(2, 2);
    
    $("section#wrapper").easydrag(false);
});

(function($) {
    
    $.extend({
	rotateElement: function(element,degree,c){
	    degree = (c == 0) ? --degree : ++degree;
	    element.css({ WebkitTransform: 'rotate(' + degree + 'deg)', '-moz-transform': 'rotate(' + degree + 'deg)'});
	    setTimeout(function() { $.rotateElement(element,degree,c); }, 33);
	},
	rotateBg: function(element,pixels){
	    pixels--;
	    element.css({ 'background-position': '0px ' + pixels + 'px' });
	    setTimeout(function() { $.rotateBg(element,pixels); }, 100);
	}
    });

    jQuery.fn.casesAction = function() {
	return this.each(function() {
	    $(".carouselCases").jcarousel({ scroll: 1, wrap: 'circular' });
	    
	    $(".video").each(function() {
		$id = "video" + Math.floor(Math.random() * 1000);
		$(this).attr("id", $id);
		$urlVideo = $(this).find("a").attr("href");
		swfobject.embedSWF('../swf/player.swf', $id, $(this).css("width"), $(this).css("height"), "10.0.0", "swf/expressInstall.swf", { urlVideo: $urlVideo }, {quality: "autohigh", bgcolor: "#000000", allowscriptaccess: "sameDomain", allowfullscreen: true, wmode: "transparent"}, {id: $id, name: $id });
//"tocando" = "true" | "false"
	    });
	    
	});
    };

    /*
     * jQuery Input Hint Overlay plugin v1.1.10, 2010-09-21
     * Only tested with jQuery 1.4.1 (early versions - YMMV)
     * 
     *   http://jdeerhake.com/inputHintOverlay.php
     *   http://plugins.jquery.com/project/inputHintOverlay
     *   http://github.com/jdeerhake/inputHintOverlay
     */
    
    jQuery.fn.inputHintOverlay = function (topNudge, leftNudge) {
	topNudge = typeof(topNudge) != 'undefined' ? topNudge : 0;
	leftNudge = typeof(leftNudge) != 'undefined' ? leftNudge : 0;
	var suffix = 'jqiho';
	return this.each(function (){
	    var curParent = jQuery(this);
	    var textAreas = jQuery(this).find("textarea");
	    var pass = jQuery(this).find("input[type=password]")
	    jQuery(this).find("input[type=text]").add(textAreas).add(pass).each(function() {
		var relHint = jQuery(this).attr('title');
		var curValue = jQuery(this).attr('value');
		var inp = jQuery(this);
		var safeHint;
		if(relHint) {
		    safeHint = relHint.replace(/[^a-zA-Z0-9]/g, '');
		    jQuery(this).wrap("<div style='position:relative' id='wrap" + safeHint + suffix + "' />");
		    var wrap = jQuery(this).parent();
		    var newPos = jQuery(this).position();
		    newZ = jQuery(this).css('z-index');
		    if(newZ == "auto") newZ = "2000";
		    else newZ = newZ + 20;
		    var newCSS = {
			'position' : 'absolute',
			'z-index' : newZ,
			'left' : newPos['left'] + leftNudge,
			'top': newPos['top'] + topNudge,
			'cursor' : 'text'
		    };
		    var newDiv = jQuery(document.createElement('label'))
			    .appendTo(wrap)
			    .attr('for', jQuery(this).attr('id'))
			    .attr('id', safeHint + suffix)
			    .addClass('inputHintOverlay')
			    .html(relHint)
			    .css(newCSS)
			    .click(function() {
				jQuery(this).toggle(false);
				inp.trigger("focus");
			    });
		}
		if(curValue) {
		    newDiv.toggle(false);
		}
		jQuery(this).focus(function() {
		    newDiv.toggle(false);
		});
		jQuery(this).blur(function() {
		    if (jQuery(this).attr('value') == "") { newDiv.toggle(true); }
		});
	    });
	});
    };
})(jQuery);

/*! Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 * 
 * Requires: 1.2.2+
 */
(function(b){function d(a){var f=[].slice.call(arguments,1),e=0;a=b.event.fix(a||window.event);a.type="mousewheel";if(a.wheelDelta)e=a.wheelDelta/120;if(a.detail)e=-a.detail/3;f.unshift(a,e);return b.event.handle.apply(this,f)}var c=["DOMMouseScroll","mousewheel"];b.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],d,false);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],
d,false);else this.onmousewheel=null}};b.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);


/*
 * Metadata - jQuery plugin for parsing metadata from elements
 * Revision: $Id: jquery.metadata.js 4187 2007-12-16 17:15:27Z joern.zaefferer $
 *
 */
(function($) {
    $.extend({
	metadata : {
	    defaults : {
		type: 'class',
		name: 'metadata',
		cre: /({.*})/,
		single: 'metadata'
	    },
	    setType: function( type, name ){
		this.defaults.type = type;
		this.defaults.name = name;
	    },
	    get: function( elem, opts ){
		var settings = $.extend({},this.defaults,opts);
		if ( !settings.single.length ) settings.single = 'metadata';
		
		var data = $.data(elem, settings.single);
		if ( data ) return data;
		
		data = "{}";
		
		if ( settings.type == "class" ) {
		    var m = settings.cre.exec( elem.className );
		    if ( m )
			data = m[1];
		} else if ( settings.type == "elem" ) {
		    if( !elem.getElementsByTagName )
			return undefined;
		    var e = elem.getElementsByTagName(settings.name);
		    if ( e.length )
			data = $.trim(e[0].innerHTML);
		} else if ( elem.getAttribute != undefined ) {
		    var attr = elem.getAttribute( settings.name );
		    if ( attr )
			data = attr;
		}
		
		if ( data.indexOf( '{' ) <0 )
		data = "{" + data + "}";
		
		data = eval("(" + data + ")");
		
		$.data( elem, settings.single, data );
		return data;
	    }
	}
    });
    $.fn.metadata = function( opts ){
	return $.metadata.get( this[0], opts );
    };
})(jQuery);





(function($){
    $.fn.extend({ 
	easydrag: function(allowBubbling) {

	    return this.each(function(){
    
		var $isMouseDown    = false;
	    
		var $currentElement = null;
	    
		var $dropCallbacks = {};
		var $dragCallbacks = {};
	    
		var $lastMouseX;
		var $lastMouseY;
		var $lastElemTop;
		var $lastElemLeft;
		
		var $dragStatus = {};	
	    
		$.getMousePosition = function(e){
		    var $posx = 0;
		    var $posy = 0;
	    
		    if (!e) var e = window.event;
	    
		    if (e.pageX || e.pageY) {
			$posx = e.pageX;
			$posy = e.pageY;
		    }
		    else if (e.clientX || e.clientY) {
			$posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			$posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
		    }
	    
		    return { 'x': $posx, 'y': $posy };
		};
	    
		$.updatePosition = function(e) {
		    var $pos = $.getMousePosition(e);
	    
		    var $spanX = Math.floor(($pos.x - $lastMouseX)/2);
		    var $spanY = Math.floor(($pos.y - $lastMouseY)/1.2);
		    
		    window.scrollBy($spanX,$spanY);
		    $lastMouseX = $pos.x;
		    $lastMouseY = $pos.y;
		};
	    
		$(document).mousemove(function(e){
		    if($isMouseDown && $dragStatus[$currentElement.id] == 'on'){
			$.updatePosition(e);
			return false;
		    }
		});
	    
		$(document).mouseup(function(e){
		    if($isMouseDown && $dragStatus[$currentElement.id] == 'on'){
			$isMouseDown = false;
			//$("html").focus();
			return false;
		    }
		});
    
		if(undefined == this.id || !this.id.length) this.id = "easydrag"+(new Date().getTime());
    
		$dragStatus[this.id] = "on";
    
		$(this).mousedown(function(e){
		    $isMouseDown    = true;
		    $currentElement = this;
		    
		    var pos    = $.getMousePosition(e);
		    $lastMouseX = pos.x;
		    $lastMouseY = pos.y;
		    
		    $lastElemTop  = this.offsetTop;
		    $lastElemLeft = this.offsetLeft;
		    
		    $.updatePosition(e);
		    
		    return allowBubbling ? true : false;
		});
	    });

	}
    });
})(jQuery);


