jQuery(document).ready(function() { 

	var imageObj = jQuery(".latestImage");
	var fstImg = jQuery(imageObj[0]);
	var fstImgID = jQuery(fstImg).attr('id');
	var fstImgHTML = jQuery(fstImg).html();
	var fstNewsID = str_replace('newsImg','',fstImgID);
	
	var videoObj = jQuery(".latestVideo");
	var fstVideo = jQuery(videoObj[0]);
	var fstVideoID = jQuery(fstVideo).attr('id');
	var fstVideoHTML = jQuery(fstVideo).html();
	
	//var fstNewsID = str_replace('video','',fstVideoID);
	
	
	
	//activte 1st image	
	jQuery('#latest-news-content'+fstNewsID).addClass("news-latest-item-active");
	
	if(fstVideoHTML)
	jQuery('#latestImgVisible').html(fstVideoHTML);	
	else
	jQuery('#latestImgVisible').html(fstImgHTML);	
	
	if(jQuery('#generalSynod'+fstNewsID).html()) {
		jQuery('#generalSynodHome').html(jQuery('#generalSynod'+fstNewsID).html());
		jQuery('#generalSynodHome').css({ display: ""});		
	}
	
	
	//caption
	var captionObj = jQuery(".latestImageCaption");
	var fstCaption = jQuery(captionObj[0]);
	var fstCaptionID = jQuery(fstCaption).attr('id');
	var fstCaptionHTML = jQuery(fstCaption).html();
		
	if(fstCaptionHTML){
		/*jQuery('#generalSynodHome').html(fstCaptionHTML);
		jQuery('#generalSynodHome').css({ display: ""});*/
		
		jQuery('#imagecaptionHome').html(fstCaptionHTML);
		jQuery('#imagecaptionHome').css({ display: ""});
	}
	
	
		
	jQuery(".news-latest-item").mouseover( function() { 
		
		jQuery('.general_synod').css({ display: "none"});
		jQuery('.news-latest-item').removeClass("news-latest-item-active");
		jQuery(this).addClass("news-latest-item-active");
		
		
		//change image
		var currentNewsID = str_replace('latest-news-content','',jQuery(this).attr('id'));
		
		if(jQuery('#video'+currentNewsID).html())
		jQuery('#latestImgVisible').html(jQuery('#video'+currentNewsID).html());
		else
		jQuery('#latestImgVisible').html(jQuery('#newsImg'+currentNewsID).html());
		
		//change header
		var hObj = jQuery('#generalSynod'+currentNewsID).html();
		if(hObj){
			//alert(hObj);
			jQuery('#generalSynodHome').html(jQuery('#generalSynod'+currentNewsID).html());
			jQuery('#generalSynodHome').css({ display: ""});
			//jQuery('#generalSynod'+currentNewsID).css({ display: ""});
		}
		
		//change caption
		var hObj = jQuery('#latestImageCaption'+currentNewsID).html();
		if(hObj){
			//alert(hObj);
			jQuery('#imagecaptionHome').html(jQuery('#latestImageCaption'+currentNewsID).html());
			
			if(!jQuery('#video'+currentNewsID).html())
			jQuery('#imagecaptionHome').css({ display: ""});
			else{
				jQuery('#imagecaptionHome').css({ display: "none"});	
			}
		}
		

	});
	
	function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
	}

});