/* Document Ready
----------------------------------------------------------------------*/
$(document).ready(
	function()
	{
		// Toggles block visibility when clicking on head
		try{
		    $('div.head').click(function()
			    {
				    //toggle visibility
				    $(this).next('div').toggle();
    				
				    //toggle no-print class
				    if ($(this).parent('div').attr('class').indexOf("no-print")==-1){
			            $(this).parent('div').addClass('no-print');
		            } else {
		                $(this).parent('div').removeClass('no-print');
		            }
				    return false;
			    }
		    );
        }
        catch(e) {}
        
        // Hide All elements with hideonload class
        try{
            $('.hideonload').css('display', 'none');}
        catch(e) {}
        
        // Append Host Family or Au Pair Number to "contact us" link
        try{
            $(".contactUsForm").attr("href", $(".contactUsForm").attr("href") + $.cookie("HFNumber"));}
        catch(e) {}
		
		// InfoSource Functions
		if (location.hostname.toString().indexOf("infosource") != -1){
			outLinks();
			hideComments();
			hideRelatedDocuments();
		}
		
		//Inserts a filetype icon after each .doc, .pdf etc. file
        $("a[href$='.pdf'], a[href$='.PDF']").not(':has(img)').addClass("docTypeIcon pdf");
        $("a[href$='.doc'], a[href$='.DOC']").not(':has(img)').addClass("docTypeIcon doc");
        $("a[href$='.ppt'], a[href$='.PPT']").not(':has(img)').addClass("docTypeIcon ppt");
        $("a[href$='.xls'], a[href$='.XLS']").not(':has(img)').addClass("docTypeIcon xls");
        $("a[href$='.zip'], a[href$='.ZIP']").not(':has(img)').addClass("docTypeIcon zip");
        $("a[href^='mailto:'], a[href^='MAILTO:']").not(':has(img)').addClass("docTypeIcon mailto");
        $("a[href$='.gif'], a[href$='.GIF'], a[href$='.jpg'], a[href$='.JPG'], a[href$='.jpeg'], a[href$='.JPEG'], a[href$='.png'], a[href$='.PNG'], a[href$='.bmp'], a[href$='.BMP']").not(':has(img)').addClass("docTypeIcon image");
        
	}
);

/* Hide InfoSource "Related Documents" box if its empty
----------------------------------------------------------------------*/
function hideRelatedDocuments(){
try{
	if ($.trim($("#related-docs-items").text()) == ''){
        $("#related-documents").hide();
    }
}
catch(e) {}
}

/* Hide InfoSource comments at page load 
----------------------------------------------------------------------*/
function hideComments(){
    try{
        
        //only hide the comments if anchor in url does not contain "comment-" (permalink)
        var str = location.hash.toString();
        var position = str.indexOf("comment-")
    
        if (position == -1) $("#comments").hide();
    }
    catch(e) {}
}

/* Open all external links in a new window
----------------------------------------------------------------------*/
var siteURL1 = "culturalcare.com";
function outLinks() {
  var outLink;
  if ($('a')) {
    for (var i = 0; (outLink = $('a')[i]); i++) {
      if (outLink.href.indexOf(siteURL1) != -1) {
        //internal link, don't open in a new window
      }
      else {outLink.setAttribute('target', '_blank');}
    }
  }
}

/* Set/remove value of text field
----------------------------------------------------------------------*/
function clearInput(obj, text, eventType) {

    if (eventType == 'blur') {
        if (obj.value=='') {obj.value=text; return false;}
    }
    else if (eventType == 'focus') {
        if (obj.value==text) {obj.value=''; return false;}
    }
    
    return false;
}

/* Add fadeToggle() to all jQuery elements
----------------------------------------------------------------------*/	
try{
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({ opacity: 'toggle' }, speed, easing, callback);
	}; 
}
catch(ex){}

/* Debug bar helper function
----------------------------------------------------------------------*/	
function showDebugInfo(html){
	if($('#debug-info').css('display') == 'none') 
		$('#debug-info').fadeToggle();
	$('#debug-info').html(html);
}
