$(document).ready(function() {
	$("#tabs").tabs();
	$(document).pngFix(); 
	$('a.lightbox').lightBox({
        imageLoading: 'http://www.umc.org/atf/cf/%7Bdb6a45e4-c446-4248-82c8-e131b6424741%7D/lightbox-ico-loading.gif',
        imageBtnClose: 'http://www.umc.org/atf/cf/%7Bdb6a45e4-c446-4248-82c8-e131b6424741%7D/LIGHTBOX-BTN-CLOSE.GIF',
        imageBtnPrev: 'http://www.umc.org/atf/cf/%7Bdb6a45e4-c446-4248-82c8-e131b6424741%7D/lightbox-btn-prev.GIF',
        imageBtnNext: 'http://www.umc.org/atf/cf/%7Bdb6a45e4-c446-4248-82c8-e131b6424741%7D/lightbox-btn-next.GIF',
        imageBlank: 'http://www.umc.org/atf/cf/%7Bdb6a45e4-c446-4248-82c8-e131b6424741%7D/lightbox-blank.GIF'
    });
	$('.secondTab').click(function() {
		var myTabs = $("#tabs").tabs();
		var childNumber = $("ul.ui-tabs-nav").children().size();
		childNumber = childNumber - 3;
		myTabs.tabs('select', childNumber);
	});
	$('.fourthTab').click(function() {
		var myTabs = $("#tabs").tabs();
		var childNumber = $("ul.ui-tabs-nav").children().size();
		childNumber = childNumber - 1;
		myTabs.tabs('select', childNumber);
	});
	$('input[name=embed_code]').focus(function(){
		$(this).select();
	});
	$('textarea[name=embed_code]').focus(function(){
		$(this).select();
	});
	$('.tweetThisBox p').click(function(){
		var statUpdate = $(this).text();
		url = 'http://twitter.com/home?status='+encodeURIComponent(statUpdate);
		window.open(url,'titterWindow','height=650,width=1024,scrollbars=1');
	});


/* Imagine No Malaria: Feature  */
	function xmlPull(){
		var parent=this;
		this.grabRSS=function(rssLocation,blockType){
			parent.maxItems=jQuery(rssLocation).attr('count');
			parent.skipItems=jQuery(rssLocation).attr('skip');	
			parent.blockType=blockType;
			parent.rssLocation=rssLocation;
			var rss = jQuery(rssLocation).attr('rss');
			jQuery.ajax({
				type:"GET",
				url:rss,
				dataType:"xml",
					success: function(data){
							jQuery(data).find('item').each(function(i){
									var $item=jQuery(this);
									storyObject={                   
										title:$item.find('title').text(),
										description:$item.find('description').text(),
										articleLink:$item.find('link').text(),
										pubDate:$item.find('pubDate').text(),
										imageThumb:$item.find('[nodeName=k:feature_image]').text(),
										shortTitle:$item.find('[nodeName=k:shortTitle]').text(),
										target:$item.find('[nodeName=k:go_to_article_now_external]').text(),
										externalLink2:$item.find('[nodeName=k:go_to_article_now_url_external]').text(),
										externalLink:$item.find('[nodeName=k:go_to_article_now]').text(),
										link1Href:$item.find('[nodeName=k:extra_link1_href]').text(),
										link1Name:$item.find('[nodeName=k:extra_link1_name]').text(),
										link2Href:$item.find('[nodeName=k:extra_link2_href]').text(),
										link2Name:$item.find('[nodeName=k:extra_link2_name]').text(),
										homeFeature:$item.find('[nodeName=k:home_feature]').text(),
										homeSubFeature:$item.find('[nodeName=k:home_subfeature]').text(),
										homeFeatureLink:$item.find('[nodeName=k:home_feature_link]').text(),
										videoId:$item.find('[nodeName=k:video]').text(),
										blogImage:$item.find('[nodeName=k:blog_image]').text(),
										readMore:$item.find('[nodeName=k:read_more]').text(),
										customSummary:$item.find('[nodeName=k:custom_home_summary]').text(),
										windowsMediaVideo:$item.find('[nodeName=k:windows_media]').text(),
										quickTimeVideo:$item.find('[nodeName=k:quick_time]').text()
												   }
									if(storyObject.externalLink==""){storyObject.externalLink=storyObject.articleLink}
									if(i==parent.maxItems){return false;}
									if(i==0){jQuery(parent.rssLocation+" .loader").remove();}
									switch(parent.blockType)
									{
									case "featureCycle":
									parent.createCycleStory(storyObject,i,parent.rssLocation,parent.maxItems);
									break;
									case "relatedHeads":
									if(i > parent.skipItems) {
										parent.createListing(storyObject,i,parent.rssLocation,parent.maxItems);
									}
									break;
									}
							});           
				}
			});
	}
	this.createCycleStory=function(storyObj,i,divLocation,maxItems){
		jQuery(divLocation).append('<div id="feature'+i+'" class="featureSlide"><div class="featureTextBlock"><div class="featureTitle">'+storyObj.title+'</div><div class="featureSummary">'+storyObj.description+'</div><div class="fullStory"><a  target="'+storyObj.target+'" href="'+storyObj.externalLink+'">Full Story</a></div></div><div class="featureImage"><img src="'+storyObj.homeFeature+'" width="420" height="262"/></div></div>');
		jQuery("#navHaiti").append('<div><a href="#">'+storyObj.title+'</a></div>');
		if(i==maxItems-1){jQuery(divLocation).cycle({fx: 'scrollDown',timeout:20000,pager:'#navHaiti',pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#navHaiti div:eq(' + idx + ') a'; 
    } });}
	}
	
		this.createListing=function(storyObj,i,divLocation,maxItems){
		jQuery(divLocation).append('<ul id="icl_container"><li class="icl_title"><a target="'+storyObj.target+'" href="'+storyObj.externalLink+'">'+storyObj.title+'</a></li></ul>');
		
	}
}	
	//load items if they exist on the page
	if(jQuery("#featureCycle").length){
		jQuery.getScript('http://www.kintera.org/atf/cf/{a261c5b5-6810-4eef-962f-f5aa4aa5d22c}/JQUERY.CYCLE.ALL.JS',function(){
			jQuery("#featureCycle").after('<div id="navHaiti"></div>');
			var featureCycle=new xmlPull();
			featureCycle.grabRSS("#featureCycle","featureCycle");			
		});
	}
	if(jQuery("#relatedHeadlineAuto").length){
		var listing=new xmlPull();
		listing.grabRSS("#relatedHeadlineAuto","relatedHeads");
	}
	
});

/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.2, 09.03.2009
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    09.03.2009 Version 1.2
 *    - Update for jQuery 1.3.x, removed @ from selectors
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);