if (document.getElementById("science_feed")) {
     google.setOnLoadCallback(function() {
     	var feed = new google.feeds.Feed("https://science.pfizer.com/feed/");
     	feed.load(function(result) {
     		if (!result.error) {
     			var container = document.getElementById("science_feed");
     			container.removeChild(container.childNodes[0]);
     			var ul = document.createElement("ul");
     			for (var i = 0; i < result.feed.entries.length; i++) {
     				var entry = result.feed.entries[i];
     				var ahref = document.createElement("a");
     				ahref.setAttribute('href', entry.link);
     				ahref.setAttribute('target', '_blank');
     				var li = document.createElement("li");
     				ahref.appendChild(document.createTextNode(entry.title));
     				li.appendChild(ahref);
     				ul.appendChild(li);
     			}
    				container.appendChild(ul);
     		}
     	});
     });
}
if (document.getElementById("health_feed")) {
     google.setOnLoadCallback(function() {
     	var feed = new google.feeds.Feed("https://fellows.pfizer.com/?feed=rss2");
     	feed.load(function(result) {
     		if (!result.error) {
     			var container = document.getElementById("health_feed");
     			container.removeChild(container.childNodes[0]);
     			var ul = document.createElement("ul");
     			for (var i = 0; i < result.feed.entries.length; i++) {
     				var entry = result.feed.entries[i];
     				var ahref = document.createElement("a");
     				ahref.setAttribute('href', entry.link);
     				ahref.setAttribute('target', '_blank');
     				var li = document.createElement("li");
     				ahref.appendChild(document.createTextNode(entry.title));
     				li.appendChild(ahref);
     				ul.appendChild(li);
     			}
    				container.appendChild(ul);
     		}
     	});
     });
}

$(function() {	
	window.setTimeout(openAccordion, 1000);
	if ($('#apply_country option:selected').val()=='false') {
		$('#btn_applynow').find('a').attr('href','#').attr('target','_self').removeClass('enable');
	}
	function openAccordion() {
		var obj = $('#start');
		$('h3').toggleClass('iefix');
		obj.find('h3').toggleClass('op');
		$(obj).animate({
		     height: 200,
		     bottom: 0
		}, 200, function() {
		     $('.hidden', this).fadeIn();
		     $('.acc_on').removeClass('acc_on');
		     $(this).addClass('acc_on');
			$('h3').toggleClass('iefix');
		});
	}
	$('.accordion h3').click(function() {
		if ($(this).parent().hasClass('acc_on')) {
			$(this).parent().removeClass('acc_on');
			$(this).toggleClass('op');
			$(this).parent().animate({
				height: 48,
				bottom: 0
			}, 200, function() {
			$('.hidden').hide();
			});
		}
		else {
			$('.acc_on').animate({
				height: 48,
				bottom: 0
			}, 200, function() {
				$('h3', this).toggleClass('op');
				$('.acc_on .hidden').hide();
			});
			$(this).toggleClass('op');
			$(this).parent().animate({
				height: 200,
				bottom: 0
			}, 200, function() {
				$('.hidden', this).fadeIn();
				$('.acc_on').removeClass('acc_on');
				$(this).addClass('acc_on');
			});
		}
	});
	$('.accordion div').hover(function() {
		$('h3', this).toggleClass('active');
	});
	$('#search').find('input').focusin(function() {
		var str = $.trim($(this).val());
		if (str=='Site Search') {
			$(this).val('');
		}
	});
	$('#search').find('input').focusout(function() {
		var str = $.trim($(this).val());
		if (str=='') {
			$(this).val('Site Search');
		}
	});
	
	$('#top_nav .dd').hover(function() {
		$(this).toggleClass('hover');
	});
	$('#nav li').hover(function() {
		$(this).toggleClass('hover');
	});
	
	$('#lang').hover(function() {
		$(this).find('#lang_dd').toggle();
	});
	$('#local').hover(function() {
		$(this).find('#local_dd').toggle();
	});
	$('#lang ul li').click(function() {
		$(this).toggleClass('lang_sel');
		var lang_id = $(this).attr('id');
		var now = new Date();
		$.post('/ajax.php?lang='+lang_id, function(data) {
			if (data!=='false') {
				window.location=data;
			}
		});
	});
	
	$('.modal').click(function() {
		var id=$(this).attr('rel')
		if (id=='locations') {
			var locations_div = document.createElement('div');
			locations_div.setAttribute('id','locations');
			locations_div.setAttribute('class','hidden');
			var map_div = document.createElement('div');
			map_div.setAttribute('id','map');
			locations_div.appendChild(map_div);
			var main = document.getElementById('main');
			main.appendChild(locations_div);
			pf.init(lang);
			$('#'+id).modal({
				minWidth: 670,
				minHeight: 480
			});
		}
		else {
			$('#'+id).modal({
				maxWidth: 411,
				minHeight: 350
			});
		}
	});	$('#btn_sitemap').hover(function() {
		$(this).toggleClass('hov');
	});
	$('#btn_sitemap').click(function() {
		$('#sitemap_wrap').toggle('blind');
		$('#btn_sitemap').toggleClass('on');
	});
		
	$('#apply_country').change(function() {
		var url = $('option:selected',this).val();
		var apply_btn = $('#btn_applynow').find('a');
		if (url=='false') {
			apply_btn.attr('href','#').attr('target','_self').removeClass('enable');
			return false;
		}
		else {
			apply_btn.attr('href', url).attr('target','_blank').addClass('enable');
		}
	});
});

function dynamicAccordion() {
	$(function() {
		$('p:contains["&nbsp;"] + hr').each(function() {
			if($(this).length>0) {
				$(this).prev().remove();
			}
		});
		$('hr + p:contains["&nbsp;"]').each(function() {
			if($(this).length>0) {
				$(this).remove();
			}
		});
	     $('hr + h3').each(function() {
     		$(this).prev().nextUntil('hr').wrapAll('<div id="faq_accordion" class="accord">');
     	});
	     $('#faq_accordion h3').each(function() {
	     	//$(this).nextUntil('h2').wrapAll('<div>');
	     	$(this).nextUntil(':header').wrapAll('<div>');
	     });
     	$('hr').each(function() {
    			$(this).remove();
     	});
		$('.accord').each(function() {
			$(this).accordion({
				header: 'h3',
				autoHeight: false,
				active: false,
				collapsible: true,
				icons: { 'header': 'ui-icon-plus',
				'headerSelected': 'ui-icon-minus' }
			});
		});
	});
}
