;(function($){
	$.extend({
		Cristalino: function(options) {
			return {
				init: function(options) {
					settings = jQuery.extend({
						//name: options.name,
						lang: options.lang
					}, options);
						
					return this;
				},

				// Exibe os itens do menu accordion --------------------------------
				GaleriaAccordion: function(p) {
					$('#picturesAccordion').accordion({ autoHeight: false });
				},// GaleriaAccordion
				
				// Imagens da Home -------------------------------------------------
				HomeImages: function(p) {
					$.post('get_home.php',{ acao: "IMAGEM-HOME", lang: settings.lang },
						function(resposta){							
						$("#colunahome").html(resposta);						
						return false;
						}
					);
				},// HomeImages

				// Notícias Exibidas na Home ---------------------------------------
				NoticiasListHome: function(p) {
					$.post('get_noticias.php',{ acao: "NEWS-LIST", lang: settings.lang },
						function(resposta){							
							$("#news").html(resposta);
							$(".linknews").click(function(){								
								window.location='noticias.php?lang='+ settings.lang +'&id='+ $(this).attr('code');								
							})
							return false;
						}
					);
				},// NoticiasListHome

				// Galerias das Categorias -----------------------------------------
				GaleriasLoad: function(p) {
					$.post('get_galerias.php',{ acao: "PICTURES-LIST", lang: settings.lang, idcategoria: p.idcategoria },
						function(resposta){							
							$("#pictures").html(resposta);
							$.Cristalino.GaleriasLoadMain();
							$.Cristalino.GaleriaAccordion();
							$.Cristalino.PreLoadImage();
							return false;
						}
					);
				},// GaleriasLoad

				// Galerias das Notícias -------------------------------------------
				GaleriasLoadNews: function(p) {
					$.post('get_galerias.php',{ acao: "PICTURES-LIST-NEWS", lang: settings.lang, idnoticia: p.idnoticia },
						function(resposta){							
							$("#pictures").html(resposta);
							$.Cristalino.GaleriasLoadMain();
							$.Cristalino.GaleriaAccordion();
							$.Cristalino.PreLoadImage();
							return false;
						}
					);
				},// GaleriasLoadNews

				// Vídeos das Categorias -------------------------------------------
				VideosLoad: function(p) {
					$.post('get_galerias.php',{ acao: "VIDEOS-LIST", lang: settings.lang, idcategoria: p.idcategoria },
						function(resposta){							
							$("#videos").html(resposta);
							$.Cristalino.VideosLoadMain();
							if(p.loadvideo == 1){ $.Cristalino.VideosLoadMainFirst(); }
							return false;
						}
					);
				},// VideosLoad

				// Vídeos das Notícias ---------------------------------------------
				VideosLoadNews: function(p) {
					$.post('get_galerias.php',{ acao: "VIDEOS-LIST-NEWS", lang: settings.lang, idnoticia: p.idnoticia },
						function(resposta){							
							$("#videos").html(resposta);
							$.Cristalino.VideosLoadMain();
							return false;
						}
					);
				},// VideosLoadNews

				// PDFs das Categorias ---------------------------------------------
				PDFSLoad: function(p) {
					$.post('get_galerias.php',{ acao: "PDFS-LIST", lang: settings.lang, idcategoria: p.idcategoria },
						function(resposta){							
							$("#pdfs").html(resposta);
							return false;
						}
					);
				},// PDFSLoad

				// PDFs das Notícias -----------------------------------------------
				PDFSLoadNews: function(p) {
					$.post('get_galerias.php',{ acao: "PDFS-LIST-NEWS", lang: settings.lang, idnoticia: p.idnoticia },
						function(resposta){							
							$("#pdfs").html(resposta);
							return false;
						}
					);
				},// PDFSLoad


				// Carrega as Imagens em OFF ---------------------------------------
				PreLoadImage: function(){
					$(".fileGaleria").each(function() {
						$img	= $(this).attr('rel');
						var img = new Image();
						$(img).load(function () {
							//alert('carregou');
						}).error(function () {
							// notify the user that the image could not be loaded
						}).attr('src', $img);
					});
					return false;
				},

				// Carrega a imagem Main -------------------------------------------
				GaleriasLoadMain: function() {
					$(".fileGaleria").click(function(){
						$('.loading').show();
						$img	= $(this).attr('rel');
						$legenda	= $(this).attr('title');
						var img = new Image();
						$(img).load(function () {
							$('.loading').hide();
							$('.fotoMainCenter').html('');
							$(this).hide();
							$('.fotoMainCenter').removeClass('loading').append(this).fadeTo("slow", 1.0);
							$(this).fadeIn();
						}).error(function () {
							// notify the user that the image could not be loaded
						}).attr('src', $img);
						$('.fotoMainLegenda').html($legenda);
					});// fileGaleria
				},// GaleriasLoadMain

				// Carrega o vídeo no centro
				// -----------------------------------------------------------------
				VideosLoadMain: function() {
					$(".fileLoadVideo").click(function(){
						var v	= $(this).attr('rel');
//						var v	= "http://www.youtube.com/v/wGtz6iMeZJ8&hl=pt-br&fs=1&autoplay=1";
//						var v = "http://www.youtube.com/watch?v=I_n9RBmxbqg";

						// YouTube
						$movie = v;
						if (v.match(/watch\?v=(.+)(.*)/)) {
							$movie = 'http://www.youtube.com/v/' + v.match(/v=(.*)(.*)/)[0].split('=')[1];
						}
						$legenda	= $(this).attr('title');
//						$('.loading').hide();
						$.get("templates/tmp_youtube.html", function(data){
							var t = $.template( data );
							$('.fotoMainCenter').removeClass('loading').fadeTo("slow", 1.0);
							$(".fotoMainCenter").html( t , {
								urlvideo: $movie
							});		
						});
						$(".fotoMainCenter").show();
						$('.fotoMainLegenda').html($legenda);
						return false;
					});// end : fileGaleria : click
				},// end : VideosLoadMain

				// Carrega o primeiro vídeo da lista -------------------------------
				VideosLoadMainFirst: function() {
					$('.loading').show();
					$this = $(".fileLoadVideo:fist");
					var v	= $this.attr('rel');
					// YouTube
					$movie = v;
					if (v.match(/watch\?v=(.+)(.*)/)) {
						$movie = 'http://www.youtube.com/v/' + v.match(/v=(.*)(.*)/)[0].split('=')[1];
					}
					$legenda	= $this.attr('title');
//						$('.loading').hide();
					$.get("templates/tmp_youtube.html", function(data){
						var t = $.template( data );
						$('.fotoMainCenter').removeClass('loading').fadeTo("slow", 1.0);
						$(".fotoMainCenter").html( t , {
							urlvideo: $movie
						});		
					});
					$('.loading').hide();
					$(".fotoMainCenter").show();
					$('.fotoMainLegenda').html($legenda);
					return false;
				},// VideosLoadMainFirst

				// Carrega a imagem Main
				// -----------------------------------------------------------------
				CategoriaLoad: function(p) {
					//$("#retorno").html( 'load: '+ p.idcategoria );
					$.post('get_categorias.php',{
						acao: "CATEGORIAS-MAIN",
						lang: settings.lang,
						idcategoria: p.idcategoria
					},
						function(resposta){							
							$("#right").html(resposta);							
							$.Cristalino.GaleriasLoad({idcategoria: p.idcategoria});
							$.Cristalino.VideosLoad({idcategoria: p.idcategoria});
							$.Cristalino.PDFSLoad({idcategoria: p.idcategoria});
							$.Cristalino.GaleriasLoadMain();
							return false;
						}
					);
				},// end : CategoriaLoad


				// Carrega a imagem Main
				// -----------------------------------------------------------------
				NoticiasLoad: function(p) {
					//$("#retorno").html( 'load: '+ p.idcategoria );
					$.post('get_noticias.php',{
						acao: "NOTICIAS-MAIN",
						lang: settings.lang,
						id: p.id
					},
						function(resposta){							
							$("#chamadas").html(resposta);							
//							$.Cristalino.GaleriasLoad({idcategoria: p.idcategoria});
//							$.Cristalino.VideosLoad({idcategoria: p.idcategoria});
//							$.Cristalino.PDFSLoad({idcategoria: p.idcategoria});
//							$.Cristalino.GaleriasLoadMain();
							return false;
						}
					);
				},// end : CategoriaLoad










				// Relacionados
				// -----------------------------------------------------------------
				// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				// GALERIA DE IMAGENS
				// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




				um: function() { 
					alert('um ' + settings.name )
				},

        dois: function() {
					alert('dois ' + settings.id)
				}

			};
		}()
	});
})(jQuery);
