/* All BMJ Group custom jQuery functions should be added here */

var $jQuery = jQuery.noConflict();	/* Remove Javascript libary conflicts between Prototype and jQuery */


$jQuery(function() {  /* A jQuery Google Analytics extensions which adds support for outbound links, mailto and downloads */

$jQuery('a').click(function() {

  var $a = $jQuery(this);
  var href = $a.attr('href');

  if(href.match(/^\/cgi\/powerpoint/)) { /* HighWire specific to track powerpoint downloads */
      href = href+".ppt";
  }

  var hrefArray = href.split('.');
  var extension = hrefArray[hrefArray.length - 1];

  var fileTypes = ['doc','zip','xls','ppt','xml','pdf','mp3'];

  // see if the link is external
  if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {

    // if so, register an event
    var category = 'outgoing'; // set this to whatever you want
    var event = 'click'; // set this to whatever you want
    var label = href; // set this to whatever you want
    pageTracker._trackEvent(category, event, href);
  }

  // see if the link is mailto
  if ( href.match(/^mailto/) ) {

    // if so, register an event
    var category = 'mailto'; // set this to whatever you want
    var event = 'click'; // set this to whatever you want
    var label = href; // set this to whatever you want
    pageTracker._trackEvent(category, event, href);
  }

  // for type downloads
  if ($jQuery.inArray(extension,fileTypes) != -1) {

      pageTracker._trackEvent('download', extension, href);
  }

});

})



/* A function which populates a search form-field with a default text for thehe Group and local site search (Added by D. Berhane) */
/* The first parameter is a selector (for BMJ Group search, it is "#groupSearchGadget" ), the second parameter is the default value of that input element (e.g. " Search all BMJ Products"). */


function populateElement(selector, defvalue) {
    if($jQuery.trim($jQuery(selector).val()) == "") {
        $jQuery(selector).val(defvalue);
    }
  
    $jQuery(selector).focus(function() {
        if($jQuery(selector).val() == defvalue) {
            $jQuery(selector).val("");
        }
    });
    
    $jQuery(selector).blur(function() {
        if($jQuery.trim(jQuery(selector).val()) == "") {
            $jQuery(selector).val(defvalue);
        }
    });
 };

 
/* A function which open a pop-up window for OOP registration when the there is a refrence 'rel="external" with the A tag'  */

function popUp() {

    $jQuery('A[rel="external"]').click( function() {
        window.open( $jQuery(this).attr('href'),'', 'status=yes,scrollbars=yes,resizable=yes,width=700,height=550' );
        return false;
    });

}
   

/* A function to deploy cross domain widgets */
function widget(options) 
{
	/* Define all default widget parameters */
    var default_args = {
        'url': "http://www.bmj.com/rss/recent.xml",
        'section': "none",
        'source': "no",
        'category': "all",
        'track': "widget_bmjblogs",
        'title': "Latest from BMJ",
        'subject': "all",
        'style': "bmj",
        'widget': "feeds-widget1",
        'jurl': "http://group.bmj.com/feed2json/index.php", /* default JSON feed URL */
        'target': "_self",
        'num_items': "5"
    }

this.default_args = default_args;

this.options = options;

	/* If a user does not define any of the widget parameters, use the default define above */
	for(var index in this.default_args) {

		if(typeof this.options[index] == "undefined") this.options[index] = this.default_args[index];

	}	
	
   $jQuery.ajax({
        url: this.options['jurl'],
        data: "url=" + this.options['url'] + "&widget_title=" + this.options['widget_title'] + "&style=" + this.options['style'] + "&source=" + this.options['source'] + "&track=" + this.options['track'] + "&target=" + this.options['target'] + "&num_items=" + this.options['num_items'] + "&section=" + this.options['section'] + "&enclink=" + this.options['enclink'] + "&enclength=" + this.options['enclength'] + "&encltype=" + this.options['encltype'] + "&widget=" + this.options['widget'] + "&callback=bmjcallback1",
        cache: true,
        dataType: "script",
        success: bmjcallback1 = function(data){
		
		
			if (data) {
			
			
				$jQuery('div#' + data.feedhead[0].widget).empty(); /* Replace the default widget Markup done for SEO */
				$jQuery('div#' + data.feedhead[0].widget).append('<h2>' + data.feedhead[0].widget_title + '</h2>');
				
				/* BMJ Group XHTML markup for styling the feed content */
				
				$jQuery('div#' + data.feedhead[0].widget).addClass(data.feedhead[0].style);
				$jQuery('div#' + data.feedhead[0].widget).append('<ul class="StandardBullet">');
				
				
				$jQuery.each(data.items, function(i, item){
				
					feed_html = '<li class="rss-item">';
					
					if (item.source == "no") {
					
						if (item.section.length > 0) {
							feed_html += ' ' + '<span class="sect1">' + item.section + ':' + '</span>' + ' ';
						}
					}
					else {
						if (item.source.length > 0) {
							feed_html += ' ' + '<span class="sect1">' + item.source + ':' + '</span>' + ' ';
						}
					}
					
					feed_html += ' ' + '<span class="title1"><a href="' + item.link + '" target="' + data.feedhead[0].target + '">' + item.title + '<\/a>' + '</span>' + ' ';
					
					if (item.date) {
						feed_html += '<span class="date">' + "(" + item.date + ")" + '</span>';
					}
					
					if (item.encltype == "audio/mpeg") {
						feed_html += '<br/><object type="application/x-shockwave-flash" data="http://group.bmj.com/media/player/player.swf" id="audioplayer1" height="24" width="140"><param name="movie" value="http://group.bmj.com/media/player/player.swf"><param name="FlashVars" value="playerID=1&amp;leftbg=0x006990&amp;lefticon=0xffffff&amp;rightbg=0x006990&amp;rightbghover=0xFF00FF&amp;righticon=0x0ffffff&amp;righticonhover=0xcccccc&amp;text=0x006990&amp;slider=0x006990&amp;border=0x006990&amp;loop=no&amp; autostart=no&amp;soundFile=' + item.enclink + '"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"></object>';
					}
					
					
					feed_html += '</li>';
					
					$jQuery('div#' + data.feedhead[0].widget + ' ul').append(feed_html);
					
				});
				
			}
		}	        
        }); 
 }  



