﻿$(document).ready(function(){
	
	

    $('.emergencyChecker a').fancybox({ 
    'type'          :   'iframe',
    'width'         :   '50%',
    'height'        :   '52%',
    'overlayOpacity': 0.7});
		

	/* initiate small banners caousel */
	if($(".show-arabic .jcarousel-skin-sml").size()>0){
		if($(".show-arabic .jcarousel-skin-sml li").size() >4) {
			$('.show-arabic .jcarousel-skin-sml').jcarousel({
				vertical:true,
				scroll:1,
				wrap: 'circular',
				auto: 12
			});
		}	
	}
	else {
		if($(".jcarousel-skin-sml li").size() >4) {
			$('.jcarousel-skin-sml').jcarousel({
				vertical:true,
				scroll:1,
				wrap: 'circular',
				auto: 12
			});
		}
	}
		
	/*Reverse Image Gallery in Arabic*/
	ul = $('.filmstrip'); 
	ul.children().each(function(i,li){ul.prepend(li)})
	ul = $('#photos'); 
	ul.children().each(function(i,li){ul.prepend(li)})

	/* print page */
	$(".icon-print").click(function(){
		//window.print();
		//return false;		
		window.open('/SitemapXML/printtemplate.htm');				   
	});
	
	/* ellipsis */
	if($(".ellipsis").size()>0){
		$(".ellipsis").autoEllipsis();
	}
	
	/* tooltip */
	if($(".tooltip-link").size()>0){
		$(".tooltip-link").tooltip({position:'bottom right',delay:0});
	}
	
	// Increase Font Size
	$(".icon-font-inc").click(function(){
		var currentFontSize = $('body').css('font-size');
		if (parseInt(currentFontSize)<15){
			var newFontSize = (parseInt(currentFontSize)+1)+"px";
			$('body').css('font-size', newFontSize);
		}
		return false;
	});
	
	// Decrease Font Size
	$(".icon-font-dec").click(function(){
		var currentFontSize = $('body').css('font-size');
		if (parseInt(currentFontSize)>10){
			var newFontSize = (parseInt(currentFontSize)-1)+"px";
			$('body').css('font-size', newFontSize);
		}
		return false;
	});
	
	/* dropdown main menu */
	if($(".mainMenu").size()>0){
		$('.mainMenu ul:first ul:first').ptMenu();
		$('.mainMenu ul.mohdd-menu ul.mohdd-menu-group').each(function(){
			var cur_count = $(this).find("> li").size();
			if(cur_count>5 && cur_count<=10){
				$(this).css('width','340px');
				$(this).find("> li:nth-child(2n)").after('<li class="clear"></li>');
			}
			if(cur_count>10 && cur_count<=15){
				$(this).css('width','510px');
				$(this).find("> li:nth-child(3n)").after('<li class="clear"></li>');
			}
		});
	}
	
	/* set selected item in sub menu */
	$("ul.mohdd-menu ul.mohdd-menu-group li.selected").each(function(){
		$(this).parents("li:first").find("a:first").addClass("selected");
	});
	
	
	// replace the search dropdown with radio buttons 
	if ($(".show-arabic .ms-sbscopes option").size()>0){
		//$(".search").append('<div class="search-radio">Search in: </div>');
		var i=0;
		var cur_value;
		$(".show-arabic .ms-sbscopes option").each(function(){
			cur_value = $(this).text();
			if ($(this).attr("selected"))
				$(".search-radio").append('<label><input type="radio" checked="checked" name="search_radio" value="radio" id="search_radio_'+i+'" onclick=\'$(".show-arabic .ms-sbscopes option").removeAttr("selected");$(".show-arabic .ms-sbscopes").attr("selectedIndex", '+i+');\'/>'+cur_value+'</label>');
			else
				$(".search-radio").append('<label><input type="radio" name="search_radio" value="radio" id="search_radio_'+i+'" onclick=\'$(".show-arabic .ms-sbscopes option").removeAttr("selected");$(".show-arabic .ms-sbscopes").attr("selectedIndex", '+i+');\'/>'+cur_value+'</label>');
			i+=1;
		});
		//$(".show-arabic .ms-sbscopes").hide(); 
	}
	
	// change page title 
	var text = document.title;
	text = text.replace("الصفحات", " ");
	document.title = text;

	document.title = '  وزارة الصحة - الإمارات العربية المتحدة ' + document.title;
	current_doc_title = document.title ;

	//add classes to ids 
	$("div [id$='filterDiv']").addClass("filterDiv");
	$("input:button, input:submit").addClass("button");
	$("input:text").addClass("input-text");

	// find us gancybox
	if($(".fancybox-img").size()>0) {
		$("a.fancybox-img").fancybox({
			'centerOnScroll':true, 
			'hideOnOverlayClick':false, 
			'overlayOpacity':0.8,
			'overlayColor':'#000',
			'titleShow':false,
			'width':520,
			'height':550,
			'titlePosition':'over',
			'type':'iframe'	
			

		});
		
		

	}
	
	// prayers fancybox
	if($(".fancybox-inline").size()>0) {
		$("a.fancybox-inline").fancybox({
			'centerOnScroll':true, 
			'hideOnOverlayClick':false, 
			'overlayOpacity':0.8,
			'overlayColor':'#000',
			'titleShow':false
		});
	}
	
	$(".icon-prayer").click(function(){
		$(".tooltip-weather").hide();
		$(".tooltip-prayers").toggle();
	});
	
	$(".icon-weather").click(function(){
		$(".tooltip-prayers").hide();
		$(".tooltip-weather").toggle();
	});

	
	// hide find-us 
	if($(".find-us").size()>0) {
		$(".find-us .img img").each(function(){
			if($(this).attr("src") == "")
				$(this).parent().hide();
			if($(this).attr("src") == "/Style%20Library/en-us/moh/images/backgrounds/blank.gif")
				$(this).parent().hide();
		});
	} 

	// resize the content image
	//$(".wp-content-editor .img img").css("width","auto"); 
	/*if ($(".wp-content-editor .img img").width()>300)
		$(".wp-content-editor .img img").width(300);
	else
		$(".wp-content-editor .img img").width(100);*/

	// apply onchange on jump menu 
	$(".quickLinksContainer select").change(function() {
	  window.location.replace(this.options[this.selectedIndex].value);
	});
	//$(".quickLinksContainer select").attr("onchange","window.location.replace(this.options[this.selectedIndex].value)")

		// check the highlights + news + services
	var href = $(location).attr('href');
	if (window.location.href.indexOf("/Highlights/Pages/") != -1)
		$(".ms-WPBody").addClass("highlight-listing");
		$(".highlight-listing img[src*='default_image_news.jpg']").attr('src','/Style%20Library/en-us/moh/images/content/default_image_highlights.jpg');
	
	if (window.location.href.indexOf("/Eservices/Pages/") != -1){
		$(".ms-WPBody").addClass("eservices-listing");
		$(".eservices-listing img[src*='default_image_news.jpg']").attr('src','/Style%20Library/en-us/moh/images/content/default_image_services.jpg');
	}
	if (window.location.href.indexOf("/News/Pages/") != -1)
		$(".ms-WPBody").addClass("news-listing");

	// remove title for text links in the header 
	$(".link-txt").removeAttr("title");
	$(".lang-switch td").removeAttr("title");
	
		// admin tooltip adjustment 
	if ($("#s4-ribbonrow").is(":visible")){
		$("body").addClass("admin");
	}	
	
	// events remove all link 
	if ($("#events_carousel li").size()>0){
		$(".wp-events .ViewALL-Margin").hide();
	}
	
	// menu sep remove 
	$(".mainMenu ul ul li:first > a").css("background","none");
	
        //Sitemap Toggle
	$('.toggle-sitemap').click(function(){
		$(this).parent('li').find('ul').toggle();
		$(this).find('img').attr('src').indexOf('open') > 0 ? $(this).find('img').attr('src','/_layouts/images/ISPK Images/SiteMapWebPart/node-closed.gif'):$(this).find('img').attr('src','/_layouts/images/ISPK Images/SiteMapWebPart/node-open.gif');					   
	});
	
	
});

