﻿var ApplicationPath = '';
var EditorPath = '';
var EditorArea = '';
var UseLightBox = false;
var ResizeCenterBar = true;
var CentralBarExtraHeight = 0;


$(document).ready(function() {
 $('#advert1').show();
 $('#advert1 ul').innerfade({
 speed: 1000,
 timeout: 5000,
 type: 'sequence'
 });

 /* setting advertisements */
 if ($('#advert2 ul')) {
 $('#advert2').show();
 $('#advert2 ul').innerfade({
 speed: 1000,
 timeout: 7000,
 type: 'sequence'
 });
 }

 $('.submit_search').click(function() {
 var term = $.trim($('.input_search').val());
 if (term.length < 4) {
 $.jGrowl('Você precisa digitar ao menos 4 letras para realizar a busca');
 return false;
 }
 });

 /* set lightbox resource for images*/
 if (UseLightBox) {
 $('.lightboxImages').lightBox({
 imageLoading: ApplicationPath + 'content/images/lightbox/lightbox-ico-loading.gif',
 imageBtnClose: ApplicationPath + 'content/images/lightbox/lightbox-btn-close.gif',
 imageBtnPrev: ApplicationPath + 'content/images/lightbox/lightbox-btn-prev.gif',
 imageBtnNext: ApplicationPath + 'content/images/lightbox/lightbox-btn-next.gif',
 txtImage: 'Imagem',
 txtOf: 'de'
 });

 $('.lightboxImagesGroup2').lightBox({
 imageLoading: ApplicationPath + 'content/images/lightbox/lightbox-ico-loading.gif',
 imageBtnClose: ApplicationPath + 'content/images/lightbox/lightbox-btn-close.gif',
 imageBtnPrev: ApplicationPath + 'content/images/lightbox/lightbox-btn-prev.gif',
 imageBtnNext: ApplicationPath + 'content/images/lightbox/lightbox-btn-next.gif',
 txtImage: 'Imagem',
 txtOf: 'de'
 });
 }

 /* adjusting centerBar height*/
 if (ResizeCenterBar) {
 var mainLeftHeight = $('#mainLeft').height() - 58;
 var mainRightHeight = $('#mainRight').height() - 58;

 if (mainLeftHeight > mainRightHeight)
 $('#centerBar').height(mainLeftHeight + CentralBarExtraHeight);
 else
 $('#centerBar').height(mainRightHeight + CentralBarExtraHeight);
 } 
 
 /** jq dock **/
 //var opts = { align: 'middle', duration: 300, size: 23}; /*, labels: true*/
 //$('#animeFastLinks').jqDock(opts);
 //$('#rpgFastLinks').jqDock(opts);
 
 setFastLinkTooltip();
 
 $('.fastLinksBar img').mouseout(function(){
 $('.tooltipBox').html('');
 });
 
 $('.fastLinkButton').click(function(){
 setFastLinkActive($(this).attr('id'));
 });
});

function setFastLinkActive(id)
{
 var active = $('#' + id);
 $('#fastLinksAnimesActive').attr('id', 'fastLinksAnimes');
 $('#fastLinksRpgActive').attr('id', 'fastLinksRpg');
 $('#fastLinksGamesActive').attr('id', 'fastLinksGames');
 
 $('#fastLinks').html($('#' + active.attr('id') + 'Hidden').html());
 active.attr('id', active.attr('id').replace('Active','') + 'Active');
 setFastLinkTooltip();
}

function setFastLinkTooltip()
{
 $('.fastLinksBar img').mouseover(function(){
 var title = '';
 var itemClass = $(this).parent().parent().attr('class');
 
 if (itemClass == 'iconCreateArticle') title = "Criar Artigo";
 else if (itemClass == 'iconCreateReview') title = "Criar Review";
 else if (itemClass == 'iconCreateFanart') title = "Enviar Fanart";
 else if (itemClass == 'iconCreateWallpaper') title = "Enviar Wallpaper";
 else if (itemClass == 'iconCreateFanfic') title = "Criar Fanfic";

 else if (itemClass == 'iconCreateChronicle') title = "Criar Conto";
 else if (itemClass == 'iconCreateLegend') title = "Postar Lenda";
 else if (itemClass == 'iconCreateBorder') title = "Cadastrar Produto";
 
 if (itemClass == 'iconCreateArticle') title = "Criar Artigo";
 else if (itemClass == 'iconCreateReview') title = "Criar Review";
 else if (itemClass == 'iconCreateScreenshot') title = "Enviar Screenshot";
 else if (itemClass == 'iconCreateWallpaper') title = "Enviar Wallpaper";
 else if (itemClass == 'iconCreateWalkthrough') title = "Criar Detonado";
 else if (itemClass == 'iconCreateVideo') title = "Criar Vídeo";
 else if (itemClass == 'iconCreateGameIndication') title = "Criar Indicação"; 
 
 
 $('.tooltipBox').html(title);
 });
 
 $('.fastLinksBar img').mouseout(function(){
 $('.tooltipBox').html('');
 });
}


function GetEditor(width, height, toolbarset, value)
{
 window.onload = function()
 {
 var sBasePath = EditorPath;
 var oFCKeditor = new FCKeditor( 'FckEditor1', width, height, toolbarset, value ) ;

/* if (EditorArea != '')
 {
 
 var sSkin = 'default';
 var sSkinPath = sBasePath + 'editor/skins/' + sSkin + '/' ;
 oFCKeditor.Config['SkinPath'] = sSkinPath; 
 oFCKeditor.Config['SkinEditorCSS'] = sSkinPath + 'fck_editor_' + EditorArea + '.css'; 
 } */
 
 oFCKeditor.BasePath = sBasePath ;
 oFCKeditor.ReplaceTextarea() ;
 }
}

// called when FCKeditor is done starting..
function FCKeditor_OnComplete( editorInstance ){
 editorInstance.LinkedField.form.onsubmit = doSave;
 jQuery.each(jQuery.browser, function(i, val) {
 if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
 window.stop();
 }); 
}

 function limitChars(textid, limit, infodiv)
 {
 var text = $('#'+textid).val(); 

 var textlength = text.length;
 if(textlength > limit)
 {
 $('#' + infodiv).html('Você não pode escrever mais do que '+limit+' caracteres!');
 $('#'+textid).val(text.substr(0,limit));
 return false;
 }
 else
 {
 $('#' + infodiv).html('Você ainda possui '+ (limit - textlength) +' caracteres restantes.');
 return true;
 }
 }
 
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robert Nyman | http://robertnyman.com/ */
function removeHTMLTags(strInputCode){
 strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 return (p1 == "lt")? "<" : ">";
});
var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
return strTagStrippedText;

}

function check_extension(filename) {
 var re = /\..+$/;
 var ext = filename.match(re);
 if (hash[ext]) 
 return true;
 else 
 return false;
}

function message(text)
{
 $.jGrowl(text);
 return false;
}

