var d=document;
$ = function(id) {
	if(!arguments[1]) return document.getElementById(id);
	else document.getElementById(id).style[arguments[1]]=arguments[2];
}


function delItem(arr,item){
	for(;item<arr.length;item++) arr[item]=arr[item + 1];
	arr.length=arr.length-1;
} 

function goURL(){
	(Item[atual][3].indexOf('_blank')!=-1) ? window.open(Item[atual][3].substring(0,Item[atual][3].indexOf(' '))) : location.href=Item[atual][3];
} 

function startSlide(){ 
	loadImages();
	if(!paused) timeoutId=setTimeout('changeImg(1)',6000);
} 

function initialize(){
	timeoutId=0;
	textareaContent=d.form_cr.select_cr.value.xSplit(/[\r\n]/i);
	Item = new Array();
	var y=0;
	for(x=0;x<textareaContent.length;x++){ 
		if(textareaContent[x].length>30) Item[y++]=textareaContent[x].split('|');
	}
	for(i=Item.length-1;i>=0;i--){
		Item[i][0]=Item[i][0].replace(/([ \n\t\r])+/, " ");
		Item[i][4]=(Item[i][4].length<3) ? '' : '<img src="'+Item[i][4]+'" border="0" style="margin-left:4px;" />';
		if(Item[i][1].length<3||Item[i][3].length<3||Item[i][2].length<3||Item[i][0].length<2) delItem(Item,i);
	}
	if(Item.length==1) d.write('<style>#anterior,#proximo,#pause{visibility:hidden;}</style>');
	atual = Math.random().toString().substring(2,6) % Item.length;
}

function startPanel(){
	usaCredito = '';
	initialize();
	if(arguments.length>0){
		if(!isNaN(arguments[0])) atual = arguments[0];
	}
	if(paused) {imgpause='on'; altpause='alt="Ligar" title="Ligar"';}
	else {imgpause='off'; altpause='alt="Parar" title="Parar"';}
}


function pauseSlide(){
if(paused){
	$('pause').src='imagens/pause.gif';
	$('pause').title='Parar'; $('pause').alt = 'Parar';
	d.cookie="homeFICOPOLApause=0;domain=.FICOPOLA.com.br;expires=Thu, 2 Aug 1970 20:47:11 UTC;"; 		
	paused=false;
	startSlide();
}else{
	clearTimeout(timeoutId);
	d.cookie="homeFICOPOLApause=1;domain=.FICOPOLA.com.br;expires=Thu, 2 Aug 2222 20:47:11 UTC;"; 	
	$('pause').src='imagens/pause1.gif';
	$('pause').title='Ligar'; $('pause').alt = 'Ligar';
	paused = true;
} }

var okToGo=false;
var paused=(d.cookie.indexOf('homeFICOPOLApause=1')!=-1) ? true : false;
onload=startSlide;


// painel rotativo //
function changeOpac(opacity){
var obj = $('to-blend').style;
obj.opacity=(opacity/101);
obj.MozOpacity=(opacity/101);
obj.KhtmlOpacity=(opacity/101);
} function blend(imagefile){
var speed=7;
var timer=0;
for(i=100;i>0;i-=2) setTimeout('changeOpac('+i+')', timer++ * speed);
setTimeout('changeContent()', timer * speed);
for(i=0;i<=100;i+=2) setTimeout('changeOpac('+i+')', timer++ * speed);
}

function changeImg(id){
clearTimeout(timeoutId);
atual+=parseInt(id);
if(atual>Item.length-1) atual=0;
if(atual<0) atual=Item.length-1;
if(imgDsp[atual].complete==false){
	atual--;
	timeoutId = setTimeout('changeImg('+id+')',500);
	return;
	} 
if(d.all && navigator.userAgent.indexOf('Opera')==-1){
	try {
	oDiv = $('to-blend');
	oDiv.style.filter="blendTrans(duration=0.7)";
   	oDiv.filters.blendTrans.apply();
    oDiv.filters.blendTrans.play();
	changeContent();
	} catch(e) {  }
} else { blend(); }
if(!paused) timeoutId=setTimeout('changeImg(1)',6000);
}

function loadImages(){
	imgDsp = new Array();
	for(n=0;n<Item.length;n++){
		imgDsp[n]=new Image();
		imgDsp[n].src=Item[n][1];
	}
	okToGo = true;
}