// ------------------------------------------------------ Functions ----------------------------
function process_special(txt) {
	return txt.replace(/&amp;/g, "&");//.replace(/&gt;/g, ">").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, "/"");
}
	

	
	
// get object by ID for drag panel 
function getObject(id) {
	if(document.getElementById) {
		obj = document.getElementById(id);
	}
	else if(document.all) {
		obj = document.all.item(id);
	}
	else {
		obj = null;
	}
	return obj;
}
// drag panel function
function loadDragElements() {
	var theHandle = getObject("MSOTlPn_ToolPaneCaption");
	var theRoot = getObject("MSOTlPn_Tbl");
	if(theHandle != null && theRoot != null) {
		Drag.init(theHandle, theRoot);
	}
}
// news slider callback function
function featured_carousel_initCallback(carousel) {
	$('.current_tab_holder').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});
}

// map icons click 
function icon_click(id){
	if (id == 1)
               Openlightbox(0,"/_layouts/adam/Symptom Checker/44/000001.htm","Symptoms Checker",800,600,100); 
        if (id == 2)
               Openlightbox(1,"/_layouts/adam/Care Guides/200000.htm","Health Guide",800,600,100);
        if (id == 3)
               Openlightbox(2,"/_layouts/adam/HealthTips/HealthTips.htm","Health Tips",800,600,100); 
        if (id == 4)
               Openlightbox(3,"/_layouts/adam/Wellness Tools/200000.htm","Health Tools",800,600,100); 
        if (id == 6)
               Openlightbox(4,"/_layouts/adam/pregnancy center/14/000002.htm","Pregnancy center",800,600,100); 
        if (id == 5)                   
               Openlightbox(5,"/_layouts/adam/Complementary and Alternative Medicine/200000.htm","Alternative medicine",800,600,100); 
} 

