jQuery(function($){

    var email_regexp = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

    function valid_email(email) {
        return email_regexp.test(email);
    }
    
    $('.phone-input').mask('(99) 9999-9999');    

    $.ajaxSetup({
        url: SITE + '/ajax',
        type: 'POST'
    });

    $$ = function(el)
    {
        return $(document.getElementById(el));
    };

    $.fn.clear_form = function(){
        $(this).find(':input').each(function(){

            var $this = $(this);

            switch(this.type){
                case 'hidden':
                    break;
                case 'checkbox':
                case 'radio':
                    this.checked = false;
                    break;
                default:
                    $this.val('');
            }

            $this.blur();

        });
    };

    $('#sform-close').live('click', function(){
        $('#simulacao').unblock();
    });

    $('#simulacao-form').find('[name=cep]').mask('99999-999');
    $('#simulacao-form').find('[name=fone]').mask('(99) 9999-9999');
    $('#simulacao-form').find('[name=celular]').mask('(99) 9999-9999');
    $('#simulacao-form').find('[name=aniver]').mask('99/99');
  //  $('#telefone, #telefone_contato, #celular').mask('(99) 9999-9999');

    $('#simulacao-form').submit(function(e){
        e.preventDefault();

        var $this = $(this);
        var ok = true;

        $this.find(':input').not(':button').each(function(){
            $(this).blur();
            if ($.trim($(this).val()) == '') {
                ok = false;
                return false;
            }
        });

        if (!ok) {
            $('#simulacao').block({
                message: 'Por favor, preencha todos os campos<br/><a href="#" id="sform-close" class="button"><span>Ok</span></a>',
                css: {width: '60%'}
            });
            return;
        }

        if (!valid_email( $(this).find('[name=email]').val() )) {
            $('#simulacao').block({
                message: 'Digite um email válido<br/><a href="#" id="sform-close" class="button"><span>Ok</span></a>',
                css: {width: '40%'}
            });
            return;
        }

        $('#simulacao').block();

        $.ajax({
            data: $this.serialize() + '&type=simulacao',
            success: function(resp){
                if (resp == 'true') {
                    $('#simulacao').block({
                        message: 'Sua simulação está em análise. Em breve entraremos em contato.<br/><a href="#" id="sform-close" class="button"><span>Ok</span></a>',
                        css: {width: '80%'}
                    });
                    return;
                }
                this.error();
            },
            error: function(){
                $('#simulacao').unblock();
                alert('Ocorreu um erro, tente novamente');
            }
        });

    });

    $('#contato-atd, .box-atd').find('a').click(function(e){
        e.preventDefault();

        var width = 310;
        var height = 510;
        var left = (screen.width - width) / 2;
        var top = (screen.height - height) / 2;
        window.open(SITE + '/atendente1','atendimento', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no,maximized=no,titlebar=no, fullscreen=no');
    });

/*
    $$('banner-imgs').jqFancyTransitions({
        effect: 'wave',
        strips: 10,
        width: 980,
        height: 727,
        delay: 10000
    });
*/

    if ($$('duvidas')[0]) {
        $$('duvidas').change(function(){

            window.location.href = $(this).val();

        });
    }

    if ($$('city-filter')[0]) {
        var lista = $$('pvendas').children();
        var vel = 500;
        var out = 0.1;

        $$('city-filter').change(function(){
            var $this = $(this);

            if ($this.val() == '') {
                lista.show();
            } else {
                var current = lista.filter('[data-city=' + $this.val() + ']');

                current.show();
                lista.not(current).hide();
            }

        });
    }

    if ($$('box-newsletter')[0]) {
        $$('box-newsletter').submit(function(e){

            e.preventDefault();
            var $this = $$('box-newsletter'),
                msginf = $$('newsletter-msgs'),
                nome   = $$('newsletter-name'),
                email  = $$('newsletter-email');

            msginf.html('');

            if ( ($.trim(nome.val()) == '') || (nome.val() == nome.attr('placeholder')) ) {
                msginf.html('Digite seu nome');
                nome.focus();

                return;
            }

            if ( ($.trim(email.val()) == '') || (email.val() == email.attr('placeholder')) ) {
                msginf.html('Digite seu email');
                email.focus();

                return;
            }

            if (!valid_email($.trim(email.val()))) {
                msginf.html('Digite um email válido');
                email.focus();

                return;
            }

            $this.block();

            $.ajax({
                data: $this.serialize(),
                success: function(res){

                    if (res == 'jatem') {
                        $this.clear_form();

                        $this.block({
                            message: '<p>Email já cadastrado!</p><a href="#" id="nletterbox-close" class="button"><span>Ok</span></a>',
                            css: {
                                width: 220
                            }
                        });

                        $$('nletterbox-close').click(function(e){
                            e.preventDefault();
                            $this.unblock();
                        });

                        return;
                    }

                    if (res == 'true') {
                        $this.clear_form();

                        $this.block({
                            message: '<p>Email cadastrado com sucesso!</p><a href="#" id="nletterbox-close" class="button"><span>Ok</span></a>',
                            css: {
                                width: 220
                            }
                        });

                        $$('nletterbox-close').click(function(e){
                            e.preventDefault();
                            $this.unblock();
                        });

                        return;
                    }
                    this.error();
                },
                error: function(){
                    $this.unblock();
                    msginf.html('<span style="color:red;">Ocorreu um erro, tente novamente.</span>');
                }
            });

        });
    }

    if ( $$('box-callme')[0] ) {
        $$('box-callme').submit(function(e){

            e.preventDefault();
            var $this  = $$('box-callme'),
                msginf = $$('callme-msgs'),
                nome   = $$('callme-name'),
                telefone = $$('callme-phone').blur();

            msginf.html('');

            if ( ($.trim(nome.val()) == '') || (nome.val() == nome.attr('placeholder')) ) {
                msginf.html('Digite seu nome');
                nome.focus();
                return;
            }

            if ( ($.trim(telefone.val()) == '') || (telefone.val() == telefone.attr('placeholder')) ) {
                 msginf.html('Digite seu telefone');
                telefone.focus();

                return;
            }

            $this.block();

            $.ajax({
                data: $this.serialize(),
                success: function(res){
                    if (res == 'true') {
                        $this.clear_form();

                        $this.block({
                            message: '<p>Contato enviado, em breve ligaremos para vocÃª!</p><a href="#" id="callme-close" class="button"><span>Ok</span></a>',
                            css: {
                                width: 220
                            }
                        });

                        $$('callme-close').click(function(e){
                            e.preventDefault();
                            $this.unblock();
                        });

                        return;
                    }
                    this.error();
                },
                error: function(){
                    $this.unblock();
                    msginf.html('<span style="color:red;">Ocorreu um erro, tente novamente.</span>');
                }
            });
        });
    }

    if ( $$('form-depo')[0] ) {

        $$('depoimento').conta('#depo-counter', 250);

        $$('form-depo').submit(function(e){
            e.preventDefault();

            var $this = $$('form-depo'),
                msginf = $$('form-depo-msginf'),
                nome = $$('nome'),
                telefone = $$('telefone').blur(),
                depoimento = $$('depoimento');

            msginf.html('');

            if ( ($.trim(nome.val()) == '') || (nome.val() == nome.attr('placeholder')) ) {
                msginf.html('Digite seu nome');
                nome.focus();

                return;
            }

          /*  if ( ($.trim(telefone.val()) == '') || (telefone.val() == telefone.attr('placeholder')) ) {
              alert(telefone.val());
                msginf.html('Digite seu telefone');
                telefone.focus();

                return;
            }*/

            if ( ($.trim(depoimento.val()) == '') || (depoimento.val() == depoimento.attr('placeholder')) ) {
                msginf.html('Escreva o depoimento');
                depoimento.focus();

                return;
            }

            if ( depoimento.val().length > 250 ) {
                msginf.html('MÃ¡x. 250 caracteres');
                depoimento.focus();

                return;
            }

            $this.block();

            $.ajax({
                data: $this.serialize(),
                success: function(res){
                    if (res == 'true') {
                        $this.clear_form();

                        $this.block({
                            message: '<p>Depoimento enviado! Obrigado por comentar sobre nossos serviÃ§os.</p><a href="#" id="depo-close" class="button"><span>Ok</span></a>',
                            css: {
                                width: 240
                            }
                        });

                        $$('depo-close').click(function(e){
                            e.preventDefault();
                            $this.unblock();
                        });

                        return;
                    }
                    this.error();
                },
                error: function(){
                    $this.unblock();
                    msginf.html('<span style="color:red;">Ocorreu um erro, tente novamente.</span>');
                }
            });

        });

    }

    if ( $$('contact-form')[0] ) {
        $$('contact-form').submit(function(e){
            e.preventDefault();

            var $this = $$('contact-form'),
                msginf = $$('contact-msginf').html('Preencha todos os campos.');

            msginf.css('font-weight', 'normal');

            var ok = true;

            $.each(['nome', 'telefone', 'email', 'cidade', 'mensagem'], function(i, el){

                var el = $$(el);

                el.blur();

                if ($.trim(el.val()) == ''){
                    el.focus();
                    ok = false;

                    return false;
                }

            });

            if (!valid_email($$('email').val()) && ok) {
                $$('email').focus();
                msginf.html('Digite um email vÃ¡lido');
                ok = false;
            }

            if (!ok) {
                msginf.css('font-weight', 'bold');
                return;
            }

            $this.block();

            $.ajax({
                data: $this.serialize(),
                success: function(res){
                    if (res == 'true') {
                        $this.clear_form();

                        $this.block({
                            message: '<p>Mensagem enviada! Em breve entraremos em contato.</p><a href="#" id="cform-close" class="button"><span>Ok</span></a>',
                            css: {
                                width: 300
                            }
                        });

                        $$('cform-close').click(function(e){
                            e.preventDefault();
                            $this.unblock();
                        });

                        return;
                    }
                    this.error();
                },
                error: function(){
                    $this.unblock();
                    msginf.html('<span style="color:red;">Ocorreu um erro, tente novamente.</span>');
                }
            });

        });
    }
 if ( $$('premios')[0] ) {
        $$('premios').submit(function(e){
            e.preventDefault();

            var $this = $$('premios'),
                msginf = $$('contact-msginf').html('Enviando..');

            msginf.css('font-weight', 'normal');

            var ok = true;

            $.each(['nome1', 'telefone1', 'email1', 'escolha'], function(i, el){

                var el = $$(el);

                el.blur();

                if ($.trim(el.val()) == ''){
                    el.focus();
                    ok = false;

                    return false;
                }

            });

            if (!valid_email($$('email1').val()) && ok) {
                $$('email1').focus();
                msginf.html('Digite um email válido');
                ok = false;
            }

            if (!ok) {
                msginf.html('Preencha todos os campos');
                return;
            }


            $.ajax({
                data: $this.serialize(),
                success: function(res){
                    if (res == 'true') {
                        $this.clear_form();

                        msginf.html('Mensagem enviada!');

                        return;
                    }
                    this.error();
                },
                error: function(){
                    $this.unblock();
                    msginf.html('<span style="color:red;">Ocorreu um erro, tente novamente.</span>');
                }
            });

        });
    }
    if ( typeof google != 'undefined' && typeof google.maps != 'undefined' ) {

        var marker_maps = new google.maps.MarkerImage(
            DIR_IMAGES + 'marker.png',
            new google.maps.Size(32,35),
            new google.maps.Point(0,0),
            new google.maps.Point(14,32)
        );

        if ( $$('mapa')[0] ) {

            var arr_latlng = new Array();

            $$('mapa-markers').find('option').each(function(){
                var str = $(this).attr('value').split(',');
                arr_latlng.push(new google.maps.LatLng($.trim(str[0]), $.trim(str[1])));
            });

            var mapDiv = document.getElementById('mapa');
            var map = new google.maps.Map(mapDiv, {
                center: arr_latlng[0],
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true,
                navigationControl: false,
                navigationControlOptions: {
                    position: google.maps.ControlPosition.LEFT
                }
            });

            $.each(arr_latlng, function(i, latlng){
                new google.maps.Marker({
                    position: latlng,
                    map: map,
                    title: 'Uniï¿½o',
                    icon: marker_maps
                });
            });

            $$('mapa-markers').change(function(e){
                e.preventDefault();

                var str = $(this).val().split(',');
                map.setCenter(
                    new google.maps.LatLng($.trim(str[0]), $.trim(str[1]))
                );
            });

            var $map = $(mapDiv);

            var delay = false;

            $$('mapa-container').hover(function(){
                $(this).addClass('has_focus');

                $map.stop(true).animate({
                    width: 400,
                    height: 300
                }, 900, function(){
                    delay = 5000;

                    map.setOptions({
                        navigationControl: true
                    });
                });

            }, function(){

                map.setOptions({
                    navigationControl: true
                });

                $map.stop(true).delay(delay).animate({
                    height: 140,
                    width: 235
                }, 900, function(){
                    map.setOptions({
                        navigationControl: false
                    });
                    $(this).removeClass('has_focus');
                    delay = false;
                });

            });

        }

        if ( $$('pvendas-mapa')[0] ) {

            var arr_latlng = new Array();

            $('.pvendas-li').find('.open-map').each(function(){
                var str = $(this).attr('data-latlng').split(',');
                var latlng = new google.maps.LatLng($.trim(str[0]), $.trim(str[1]));

                arr_latlng.push(latlng);

                $(this).click(function(){
                    map.setCenter( latlng );
                })
            });

            var mapDiv = document.getElementById('pvendas-mapa');
            var map = new google.maps.Map(mapDiv, {
                center: arr_latlng[0],
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true,
                navigationControl: true,
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.DEFAULT,
                    position: google.maps.ControlPosition.LEFT
                }
            });

            $.each(arr_latlng, function(i, latlng){
                new google.maps.Marker({
                    position: latlng,
                    map: map,
                    title: 'Uniï¿½o',
                    icon: marker_maps
                });
            });
        }
    }

    var fop = $('#form-oportunidade');

    fop.submit(function(e){
        e.preventDefault();

        var msgs = $('#fop-msgs').html('Os campos em <strong>negrito</strong> sÃ£o obrigatÃ³rios');
        var type = $('#optype').val();
        var required = ['nome', 'endereco', 'cidade', 'estado', 'telefone', 'email'];

        if (type == 'profissional') {
            required.push('dia', 'mes', 'ano');
        } else {
            required.push('hora', 'minuto');
        }

        var ok = true;

        $.each(required, function(i, el){
            el = fop.find('[name=' + el + ']');

            el.blur();

            if ($.trim(el.val()) == ''){
                el.focus();
                ok = false;
                return false;
            }
        });

        if (ok == false) {
            msgs.html('<span style="color:red">Os campos em <strong>negrito</strong>sÃ£o obrigatÃ³rios</span>');
            return;
        }

        if ( !valid_email($('#email').val()) ) {
            msgs.html('<span style="color:red">Digite um email vÃ¡lido</span>');
            $('#email').focus();
            return;
        }

        $('#credito-forms').block();

        $.ajax({
            data: fop.serialize(),
            success: function(res){
                if (res == 'true') {
                    fop.clear_form();
                    msgs.html('<span style="color:green;">FormulÃ¡rio enviado, em breve entraremos em contato.</span>');
                    $('#credito-forms').unblock();
                    return;
                }
                this.error();
            },
            error: function(){
                $('#credito-forms').unblock();
                msgs.html('<span style="color:red;">Ocorreu um erro, tente novamente.</span>');
            }
        });

    });

    $('#showf-profissional').click(function(){
        fop.insertAfter(this).show();
        fop.find('.fopt').hide().filter('.for-profform').show();
        $('#optype').val('profissional');
    });

    $('#showf-callme').click(function(){
        fop.insertAfter(this).show();
        fop.find('.fopt').hide().filter('.for-callme').show();
        $('#optype').val('callme');
    });

    $.placeholderize();
});

