var newclick=0;

jQuery(document).ready(function(){
	
	//move1();
	//jQuery("body").css({background-position:"0px 0px"});
	//jQuery("body").animate({backgroundPosition: "-1000px 0px" },5000);
	
	jQuery(".menu-item").each(function(event){
		
		var obj = jQuery(this).children("a");
		var url = jQuery(obj[0]).attr("href");
		var title = jQuery(obj[0]).html();
		var id = title.replace(/[\s.]/g,"_");
		
		jQuery("#vContainer").append("<div id='" + jQuery(this).attr("id") + "_1'>" + url + "<br /> " + title + "</div>");
		
		if (title == "Contato") {
			jQuery(this).css("border","none");
		}
		
		if (url.search(/(blog|contato)/) != -1 || document.location.toString().search(/blog/) != -1) {
			//jQuery.scrollTo('#accessTop', 800 );
		} else {
			jQuery("#vContainer").append("<div id='" + id + "'></div>");
			
			jQuery("#"+id).html("<img src='http://campanhadigital.net.br/images/ajax-loader.gif'>");
			
			jQuery('#'+id).load(url + "?ajax=1");
		}
		
		jQuery(obj[0]).click(function(e){
			e.preventDefault();
			
			newclick=1;
			$(window).location.hash = id;
			
			jQuery(".menu-item").removeClass("current_page_item");
			jQuery(obj[0]).parent().addClass("current_page_item");
			
			if (url.search(/(blog|contato)/) != -1 || document.location.toString().search(/blog/) != -1) {
				document.location = url;
			} else {
				jQuery('#content').html(jQuery('#'+id).html());
				var t = setTimeout("replaceAfter()",200);
				jQuery.scrollTo('#accessTop', 800 );
			}
			
		});
		
		
	});
	
	
	var SB;
	
	setSidebarPosition(SB);
	
	jQuery(window).scroll(function() {
		  
		  setSidebarPosition(SB);
		  
	});
	
	
	jQuery(window).resize(function() {
		
		if (jQuery(".youtube").length != 0) {
			var obj = jQuery(".youtube object");
			
			var height = ((obj.width()*1080)/1920) + 25;
			
			obj.css("height",height);
		}
		
		if (jQuery(".prezi-player").lenght != 0) {
		
			var obj1 = jQuery(".prezi-player");
			var obj2 = jQuery("#prezi_aeedibzpyotw");
			var obj3 = jQuery("#preziEmbed_aeedibzpyotw");
			
			var height1 = ((obj1.width()*490)/750);
			
			obj1.css("height",height1);
			obj2.css("height",height1);
			obj3.css("height",height1);
			
		}
	
	});

	
	var t = setTimeout("replaceAfter()",1000);

 });
 
 
 function setSidebarPosition(SB) {
 	
 	offsetTop = jQuery(window).scrollTop();
 	
 	SB = isScreenBigger();
		
	  if (SB == 1 && offsetTop >= 492) {
		  jQuery('.sidebar').css("position", "fixed");
		  jQuery('.sidebar').css("top", "0px");
		  jQuery('.sidebar').css("right", "5%");
		  jQuery('.sidebar').css("margin-right","8px");
		  jQuery('.sidebar').css("width","22%");
	  } else if (SB != 1 && SB != 0 && offsetTop >= 492) {
	  	  jQuery('.sidebar').css("position", "fixed");
		  jQuery('.sidebar').css("top", -SB + "px");
		  jQuery('.sidebar').css("right", "5%");
		  jQuery('.sidebar').css("margin-right","8px");
		  jQuery('.sidebar').css("width","22%");
	  } else {
		  jQuery('.sidebar').css("position", "static");
		  jQuery('.sidebar').css("right", "0px");
		  jQuery('.sidebar').css("margin-right","0px");
		  jQuery('.sidebar').css("width","25%");
	  }
 	
 }
 
 
 function isScreenBigger() {
 	
 	var screenBigger;
 	
	if (jQuery(window).height() > 570) {
		return 1;
	} else if (jQuery(window).height() < 570 && jQuery(window).height() > 400) {
		return -(jQuery(window).height()) + 570;
	} else {
		return 0;
	}
 	
 }
 
 function replaceAfter() {
 
 	if ($(window).location.hash != "" && newclick=="0") {
		
		newclick = 1;
		
		var t;
		var page = $(window).location.hash.replace("#","");
		
		jQuery(".menu-item").each(function(){
			
			var obj1 = jQuery(this).children("a");
			var url1 = jQuery(obj1[0]).attr("href");
			var title1 = jQuery(obj1[0]).html();
			var id1 = title1.replace(/[\s.]/g,"_");
			
			if (id1.toLowerCase() == page.toLowerCase()) {
				jQuery(".menu-item").removeClass("current_page_item");
				jQuery(obj1[0]).parent().addClass("current_page_item");
				jQuery("#content").html("<img src='http://campanhadigital.net.br/images/ajax-loader.gif'>");
				jQuery('#content').load(url1 + "?ajax=1");
				jQuery.scrollTo('#accessTop',800);
			}
		
		});
			
	}
 	
 	if (jQuery(".idc-trackbacks h3").length != 0) {
		
		jQuery(".idc-trackbacks h3").html("Andaram falando desse artigo em:");
		
	}
	
	if (jQuery(".idc-head h3").length != 0) {
		
		jQuery(".idc-head h3").html("Veja o que já comentaram até agora:");
		
	}
	
	if (jQuery(".youtube").length != 0) {
		
		var obj = jQuery(".youtube object");
		
		obj.css("width","100%");
		
		var t = setTimeout(function(){
		
			var height = ((obj.width()*1080)/1920) + 25;
		
			obj.css("height",height);
		
		},1000);
		
		
		
	}
	
	if (jQuery(".prezi-player").lenght != 0) {
		
		var obj1 = jQuery(".prezi-player");
		var obj2 = jQuery("#prezi_aeedibzpyotw");
		var obj3 = jQuery("#preziEmbed_aeedibzpyotw");
		var obj4 = jQuery("#prezi_uwkwqjepdzjr");
		var obj5 = jQuery("#preziEmbed_uwkwqjepdzjr");
		
		obj1.css("width","100%");
		obj2.css("width","100%");
		obj3.css("width","100%");
		obj4.css("width","100%");
		obj5.css("width","100%");
		
		var height1 = ((obj1.width()*490)/750);
		
		obj1.css("height",height1);
		obj2.css("height",height1);
		obj3.css("height",height1);
		obj4.css("height",height1);
		obj5.css("height",height1);
		
	}
 	
 }