// open lightbox 
function DialogCallback(dialogResult, returnValue) {
	//meesageId = SP.UI.Notify.addNotification(returnValue, false);
}

function Openlightbox(id,myUrl,title,width,height,y) {
	
	// Calling fancybox 
	if ($("a#fancybox_link_"+id).size()==0){
		$("body").append('<a href="'+myUrl+'" class="hidden" id="fancybox_link_'+id+'"></a>');
		$("a#fancybox_link_"+id).fancybox({
			'width':width,
			'height':height,
			'centerOnScroll':true, 
			'hideOnOverlayClick':false, 
			'overlayOpacity':0.8,
			'titlePosition':'over',
			'type':'iframe',
			'href':myUrl,
			'overlayColor':'#000',
			'title':title,
			'titleShow':false
		});
	}
	$("a#fancybox_link_"+id).trigger('click'); 
	
	// Calling sharepoint lightbox
	//var options= {url:myUrl,width: width,height: height,title: title, allowMaximize: true, showClose: true /*dialogReturnValueCallback: DialogCallback*/};
	//SP.UI.ModalDialog.showModalDialog(options);
}

// fire after update panel load
function pageLoad(sender, args)
{
   if (args.get_isPartialLoad())
   {
       //add classes to ids 
		$("div [id$='filterDiv']").addClass("filterDiv");
		$("input:button, input:submit").addClass("button");
		$("input:text").addClass("input-text");
		document.title =current_doc_title;
		ReinitiateEvents();
		//SetTime();
   }
}

// faq 

$(function() {
$('.faq-question').toggle(
        function() {
            //show answer
            $(this).siblings('.faq-answer').show();
            $(this).find('.col-exp').attr('src', '/_layouts/ContentDisplayWebParts/ExpandCollapse/Images/collapse_icon.png');
            $(this).find('.col-exp').attr('alt', 'collapse');
        },
        function() {
            //hide answer
            $(this).siblings('.faq-answer').hide();
            $(this).find('.col-exp').attr('src', '/_layouts/ContentDisplayWebParts/ExpandCollapse/Images/expand_icon.png');
            $(this).find('.col-exp').attr('alt', 'expand');
        })
}) 
$(
    function () {
        var imageFolder = '/Style%20Library/ar-sa/moh/images/sitemap/';
         $('img.ImgClick').click(
            function () {
                if ($(this).attr('src').search("plus.gif") != -1)
                    $(this).attr('src', imageFolder + "minus.gif");
                else
                    $(this).attr('src', imageFolder + "plus.gif");
                $(this).parent().next("ul.SideSiteMap").slideToggle();
            }
        );    }
);

function ReinitiateEvents()
{
	/* initiate events caousel */
	if($(".jcarousel-skin-events li").size() >2) {
		$('.jcarousel-skin-events').jcarousel({
			vertical:true,
			scroll:2
		});
	}
}

