var ids = [];
var active = 0;

jQuery(document).ready(function(){	
	jQuery.each(jQuery(".box-destaque-slideshow .slide"), function(i, n){											
		ids.push(n.id);		
	});
	slider(ids);	
});

function slider(arr){
	setInterval(function(){
						 if (active < arr.length){
							if (active == arr.length-1)
							 	next = 0;
							else
								next = active+1;
							jQuery(".box-destaque-slideshow #"+arr[active]).fadeOut(function(){
															jQuery(".box-destaque-slideshow #"+arr[next]).fadeIn();									 
																 });							 
							 active++;
							 if(active == arr.length) active=0;
						 }
						 },5000);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function mudaVersao(str){
	if (str == 'normal'){
		$('#headerimg .link-home ').css('background-image','url(http://www.abracomcuidado.com/wp-content/themes/Abra_com_cuidado_V2/images/header.jpg)');
		$('#headerimg .link-home ').css('background-position','center 0');
		$('.box-destaque-slideshow').css('display','block');
		$('body').css('background-color','#857C6E');
		$('body').css('background-image','url(http://www.abracomcuidado.com/wp-content/themes/Abra_com_cuidado_V2/images/bg.jpg)');
		$('body').css('background-repeat','repeat-x');
		$('.coluna img').css('display','inline');
		$('.linha img').css('display','inline');
		createCookie('versao','normal');
	}else{
		$('#headerimg .link-home ').css('background-image','url(http://www.abracomcuidado.com/wp-content/themes/Abra_com_cuidado_V2/images/bg_top_office.jpg)');
		$('#headerimg .link-home ').css('background-position','center 0');
		$('.box-destaque-slideshow').css('display','none');
		$('body').css('background-image','url(http://www.abracomcuidado.com/wp-content/themes/Abra_com_cuidado_V2/images/bg_office.jpg)');
		$('body').css('background-repeat','repeat-x');
		$('.coluna img').css('display','none');	
		$('.linha img').css('display','none');	
		createCookie('versao','office');
	}
}

if(readCookie('versao') == 'office'){
	mudaVersao('office');	
}else{
	mudaVersao('normal');
}
