﻿$(document).ready(function() {
    $('.Mdl').click(function(){
        $('.mdl-inscrever').modal({
            opacity:80,
        	overlayCss: {backgroundColor:'#fff'},
        	width: 515,
        	overlayClose:true
        });
    });
    
    $('.over').each(function(){           
		var imgUrl = $(this).css('background-image');
        file = imgUrl.substring(imgUrl.lastIndexOf('/'),imgUrl.lastIndexOf('.'));
		ext = imgUrl.substring(imgUrl.lastIndexOf('.'),imgUrl.lastIndexOf('"'));
					
		$('body').append('<img src="Conteudo/_img' + file + '-over' + ext + '" class="none" />');
    });

    $('.mdl-padrao').prepend('<div class="mdl-top"></div>').append('<div class="mdl-bottom"></div>');
    
    
    $(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});

    $("a[rel='galGeral']").colorbox();
    $("a[rel='galSaoPaulo']").colorbox({loop:false}).click(function(){ $('.btn-modal-veja-mais').attr('href','Fotos.aspx?cidade=SaoPaulo') });
    $("a[rel='galCampinas']").colorbox({loop:false}).click(function(){ $('.btn-modal-veja-mais').attr('href','Fotos.aspx?cidade=Campinas') });
    $("a[rel='galRioDeJaneiro']").colorbox({loop:false}).click(function(){ $('.btn-modal-veja-mais').attr('href','Fotos.aspx?cidade=RioDeJaneiro') });
    $("a[rel='galPortoAlegre']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=PortoAlegre') });
    $("a[rel='galRiberao']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=RibeiraoPreto') });

    $("a[rel='galCuritiba']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=Curitiba') });
    $("a[rel='galGoiania']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=Goiania') });
    $("a[rel='galRecife']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=Recife') });
    $("a[rel='galSalvador']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=Salvador') });
    $("a[rel='galBeloHorizonte']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=BeloHorizonte') });
    $("a[rel='galBrasilia']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=Brasilia') });
    $("a[rel='galBelem']").colorbox({ loop: false }).click(function() { $('.btn-modal-veja-mais').attr('href', 'Fotos.aspx?cidade=Belem') });
    
    $('body').supersleight();
});

function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength) {
        obj.value = obj.value.substring(0, mlength)
    }
} 

jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: '../_img/x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
				    self.css('position', 'relative');
				};
			});
		};
	});
};



function urlencode(str) {

    var histogram = {}, tmp_arr = [];
    var ret = (str + '').toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram["'"] = '%27';
    histogram['('] = '%28';
    histogram[')'] = '%29';
    histogram['*'] = '%2A';
    histogram['~'] = '%7E';
    histogram['!'] = '%21';
    histogram['%20'] = '+';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%" + m2.toUpperCase();
    });

    return ret;
}


function urldecode(str) {

    var histogram = {};
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urlencode.
    histogram["'"] = '%27';
    histogram['('] = '%28';
    histogram[')'] = '%29';
    histogram['*'] = '%2A';
    histogram['~'] = '%7E';
    histogram['!'] = '%21';
    histogram['%20'] = '+';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';

    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }

    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
} 