/* A function to deploy cross domain widgets */
function topic_widget(options){
    /* Define all default widget parameters */
    var default_args = {
    	'url': "http://www.bmj.com/rss/recent.xml",
        'section': "none",
        'source': "no",
        'category': "all",
        'track': "widget_bmjblogs",
        'title': "Latest from BMJ",
        'subject': "all",
        'style': "bmj",
        'widget': "feeds-widget1",
        'jurl': "http://group.bmj.com/feed2json/index.php", /* default JSON feed URL */
        'target': "_self",
        'num_items': "5"
    }
    this.default_args = default_args;
    
    var feedurl = 'http://www.bmj.com/rss/recent.xml';
    var feedtitle = 'Latest from BMJ';
    
    var bmjfeed1 = {
        "Pain (anaesthesia)": "/collections/rss/collrss_4.xml",
        "Other Anesthesia": "/collections/rss/collrss_5.xml",
        "Arrhythmias": "/collections/rss/collrss_8.xml",
        "Cardiomyopathy": "/collections/rss/collrss_13.xml",
        "Congenital heart disease": "/collections/rss/collrss_18.xml",
        "Drugs: cardiovascular system": "/collections/rss/collrss_19.xml",
        "Echocardiography": "/collections/rss/collrss_20.xml",
        "Heart failure": "/collections/rss/collrss_21.xml",
        "Hypertension": "/collections/rss/collrss_25.xml",
        "Interventional cardiology": "/collections/rss/collrss_30.xml",
        "Ischaemic heart disease": "/collections/rss/collrss_31.xml",
        "Pacing and electrophysiology": "/collections/rss/collrss_36.xml",
        "Valvar diseases": "/collections/rss/collrss_37.xml",
        "Venous thromboembolism": "/collections/rss/collrss_38.xml",
        "Other Cardiovascular Medicine": "/collections/rss/collrss_151.xml",
        "Complementary medicine": "/collections/rss/collrss_47.xml",
        "Dentistry and oral medicine": "/collections/rss/collrss_55.xml",
        "Adult intensive care": "/collections/rss/collrss_50.xml",
        "Mechanical ventilation": "/collections/rss/collrss_51.xml",
        "Neonatal": "/collections/rss/collrss_52.xml",
        "Paediatric": "/collections/rss/collrss_53.xml",
        "Dentistry and Oral Medicine": "/collections/rss/collrss_55.xml",
        "Dermatology": "/collections/rss/collrss_57.xml",
        "Non-therapeutic": "/collections/rss/collrss_7.xml",
        "Pharmacology and toxicology": "/collections/rss/collrss_185.xml",
        "Regulation": "/collections/rss/collrss_186.xml",
        "Emergency Medicine": "/collections/rss/collrss_2.xml",
        "Diabetes": "/collections/rss/collrss_24.xml",
        "Pain returns": "/collections/rss/collrss_1006.xml",
        "Other Endocrinology": "/collections/rss/collrss_152.xml",
        "Drugs: endocrine system": "/collections/rss/collrss_187.xml",
        "Guidelines": "/collections/rss/collrss_189.xml",
        "Changing physician behavior": "/collections/rss/collrss_190.xml",
        "Clinical diagnostic tests": "/collections/rss/collrss_61.xml",
        "Radiology (diagnostics)": "/collections/rss/collrss_62.xml",
        "Surgical diagnostic tests": "/collections/rss/collrss_60.xml",
        "Ear, nose and throat / otolaryngology": "/collections/rss/collrss_64.xml",
        "Poisoning": "/collections/rss/collrss_67.xml",
        "Resuscitation": "/collections/rss/collrss_70.xml",
        "Trauma": "/collections/rss/collrss_71.xml",
        "Adrenal disorders": "/collections/rss/collrss_75.xml",
        "Calcium and bone": "/collections/rss/collrss_76.xml",
        "Diabetes": "/collections/rss/collrss_77.xml",
        "Drugs: endocrine system": "/collections/rss/collrss_78.xml",
        "Lipid disorders": "/collections/rss/collrss_79.xml",
        "Metabolic disorders": "/collections/rss/collrss_80.xml",
        "Pituitary disorders": "/collections/rss/collrss_81.xml",
        "Thyroid disease": "/collections/rss/collrss_82.xml",
        "Changing physician behaviour": "/collections/rss/collrss_86.xml",
        "Guidelines ": "/collections/rss/collrss_94.xml",
        "Cancer - see Oncology": "/collections/rss/collrss_100.xml",
        "Drugs: gastrointestinal system": "/collections/rss/collrss_101.xml",
        "Endoscopy": "/collections/rss/collrss_102.xml",
        "GI bleeding": "/collections/rss/collrss_103.xml",
        "Infection (gastroenterology)": "/collections/rss/collrss_109.xml",
        "Inflammatory bowel disease": "/collections/rss/collrss_117.xml",
        "Liver disease": "/collections/rss/collrss_122.xml",
        "Oesophagus": "/collections/rss/collrss_141.xml",
        "Pancreas and biliary tract": "/collections/rss/collrss_1328.xml",
        "Pancreatitis": "/collections/rss/collrss_147.xml",
        "Portal hypertension": "/collections/rss/collrss_148.xml",
        "Small intestine": "/collections/rss/collrss_149.xml",
        "Stomach and duodenum": "/collections/rss/collrss_154.xml",
        "General practice / family medicine": "/collections/rss/collrss_157.xml",
        "Clinical genetics": "/collections/rss/collrss_162.xml",
        "Cytogenetics": "/collections/rss/collrss_163.xml",
        "Genetic screening/counselling": "/collections/rss/collrss_164.xml",
        "Molecular genetics": "/collections/rss/collrss_165.xml",
        "Elder abuse": "/collections/rss/collrss_168.xml",
        "End of life decisions (geriatric medicine)": "/collections/rss/collrss_169.xml",
        "Long term care": "/collections/rss/collrss_170.xml",
        "Psychogeriatrics": "/collections/rss/collrss_171.xml",
        "Haematology (incl blood transfusion)": "/collections/rss/collrss_175.xml",
        "Immunology (including allergy)": "/collections/rss/collrss_177.xml",
        "Infectious diseases": "/collections/rss/collrss_1330.xml",
        "Adult intensive care": "/collections/rss/collrss_50.xml",
        "Mechanical ventilation": "/collections/rss/collrss_51.xml",
        "Neonatal intensive care": "/collections/rss/collrss_52.xml",
        "Paediatric intensive care": "/collections/rss/collrss_53.xml",
        "Brain stem/cerebellum": "/collections/rss/collrss_203.xml",
        "Cerebral palsy": "/collections/rss/collrss_1491.xml",
        "Coma and raised intracranial pressure": "/collections/rss/collrss_.xml",
        "Cranial nerves": "/collections/rss/collrss_206.xml",
        "Drugs: CNS (not psychiatric)": "/collections/rss/collrss_208.xml",
        "Epilepsy and seizures": "/collections/rss/collrss_209.xml",
        "Headache (including migraine)": "/collections/rss/collrss_210.xml",
        "Hydrocephalus": "/collections/rss/collrss_211.xml",
        "Infection (neurology)": "/collections/rss/collrss_212.xml",
        "Memory disorders (neurology)": "/collections/rss/collrss_207.xml",
        "Motor neurone disease": "/collections/rss/collrss_213.xml",
        "Movement disorders (other than Parkinsons)": "/collections/rss/collrss_214.xml",
        "Multiple sclerosis": "/collections/rss/collrss_215.xml",
        "Muscle disease": "/collections/rss/collrss_216.xml",
        "Neuroimaging": "/collections/rss/collrss_220.xml",
        "Neurological injury": "/collections/rss/collrss_222.xml",
        "Neuromuscular disease": "/collections/rss/collrss_223.xml",
        "Neurooncology": "/collections/rss/collrss_224.xml",
        "Pain (neurology)": "/collections/rss/collrss_227.xml",
        "Parkinson's disease": "/collections/rss/collrss_228.xml",
        "Peripheral nerve disease": "/collections/rss/collrss_229.xml",
        "Sleep disorders (neurology)": "/collections/rss/collrss_230.xml",
        "Spinal cord": "/collections/rss/collrss_231.xml",
        "Trauma CNS / PNS": "/collections/rss/collrss_233.xml",
        "Variant Creutzfeld-Jakob Disease": "/collections/rss/collrss_234.xml",
        "Childhood nutrition": "/collections/rss/collrss_257.xml",
        "Diet": "/collections/rss/collrss_258.xml",
        "Malnutrition": "/collections/rss/collrss_259.xml",
        "Obesity (nutrition)": "/collections/rss/collrss_260.xml",
        "Vitamins and supplements": "/collections/rss/collrss_262.xml",
        "Abortion": "/collections/rss/collrss_266.xml",
        "Cancer - see Oncology": "/collections/rss/collrss_267.xml",
        "Cervical cancer": "/collections/rss/collrss_268.xml",
        "Cervical screening": "/collections/rss/collrss_269.xml",
        "Contraception": "/collections/rss/collrss_270.xml",
        "Domestic violence": "/collections/rss/collrss_271.xml",
        "Drugs: obstetrics and gynaecology": "/collections/rss/collrss_272.xml",
        "Family planning": "/collections/rss/collrss_273.xml",
        "Incontinence": "/collections/rss/collrss_274.xml",
        "Menopause (including HRT)": "/collections/rss/collrss_275.xml",
        "Pregnancy": "/collections/rss/collrss_276.xml",
        "Reproductive medicine": "/collections/rss/collrss_277.xml",
        "Breast cancer": "/collections/rss/collrss_282.xml",
        "Chemotherapy": "/collections/rss/collrss_300.xml",
        "CNS cancer": "/collections/rss/collrss_283.xml",
        "Colon cancer": "/collections/rss/collrss_284.xml",
        "Endocrine cancer": "/collections/rss/collrss_286.xml",
        "Gastric cancer": "/collections/rss/collrss_287.xml",
        "Gene therapy": "/collections/rss/collrss_301.xml",
        "Gynecological  cancer": "/collections/rss/collrss_288.xml",
        "Head and neck cancer": "/collections/rss/collrss_289.xml",
        "Hepatic cancer": "/collections/rss/collrss_290.xml",
        "Lung cancer (oncology)": "/collections/rss/collrss_291.xml",
        "Oesophageal cancer": "/collections/rss/collrss_292.xml",
        "Paediatric oncology": "/collections/rss/collrss_302.xml",
        "Pancreatic cancer": "/collections/rss/collrss_294.xml",
        "Prevention": "/collections/rss/collrss_303.xml",
        "Prostate cancer": "/collections/rss/collrss_293.xml",
        "Radiotherapy": "/collections/rss/collrss_304.xml",
        "Respiratory cancer": "/collections/rss/collrss_295.xml",
        "Screening (oncology)": "/collections/rss/collrss_305.xml",
        "Skin cancer": "/collections/rss/collrss_285.xml",
        "Small intestine cancer": "/collections/rss/collrss_296.xml",
        "Urological cancer": "/collections/rss/collrss_297.xml",
        "Ophthalmology": "/collections/rss/collrss_309.xml",
        "Orthopaedics": "/collections/rss/collrss_334.xml",
        "Adolescent health": "/collections/rss/collrss_337.xml",
        "Bilirubin disorders": "/collections/rss/collrss_338.xml",
        "Child abuse": "/collections/rss/collrss_339.xml",
        "Child and adolescent psychiatry (paediatrics)": "/collections/rss/collrss_340.xml",
        "Childhood nutrition (paediatrics)": "/collections/rss/collrss_341.xml",
        "Child heath": "/collections/rss/collrss_342.xml",
        "Congenital disorders": "/collections/rss/collrss_343.xml",
        "Developmental paediatrics": "/collections/rss/collrss_344.xml",
        "Failure to thrive": "/collections/rss/collrss_345.xml",
        "Infant health": "/collections/rss/collrss_347.xml",
        "Infant nutrition (including breastfeeding)": "/collections/rss/collrss_348.xml",
        "Neonatal and paediatric intensive care": "/collections/rss/collrss_350.xml",
        "Neonatal health": "/collections/rss/collrss_351.xml",
        "SIDS": "/collections/rss/collrss_355.xml",
        "End of life decisions (palliative care)": "/collections/rss/collrss_359.xml",
        "Hospice": "/collections/rss/collrss_360.xml",
        "Pain (palliative care)": "/collections/rss/collrss_361.xml",
        "Chemical pathology": "/collections/rss/collrss_367.xml",
        "Cytopathology": "/collections/rss/collrss_368.xml",
        "Histopathology": "/collections/rss/collrss_369.xml",
        "Infection (pathology)": "/collections/rss/collrss_371.xml",
        "Inflammation": "/collections/rss/collrss_372.xml",
        "Microbiology": "/collections/rss/collrss_373.xml",
        "Microscopy": "/collections/rss/collrss_374.xml",
        "Molecular biology": "/collections/rss/collrss_375.xml",
        "Morbid anatomy/surgical pathology": "/collections/rss/collrss_376.xml",
        "Neuropathology": "/collections/rss/collrss_377.xml",
        "Virology": "/collections/rss/collrss_378.xml",
        "Drug misuse (including addiction)": "/collections/rss/collrss_383.xml",
        "Medicines regulation": "/collections/rss/collrss_385.xml",
        "Toxicology": "/collections/rss/collrss_384.xml",
        "Unwanted effects / adverse reactions": "/collections/rss/collrss_382.xml",
        "Prison medicine": "/collections/rss/collrss_388.xml",
        "Adjustment disorders": "/collections/rss/collrss_391.xml",
        "Alcohol-related disorders": "/collections/rss/collrss_392.xml",
        "Anxiety disorders (including OCD and PTSD)": "/collections/rss/collrss_399.xml",
        "Child and adolescent psychiatry": "/collections/rss/collrss_408.xml",
        "Delirium": "/collections/rss/collrss_415.xml",
        "Drugs misuse (including addiction)": "/collections/rss/collrss_416.xml",
        "Drugs: psychiatry": "/collections/rss/collrss_422.xml",
        "Eating disorders": "/collections/rss/collrss_423.xml",
        "Impulse control disorders": "/collections/rss/collrss_427.xml",
        "Memory disorders (psychiatry)": "/collections/rss/collrss_432.xml",
        "Mood disorders (including depression)": "/collections/rss/collrss_438.xml",
        "Personality disorders": "/collections/rss/collrss_443.xml",
        "Psychiatry of old age": "/collections/rss/collrss_454.xml",
        "Psychotherapy": "/collections/rss/collrss_455.xml",
        "Psychotic disorders (incl schizophrenia)": "/collections/rss/collrss_460.xml",
        "Sexual and gender disorders": "/collections/rss/collrss_466.xml",
        "Sleep disorders": "/collections/rss/collrss_471.xml",
        "Somatoform disorders": "/collections/rss/collrss_476.xml",
        "Suicide (psychiatry)": "/collections/rss/collrss_485.xml",
        "Radiology": "/collections/rss/collrss_488.xml",
        "Disability": "/collections/rss/collrss_491.xml",
        "Physiotherapy (rehabilitation)": "/collections/rss/collrss_492.xml",
        "Other rehabilitative therapies": "/collections/rss/collrss_1493.xml",
        "Acute renal failure": "/collections/rss/collrss_498.xml",
        "Chronic renal failure": "/collections/rss/collrss_499.xml",
        "Dialysis": "/collections/rss/collrss_500.xml",
        "Fluid electrolyte and acid-base disturbances": "/collections/rss/collrss_502.xml",
        "Nephrotic syndrome": "/collections/rss/collrss_503.xml",
        "Proteinurea": "/collections/rss/collrss_504.xml",
        "Renal transplantation": "/collections/rss/collrss_505.xml",
        "Airway biology": "/collections/rss/collrss_511.xml",
        "Asthma": "/collections/rss/collrss_512.xml",
        "Bronchiolitis": "/collections/rss/collrss_1512.xml",
        "Bronchitis": "/collections/rss/collrss_513.xml",
        "Cancer: see Oncology": "/collections/rss/collrss_514.xml",
        "Cystic fibrosis": "/collections/rss/collrss_516.xml",
        "Drugs: respiratory system": "/collections/rss/collrss_518.xml",
        "Interstitial lung diseases": "/collections/rss/collrss_517.xml",
        "Lung cancer": "/collections/rss/collrss_514.xml",
        "Lung function": "/collections/rss/collrss_520.xml",
        "Mechanical ventilation": "/collections/rss/collrss_522.xml",
        "Pneumonia (respiratory medicine)": "/collections/rss/collrss_523.xml",
        "Pulmonary embolism": "/collections/rss/collrss_524.xml",
        "Pulmonary emphysema": "/collections/rss/collrss_515.xml",
        "Pulmonary hypertension": "/collections/rss/collrss_525.xml",
        "Sleep disorders (respiratory medicine)": "/collections/rss/collrss_527.xml",
        "Tobacco related disease": "/collections/rss/collrss_528.xml",
        "Tuberculosis": "/collections/rss/collrss_529.xml",
        "Ankylosing spondylitis": "/collections/rss/collrss_535.xml",
        "Biological agents": "/collections/rss/collrss_536.xml",
        "Connective tissue disease": "/collections/rss/collrss_537.xml",
        "Degenerative joint disease": "/collections/rss/collrss_538.xml",
        "Drugs: musculoskeletal and joint diseases": "/collections/rss/collrss_539.xml",
        "Fibromyalgia": "/collections/rss/collrss_540.xml",
        "Musculoskeletal syndromes": "/collections/rss/collrss_541.xml",
        "Osteoarthritis": "/collections/rss/collrss_542.xml",
        "Osteoporosis": "/collections/rss/collrss_543.xml",
        "Rheumatoid arthritis": "/collections/rss/collrss_544.xml",
        "Sj@gren's syndrome": "/collections/rss/collrss_545.xml",
        "Systemic lupus erythematosus": "/collections/rss/collrss_546.xml",
        "Vasculitis": "/collections/rss/collrss_547.xml",
        "Sexual health": "/collections/rss/collrss_550.xml",
        "Sports and exercise medicine": "/collections/rss/collrss_587.xml",
        "Breast surgery": "/collections/rss/collrss_615.xml",
        "Cardiothoracic surgery": "/collections/rss/collrss_616.xml",
        "Gastrointestinal surgery": "/collections/rss/collrss_617.xml",
        "General surgery": "/collections/rss/collrss_618.xml",
        "Neurosurgery": "/collections/rss/collrss_620.xml",
        "Oral and maxillofacial surgery": "/collections/rss/collrss_621.xml",
        "Orthopaedic and trauma surgery": "/collections/rss/collrss_622.xml",
        "Otolaryngology / ENT": "/collections/rss/collrss_623.xml",
        "Plastic and reconstructive surgery": "/collections/rss/collrss_624.xml",
        "Surgical oncology": "/collections/rss/collrss_625.xml",
        "Transplantation": "/collections/rss/collrss_626.xml",
        "Urological surgery": "/collections/rss/collrss_627.xml",
        "Vascular surgery": "/collections/rss/collrss_628.xml",
        "Urology": "/collections/rss/collrss_1350.xml",
        "Academic medicine": "/collections/rss/collrss_1351.xml",
        "Communication": "/collections/rss/collrss_653.xml",
        "Clinical trials": "/collections/rss/collrss_1468.xml",
        "Epidemiologic studies": "/collections/rss/collrss_1470.xml",
        "Population trends": "/collections/rss/collrss_1481.xml",
        "Screening": "/collections/rss/collrss_666.xml",
        "Survey techniques": "/collections/rss/collrss_1482.xml",
        "Therapeutic trials": "/collections/rss/collrss_1469.xml",
        "Time-to-event methods": "/collections/rss/collrss_1483.xml",
        "Artificial and transplanted organs/tissues": "/collections/rss/collrss_675.xml",
        "Assisted dying": "/collections/rss/collrss_676.xml",
        "Bioethics": "/collections/rss/collrss_677.xml",
        "Codes of/position statements on professional ethics": "/collections/rss/collrss_678.xml",
        "Competing interests (ethics)": "/collections/rss/collrss_679.xml",
        "Confidentiality": "/collections/rss/collrss_680.xml",
        "End of life decisions (ethics)": "/collections/rss/collrss_682.xml",
        "Ethics of abortion": "/collections/rss/collrss_683.xml",
        "Ethics of reproduction": "/collections/rss/collrss_685.xml",
        "Experiments in vivo": "/collections/rss/collrss_686.xml",
        "Informed consent": "/collections/rss/collrss_687.xml",
        "Research and publication ethics": "/collections/rss/collrss_690.xml",
        "Ethnic studies": "/collections/rss/collrss_695.xml",
        "Information management": "/collections/rss/collrss_750.xml",
        "Information technology": "/collections/rss/collrss_751.xml",
        "Telemedicine": "/collections/rss/collrss_752.xml",
        "Internet": "/collections/rss/collrss_753.xml",
        "Health policy": "/collections/rss/collrss_1364.xml",
        "Health service research": "/collections/rss/collrss_763.xml",
        "Authorship": "/collections/rss/collrss_766.xml",
        "Competing interests (journalology)": "/collections/rss/collrss_767.xml",
        "Peer review": "/collections/rss/collrss_768.xml",
        "Research and publication ethics (journalology)": "/collections/rss/collrss_769.xml",
        "Legal and forensic medicine": "/collections/rss/collrss_772.xml",
        "Continuous professional development": "/collections/rss/collrss_781.xml",
        "Professional conduct and regulation": "/collections/rss/collrss_786.xml",
        "History taking and the physical examination": "/collections/rss/collrss_797.xml",
        "Postgraduate": "/collections/rss/collrss_800.xml",
        "Undergraduate": "/collections/rss/collrss_802.xml",
        "Medical humanities": "/collections/rss/collrss_805.xml",
        "Doctors' morale and well being": "/collections/rss/collrss_775.xml",
        "Medical error/ patient safety": "/collections/rss/collrss_776.xml",
        "Quality improvement": "/collections/rss/collrss_777.xml",
        "Occupational and environmental medicine": "/collections/rss/collrss_842.xml",
        "Patients": "/collections/rss/collrss_1358.xml",
        "Abuse (child, partner, elder)": "/collections/rss/collrss_935.xml",
        "Air pollution": "/collections/rss/collrss_937.xml",
        "Alcohol": "/collections/rss/collrss_938.xml",
        "Climate change": "/collections/rss/collrss_939.xml",
        "Drug misuse": "/collections/rss/collrss_941.xml",
        "Health education": "/collections/rss/collrss_944.xml",
        "Health of indigenous peoples": "/collections/rss/collrss_945.xml",
        "Health promotion": "/collections/rss/collrss_967.xml",
        "Homicide": "/collections/rss/collrss_946.xml",
        "Housing and health": "/collections/rss/collrss_947.xml",
        "Human rights": "/collections/rss/collrss_948.xml",
        "Injury": "/collections/rss/collrss_949.xml",
        "Obesity (public health)": "/collections/rss/collrss_964.xml",
        "Salutogenesis": "/collections/rss/collrss_967.xml",
        "Screening (public health)": "/collections/rss/collrss_968.xml",
        "Sexual health (public health)": "/collections/rss/collrss_969.xml",
        "Social conditions and disease": "/collections/rss/collrss_1514.xml",
        "Smoking": "/collections/rss/collrss_970.xml",
        "Suicide (public health)": "/collections/rss/collrss_971.xml",
        "Urban health": "/collections/rss/collrss_973.xml",
        "Violence against women": "/collections/rss/collrss_974.xml",
        "Violence (other)": "/collections/rss/collrss_975.xml",
        "Smoking and tobacco": "/collections/rss/collrss_1360.xml",
        "Sociology": "/collections/rss/collrss_994.xml",
        "Qualitative research": "/collections/rss/collrss_999.xml",
        "Quantitative research": "/collections/rss/collrss_1488.xml",
        "Inflammatory bowel disease": "/collections/rss/collrss_177.xml"
    };
    
    
    /* Identify the unique collection id of the page by parsing the related box information */
   $jQuery.each(bmjfeed1, function(title, url){
        if (title == $jQuery('#ArticleNav h5:contains("Related Content") + ul > li:first > a').html()) {
            //			if (title == "Asthma") {
            feedtitle = title;
            feedurl = url;
            widget_head = 'See also';
        }
        
    });
    
    if (feedurl != "http://www.bmj.com/rss/recent.xml") {
    
        this.default_args.url = "http://www.bmj.com" + feedurl;
        
        this.options = options;
        
        /* If a user does not define any of the widget parameters, use the default define above */
        for (var index in this.default_args) {
        
            if (typeof this.options[index] == "undefined") 
                this.options[index] = this.default_args[index];
            
        }
              
        
       $jQuery.ajax({
       url: this.options['jurl'],
        data: "url=" + this.options['url'] + "&widget_title=" + this.options['widget_title'] + "&style=" + this.options['style'] + "&source=" + this.options['source'] + "&track=" + this.options['track'] + "&target=" + this.options['target'] + "&num_items=" + this.options['num_items'] + "&section=" + this.options['section'] + "&enclink=" + this.options['enclink'] + "&enclength=" + this.options['enclength'] + "&encltype=" + this.options['encltype'] + "&widget=" + this.options['widget'] + "&callback=bmjcallback2",
        cache: true,
        dataType: "script",
        success: bmjcallback2 = function(data){
            
			if (data) {
            
                $jQuery('div#widget1').empty(); /* Remove the default widget Markup done for SEO */
                $jQuery('div#widget1').append('<div id="' + data.feedhead[0].widget + '"></div>'); /* Add the new feed widgets */
                /* BMJ Group XHTML markup for styling the feed content */
                
                $jQuery('div#' + data.feedhead[0].widget).addClass(data.feedhead[0].style);
                $jQuery('div#' + data.feedhead[0].widget).append('<h2>' + data.feedhead[0].widget_title + '</h2>').append('<ul class="StandardBullet">');
                
               $jQuery.each(data.items, function(i, item){
                
                    feed_html = '<li class="rss-item">';
                    
                    if (item.section.length > 0) {
                        feed_html += ' ' + item.section + ':';
                    }
                    
                    feed_html += ' ' + '<a href="' + item.link + '" target="' + data.feedhead[0].target + '">' + item.title + '<\/a>' + ' ';
                    
                    if (item.date.length > 0) {
                        feed_html += '<span class="date">' + "(" + item.date + ")" + '</span>';
                    }
                    feed_html += '</li>';
                    
                    $jQuery('div#' + data.feedhead[0].widget + ' ul').append(feed_html);
                    
                });
                
            }
}            
        });
    }
    
}


   