(function($){

    $.placeholderize = function(){

        // Verifica se o browser suporta o atributo placeholder
        if ( true ) {//!$('<input placeholder="1" />')[0].placeholder ) {

            // Fallback para o atributo placeholder
            $('[placeholder]').each(function(){

                var input = $(this);

                input

                    .bind('focus, focus.mask', function(){
                        if (input.val() == input.attr('placeholder')) {
                            input.val('');
                        }
                    })

                    .bind('blur, blur.mask', function(){
                        if (input.val() == '') {
                            input.addClass('placeholder').val(input.attr('placeholder'));
                        }
                    })

                    .bind('focus, focus.mask', function(){
                        input.removeClass('placeholder');
                    })

                    // Invoca o evento, para aplicar a funï¿½ï¿½o de fallback
                    .blur();
            });

        }
    };
})(jQuery);

/*
Masked Input plugin for jQuery
Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
Version: 1.2.2 (03/09/2009 22:39:06)
*/
(function($) {
	var pasteEventName = ($.browser.msie ? 'paste' : 'input') + ".mask";
	var iPhone = (window.orientation != undefined);

	$.mask = {
		//Predefined character definitions
		definitions: {
			'9': "[0-9]",
			'a': "[A-Za-z]",
			'*': "[A-Za-z0-9]"
		}
	};

	$.fn.extend({
		//Helper Function for Caret positioning
		caret: function(begin, end) {
			if (this.length == 0) return;
			if (typeof begin == 'number') {
				end = (typeof end == 'number') ? end : begin;
				return this.each(function() {
					if (this.setSelectionRange) {
						this.focus();
						this.setSelectionRange(begin, end);
					} else if (this.createTextRange) {
						var range = this.createTextRange();
						range.collapse(true);
						range.moveEnd('character', end);
						range.moveStart('character', begin);
						range.select();
					}
				});
			} else {
				if (this[0].setSelectionRange) {
					begin = this[0].selectionStart;
					end = this[0].selectionEnd;
				} else if (document.selection && document.selection.createRange) {
					var range = document.selection.createRange();
					begin = 0 - range.duplicate().moveStart('character', -100000);
					end = begin + range.text.length;
				}
				return {begin: begin, end: end};
			}
		},
		unmask: function() {return this.trigger("unmask");},
		mask: function(mask, settings) {
			if (!mask && this.length > 0) {
				var input = $(this[0]);
				var tests = input.data("tests");
				return $.map(input.data("buffer"), function(c, i) {
					return tests[i] ? c : null;
				}).join('');
			}
			settings = $.extend({
				placeholder: "_",
				completed: null
			}, settings);

			var defs = $.mask.definitions;
			var tests = [];
			var partialPosition = mask.length;
			var firstNonMaskPos = null;
			var len = mask.length;

			$.each(mask.split(""), function(i, c) {
				if (c == '?') {
					len--;
					partialPosition = i;
				} else if (defs[c]) {
					tests.push(new RegExp(defs[c]));
					if(firstNonMaskPos==null)
						firstNonMaskPos =  tests.length - 1;
				} else {
					tests.push(null);
				}
			});

			return this.each(function() {
				var input = $(this);
				var buffer = $.map(mask.split(""), function(c, i) {if (c != '?') return defs[c] ? settings.placeholder : c});
				var ignore = false;  			//Variable for ignoring control keys
				var focusText = input.val();

				input.data("buffer", buffer).data("tests", tests);

				function seekNext(pos) {
					while (++pos <= len && !tests[pos]);
					return pos;
				};

				function shiftL(pos) {
					while (!tests[pos] && --pos >= 0);
					for (var i = pos; i < len; i++) {
						if (tests[i]) {
							buffer[i] = settings.placeholder;
							var j = seekNext(i);
							if (j < len && tests[i].test(buffer[j])) {
								buffer[i] = buffer[j];
							} else
								break;
						}
					}
					writeBuffer();
					input.caret(Math.max(firstNonMaskPos, pos));
				};

				function shiftR(pos) {
					for (var i = pos, c = settings.placeholder; i < len; i++) {
						if (tests[i]) {
							var j = seekNext(i);
							var t = buffer[i];
							buffer[i] = c;
							if (j < len && tests[j].test(t))
								c = t;
							else
								break;
						}
					}
				};

				function keydownEvent(e) {
					var pos = $(this).caret();
					var k = e.keyCode;
					ignore = (k < 16 || (k > 16 && k < 32) || (k > 32 && k < 41));

					//delete selection before proceeding
					if ((pos.begin - pos.end) != 0 && (!ignore || k == 8 || k == 46))
						clearBuffer(pos.begin, pos.end);

					//backspace, delete, and escape get special treatment
					if (k == 8 || k == 46 || (iPhone && k == 127)) {//backspace/delete
						shiftL(pos.begin + (k == 46 ? 0 : -1));
						return false;
					} else if (k == 27) {//escape
						input.val(focusText);
						input.caret(0, checkVal());
						return false;
					}
				};

				function keypressEvent(e) {
					if (ignore) {
						ignore = false;
						//Fixes Mac FF bug on backspace
						return (e.keyCode == 8) ? false : null;
					}
					e = e || window.event;
					var k = e.charCode || e.keyCode || e.which;
					var pos = $(this).caret();

					if (e.ctrlKey || e.altKey || e.metaKey) {//Ignore
						return true;
					} else if ((k >= 32 && k <= 125) || k > 186) {//typeable characters
						var p = seekNext(pos.begin - 1);
						if (p < len) {
							var c = String.fromCharCode(k);
							if (tests[p].test(c)) {
								shiftR(p);
								buffer[p] = c;
								writeBuffer();
								var next = seekNext(p);
								$(this).caret(next);
								if (settings.completed && next == len)
									settings.completed.call(input);
							}
						}
					}
					return false;
				};

				function clearBuffer(start, end) {
					for (var i = start; i < end && i < len; i++) {
						if (tests[i])
							buffer[i] = settings.placeholder;
					}
				};

				function writeBuffer() {return input.val(buffer.join('')).val();};

				function checkVal(allow) {
					//try to place characters where they belong
					var test = input.val();
					var lastMatch = -1;
					for (var i = 0, pos = 0; i < len; i++) {
						if (tests[i]) {
							buffer[i] = settings.placeholder;
							while (pos++ < test.length) {
								var c = test.charAt(pos - 1);
								if (tests[i].test(c)) {
									buffer[i] = c;
									lastMatch = i;
									break;
								}
							}
							if (pos > test.length)
								break;
						} else if (buffer[i] == test[pos] && i!=partialPosition) {
							pos++;
							lastMatch = i;
						}
					}
					if (!allow && lastMatch + 1 < partialPosition) {
						input.val("");
						clearBuffer(0, len);
					} else if (allow || lastMatch + 1 >= partialPosition) {
						writeBuffer();
						if (!allow) input.val(input.val().substring(0, lastMatch + 1));
					}
					return (partialPosition ? i : firstNonMaskPos);
				};

				if (!input.attr("readonly"))
					input
					.one("unmask", function() {
						input
							.unbind(".mask")
							.removeData("buffer")
							.removeData("tests");
					})
					.bind("focus.mask", function() {
						focusText = input.val();
						var pos = checkVal();
						writeBuffer();
						setTimeout(function() {
							if (pos == mask.length)
								input.caret(0, pos);
							else
								input.caret(pos);
						}, 0);
					})
					.bind("blur.mask", function() {
						checkVal();
						if (input.val() != focusText)
							input.change();
					})
					.bind("keydown.mask", keydownEvent)
					.bind("keypress.mask", keypressEvent)
					.bind(pasteEventName, function() {
						setTimeout(function() {input.caret(checkVal(true));}, 0);
					});

				checkVal(); //Perform initial check for existing values
			});
		}
	});
})(jQuery);

/*!
* jQuery Conta Plugin 1.2
* http://lenonmarcel.com.br/code/jquery-conta
*
* Copyright 2009, 2010 Lenon Marcel
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Date: 07-12-2010 (July 12, 2010)
*/

(function($){

    $.fn.conta = function( counter, len )
    {
        if (!len) len = 140; // Twitter limit :)

        var input = $(this),
            counter = $(counter),
            els = [input, counter];

        input.keyup( function() {

            var count = len - input.val().length;

            for ( var i = 0; i < 2; i++ )
            {
                if (count < 0) {
                    els[i].removeClass('safe').addClass('over');
                } else {
                    els[i].removeClass('over').addClass('safe');
                }
            }

            counter.text(count);

        }).keyup();

        return this;
    }

})(jQuery);

function addFlash(file, width, height, id, wmode, version,flashvars) 
{
	var params = {'wmode':wmode};
	var attributes = {'id':id};	
	swfobject.embedSWF(file, id, width, height, version,"site/js/expressInstall.swf", flashvars, params, attributes)
}