function changeContent(){
d.img1.src=imgDsp[atual].src;
d.img1.alt=d.img1.title=Item[atual][0];
//$('txt1').innerHTML=document.getElementById(Item[atual][2]).innerHTML;
if(d.getElementById("td1").className  == 'noitica2' && d.getElementById("td2").className  == 'noitica1' && d.getElementById("td3").className  == 'noitica1'){
	d.getElementById("td1").className  = 'noitica1';
	d.getElementById("td2").className  = 'noitica2'
}else if(d.getElementById("td1").className  == 'noitica1' && d.getElementById("td2").className  == 'noitica2' && d.getElementById("td3").className  == 'noitica1'){
	d.getElementById("td2").className  = 'noitica1';
	d.getElementById("td3").className  = 'noitica2'	
}else if(d.getElementById("td1").className == 'noitica1' && d.getElementById("td2").className  == 'noitica1' && d.getElementById("td3").className  == 'noitica2'){
	d.getElementById("td3").className  = 'noitica1';
	d.getElementById("td1").className  = 'noitica2'	
}
//alert($('txt1').innerHTML)
if(usaCredito!='') $('credito').innerHTML=Item[atual][0];
$('icon-area').innerHTML=Item[atual][4];
}


/* Cross-Browser Split 1.0.1
(c) Steven Levithan <stevenlevithan.com>; MIT License
An ECMA-compliant, uniform cross-browser split method */

var cbSplit;

// avoid running twice, which would break `cbSplit._nativeSplit`'s reference to the native `split`
if (!cbSplit) {

cbSplit = function (str, separator, limit) {
    // if `separator` is not a regex, use the native `split`
    if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
        return cbSplit._nativeSplit.call(str, separator, limit);
    }

    var output = [],
        lastLastIndex = 0,
        flags = (separator.ignoreCase ? "i" : "") +
                (separator.multiline  ? "m" : "") +
                (separator.sticky     ? "y" : ""),
        separator = RegExp(separator.source, flags + "g"), // make `global` and avoid `lastIndex` issues by working with a copy
        separator2, match, lastIndex, lastLength;

    str = str + ""; // type conversion
    if (!cbSplit._compliantExecNpcg) {
        separator2 = RegExp("^" + separator.source + "$(?!\\s)", flags); // doesn't need /g or /y, but they don't hurt
    }

    /* behavior for `limit`: if it's...
    - `undefined`: no limit.
    - `NaN` or zero: return an empty array.
    - a positive number: use `Math.floor(limit)`.
    - a negative number: no limit.
    - other: type-convert, then use the above rules. */
    if (limit === undefined || +limit < 0) {
        limit = Infinity;
    } else {
        limit = Math.floor(+limit);
        if (!limit) {
            return [];
        }
    }

    while (match = separator.exec(str)) {
        lastIndex = match.index + match[0].length; // `separator.lastIndex` is not reliable cross-browser

        if (lastIndex > lastLastIndex) {
            output.push(str.slice(lastLastIndex, match.index));

            // fix browsers whose `exec` methods don't consistently return `undefined` for nonparticipating capturing groups
            if (!cbSplit._compliantExecNpcg && match.length > 1) {
                match[0].replace(separator2, function () {
                    for (var i = 1; i < arguments.length - 2; i++) {
                        if (arguments[i] === undefined) {
                            match[i] = undefined;
                        }
                    }
                });
            }

            if (match.length > 1 && match.index < str.length) {
                Array.prototype.push.apply(output, match.slice(1));
            }

            lastLength = match[0].length;
            lastLastIndex = lastIndex;

            if (output.length >= limit) {
                break;
            }
        }

        if (separator.lastIndex === match.index) {
            separator.lastIndex++; // avoid an infinite loop
        }
    }

    if (lastLastIndex === str.length) {
        if (lastLength || !separator.test("")) {
            output.push("");
        }
    } else {
        output.push(str.slice(lastLastIndex));
    }

    return output.length > limit ? output.slice(0, limit) : output;
};

cbSplit._compliantExecNpcg = /()??/.exec("")[1] === undefined; // NPCG: nonparticipating capturing group
cbSplit._nativeSplit = String.prototype.split;

} // end `if (!cbSplit)`

// for convenience...
String.prototype.split = function (separator, limit) {
    return cbSplit(this, separator, limit);
};

String.prototype.xSplit = function(_regEx)
{
   // Most browsers can do this properly, so let them -- they'll do it faster
   if ('a~b'.split(/(~)/).length === 3) { return this.split(_regEx); }
   if (!_regEx.global)
      { _regEx = new RegExp(_regEx.source, 'g' + (_regEx.ignoreCase ? 'i' : '')); }

   // IE (and any other browser that can't capture the delimiter)
   // will, unfortunately, have to be slowed down
   var m, str = '', arr = [];
   var i, len = this.length;
   for (i = 0; i < len; i++)
   {
      str += this.charAt(i);
      m = str.match(_regEx);
      if (m)
      {
         arr.push(str.replace(m[0], ''));
         arr.push(m[0]);
         str = '';
      }
   }

   if (str != '') arr.push(str);

   return arr;
}