/* A function to deploy cross domain widgets */
function tabbedwidget(options)
{
	/* Define all default widget parameters */
    var default_args = {
        'url': "http://www.bmj.com/rss/recent.xml",
        'section': "none",
        'source': "no",
        'category': "all",
        'track': "widget_bmjblogs",
        'title': "Latest from BMJ",
        'subject': "all",
        'style': "bmj",
        'widget': "feeds-widget1",
        'jurl': "http://group.bmj.com/feed2json/index.php", /* default JSON feed URL */
        'target': "_self",
        'num_items': "5"
    }


this.default_args = default_args;

this.options = options;

	/* If a user does not define any of the widget parameters, use the default define above */
	for(var index in this.default_args) {

		if(typeof this.options[index] == "undefined") this.options[index] = this.default_args[index];

	}


     $jQuery.ajax({
        url: this.options['jurl'],
        data: "url=" + this.options['url'] + "&widget_title=" + this.options['widget_title'] + "&style=" + this.options['style'] + "&source=" + this.options['source'] + "&track=" + this.options['track'] + "&target=" + this.options['target'] + "&num_items=" + this.options['num_items'] + "&section=" + this.options['section'] + "&enclink=" + this.options['enclink'] + "&enclength=" + this.options['enclength'] + "&encltype=" + this.options['encltype'] + "&widget=" + this.options['widget'] + "&callback=bmjcallback3",
        cache: true,
        dataType: "script",
        success: bmjcallback3 = function(data){
			
  			if (data) {      

	  $jQuery('div#'+data.feedhead[0].widget).empty(); /* Replace the default widget Markup done for SEO */
	 /* $jQuery('div#'+data.feedhead[0].widget).append('<h2>' + data.feedhead[0].widget_title + '</h2>'); */

	  /* BMJ Group XHTML markup for styling the feed content */

	  $jQuery('div#'+data.feedhead[0].widget).addClass(data.feedhead[0].style);
	  $jQuery('div#'+data.feedhead[0].widget).append('<div class="latestbox1">');
	  $jQuery('div#'+data.feedhead[0].widget).append('<div class="latestbox2">');

  	  $jQuery.each(data.items, function (i,item) {

			feed_html = '<div class="feeditem">';

				if (item.source == "none" || item.source == "undefined" || item.source == "no") {

					if (item.section.length > 0) {
			    	    feed_html += ' ' + '<span class="sect1">' + item.section + ':' + '</span>'+ ' ';
		    	    }
			    }
			    else {

		    	    if (item.source.length > 0) {
			    	    feed_html += ' ' + '<span class="sect1">' + item.source + ':' + '</span>'+ ' ';
		    	    }
			    }

	    	    feed_html += ' ' + '<span class="title1"><a href="' + item.link +  '" target="' +  data.feedhead[0].target +  '">' + item.title + '<\/a>' + '</span>'+ ' ';

	    	    if (item.date) {
		    	    feed_html += '<span class="date">' + "("+item.date +")" + '</span>';
			    }

	    	    if (item.encltype=="audio/mpeg") {
                   feed_html += '<br/><object type="application/x-shockwave-flash" data="http://group.bmj.com/media/player/player.swf" id="audioplayer1" height="24" width="140"><param name="movie" value="http://group.bmj.com/media/player/player.swf"><param name="FlashVars" value="playerID=1&amp;leftbg=0x006990&amp;lefticon=0xffffff&amp;rightbg=0x006990&amp;rightbghover=0xFF00FF&amp;righticon=0x0ffffff&amp;righticonhover=0xcccccc&amp;text=0x006990&amp;slider=0x006990&amp;border=0x006990&amp;loop=no&amp; autostart=no&amp;soundFile=' + item.enclink + '"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"></object>';                   }


	    	    feed_html += '</div>';


			    if (i < 10) {
	                        $jQuery('div#'+data.feedhead[0].widget+' div.latestbox1').append(feed_html);
                    }
               else {
  	                $jQuery('div#'+data.feedhead[0].widget+' div.latestbox2').append(feed_html);
                    }
		});

	}
}
 });

}

