// hero box on homepage
/*
function timeout_trigger() {
 captionNode.style.backgroundImage="url(/img/bg_bluestrip."+imgtype+")";  
}
*/

function showDiv(id) 
{





     if (document.getElementById)
     { // DOM3 = IE5, NS6
	 
	
	 
	 
       if(document.getElementById(id).style.display == 'block')
       {document.getElementById(id).style.display = 'none';
	   document.getElementById(id).style.visibility= 'hidden';
	   }
       else
       {document.getElementById(id).style.display = 'block';
	   document.getElementById(id).style.visibility= 'visible';
	   }
     }
     else
     {
       if (document.layers)
       { // Netscape 4
         document.hideShow.display = 'block';
       }
       else 
       { // IE 4
           document.all.hideShow.style.display = 'block';
       }
     }
}


$(document).ready(function(){
	
// MIke ajax for comments

				$.ajaxSetup({
							   url: "/save_comments.php",
							   global: false,
							   type: "POST"				
				 });
				 
				 $('#commentSubmit').click(function() {	
				                    var data = '';
									var comment = $('textarea[name=comment]');  
									var screen_name = $('input[name=screen_name]');  
									var pid = $('input[name=pid]'); 
									var cid = $('input[name=cid]');
									var page_type = $('input[name=page_type]'); 

								var data = 'comment=' + encodeURIComponent(comment.val()) +  '&screen_name=' + encodeURIComponent(screen_name.val()) +  '&pid=' + encodeURIComponent(pid.val()) +  '&cid=' + encodeURIComponent(cid.val()) +  '&page_type=' + encodeURIComponent(page_type.val()) ;	
//alert(data);
									$.ajax({				
											  data: data, 
											  success: function(data) {
														    $('#new_comment').html(data);
															//alert('done');

												  }
									});
									
				});
	



	
// PUT IN APPRPRT IMG FORMATS

jQuery.each(jQuery.browser, function(i) {														
  if($.browser.msie && jQuery.browser.version.substr(0,3)<"7"){
   browser="ie6";
	imgtype="gif"
  }
  else 
  if($.browser.msie && jQuery.browser.version.substr(0,3)<"8"){
  browser="ie7";
	imgtype="png"
  }
  else{
   browser="notie";
	 imgtype="png"
  }
});

// button slide - MAY BE UNNECESSARY!!!
$(".btn-slide").click(function(){
$("#panel").slideToggle("medium");
$(this).toggleClass("active"); return false;
});

/*
//
// PHOTOSTORIES					   
	
	 $('#photostoriescaption a').each( function() {
										   getHeight=this.offsetHeight;
										   if(browser!="ie6"){
										   this.style.marginTop="-"+getHeight+"px";
										  }
										   })
	  $('#photostories a').hover(function () {
										  document.getElementById("photostoriescaptionA").style.backgroundImage="url(/img/bg_orangestrip."+imgtype+")";  
										   }, 
										   function () {
											  document.getElementById("photostoriescaptionA").style.backgroundImage="url(/img/bg_bluestrip."+imgtype+")"; 
											   }
											   );
	  $('#photostoriescaption a').hover(function () {
										   document.getElementById("photostoriescaptionA").style.backgroundImage="url(/img/bg_orangestrip."+imgtype+")";
										   }, 
										   function () {
											  document.getElementById("photostoriescaptionA").style.backgroundImage="url(/img/bg_bluestrip."+imgtype+")"; 
											   }
												);
	// CELEBS					   

	
	 $('#celebscaption a').each( function() {
										   getHeight=this.offsetHeight;
										  if(browser!="ie6"){
										   this.style.marginTop="-"+getHeight+"px";
										  }
										   })
	  $('#celebs a').hover(function () {
										  document.getElementById("celebscaptionA").style.backgroundImage="url(/img/bg_orangestrip."+imgtype+")";  
										   }, 
										   function () {
											  document.getElementById("celebscaptionA").style.backgroundImage="url(/img/bg_bluestrip."+imgtype+")"; 
											   }
											   );
	  $('#celebscaption a').hover(function () {
										   document.getElementById("celebscaptionA").style.backgroundImage="url(/img/bg_orangestrip."+imgtype+")";
										   }, 
										   function () {
											   document.getElementById("celebscaptionA").style.backgroundImage="url(/img/bg_bluestrip."+imgtype+")"; 
											   }
											   );
*/






// NOT IE6 ONLY

if(browser!="ie6"){	
// text area	
 $(".formCommentBox").focus(function() {
    if( $(this).val() == "Add your comment here" ) {
        $(this).val("");
    }
});	 
 $(".formCommentBox").blur(function() {
	 if( $(this).val() == "" ) {
        $(this).val("Add your comment here");
    }
   
});	 
 
/* 
$("#mainNavUl .topMenu").hover(function () {
										   
										   $(".children", this).slideDown(100);
										   $(this).addClass("sf");
										   }, 
										   function () {
											   $(".children", this).slideUp(50);
											   }
												 
											   );
												 */
												 
												 
	}
	
	
	
	
	
										  
  /*
  $(".linkBox a").hover(function () {
								  if (this.parentNode.parentNode.className == "linkBox") {
									  this.parentNode.parentNode.style.backgroundColor="#ffe891";
									  this.parentNode.parentNode.style.backgroundPosition="0px -400px";
									  }
									  },
									  function () {
										  if (this.parentNode.parentNode.className == "linkBox") {
											  this.parentNode.parentNode.style.backgroundColor="#fff";
											  this.parentNode.parentNode.style.backgroundPosition="0px 0px";
											  }
											  }
											  );

  $('.imageWithTextTR .caption h3 a').each( function() {
	
												  getwidth=this.offsetWidth;
												  newwidth=this.offsetWidth-20;
												  this.style.width=newwidth+"px";
												  this.style.paddingRight="30px";
												  this.style.paddingLeft="10px";
												  
												  }
												  );
  $('.imageWithTextTR .caption h4 a').each( function() {
												  getwidth=this.offsetWidth;
												  newwidth=this.offsetWidth-20;
												  this.style.width=newwidth+"px";
												  this.style.paddingRight="30px";
												  this.style.paddingLeft="10px";
												  
												  }
												  );
  $('.imageWithTextTR .caption').each( function() {
												this.style.overflow="visible";
											 	getSib=this.parentNode.firstChild;
											  while (getSib.tagName!="IMG" && getSib.tagName!="A") {
												  getSib=getSib.nextSibling;
												  }
												  if(getSib.tagName=="A"){ 
												  getSib=getSib.firstChild;//alert("3 "+getSib);
												  }
												  picHeight=getSib.offsetHeight;
												  getHeight=this.offsetHeight;
												  picWidth=getSib.offsetWidth;
												  getWidth=this.offsetWidth;
												 //
												  this.parentNode.style.height=picHeight+"px";
												  newleft=picWidth-getWidth;
												  getBottomMargin=picHeight-getHeight;
												   if(browser=="ie6"||browser=="ie7"){picHeight+=3;}
													this.style.marginTop="-"+picHeight+"px";
													//this.style.marginLeft=newleft+"px";
												  }
												  ); 
  


 $('.imageWithTextBL .caption').each( function() {
											 this.style.overflow="visible";
											 getSib=this.parentNode.firstChild;
											  while (getSib.tagName!="IMG") {
												  getSib=getSib.nextSibling;
												  }
												  getHeight=this.offsetHeight;
												  picHeight=getSib.offsetHeight;
												  picWidth=getSib.offsetWidth;
												  getWidth=this.offsetWidth;
												  this.parentNode.style.height=picHeight+"px";
												  getBottomMargin=picHeight-getHeight;
												   if(browser=="ie6"||browser=="ie7"){getHeight-=3;}
													this.style.marginTop="-"+getHeight+"px";
												  }
												  ); 
 
 
 $('.imageWithTextTR a').mouseover(function(){
											 getParent=this.parentNode;
											 while (getParent.className!="imageWithTextTR") {
												 getParent=getParent.parentNode;
												 }
												  //getParent.style.border = '1px solid #f47b20';
												 for (i=0;i<getParent.childNodes.length;i++)
												 if (getParent.childNodes[i].className=="caption") {
													captionNode=getParent.childNodes[i];
													captionNode.className="captionHov"
													if(t){clearTimeout(t);}
													 }
												
												 }
												)
 .mouseout(function(){
					captionNode.className="caption"
					//getParent.style.border = '1px solid #eeeeee';
					//captionNode.style.backgroundImage="url(/img/bg_bluestrip."+imgtype+")"; 
					//t=setTimeout('timeout_trigger()', 300);
					}
					);
*/






//top menu bar changes colours to section colours for dropdowns and top menu item

  $("#mainNavUl li a img").hover(function () {
	if(this.parentNode.parentNode.id){
	this.src ="/img/"+this.id+"_active.png";
	}
	}, 
	function () {
	});
  $("#mainNavUl li").hover(function () {
	if(this.id){
	}
	}, 
	function () {
  if (this.id) {
        for (var i = 0; i < this.childNodes.length; i++) {
            if (this.childNodes[i].tagName) {
                var chosenTag = this.childNodes[i];
                if (chosenTag.tagName == "A") {
                    i = this.childNodes.length + 1;
                    for (var j = 0; j <= chosenTag.childNodes.length; j++) {
                        if (chosenTag.childNodes[j].tagName) {
                            var chosenTag2 = chosenTag.childNodes[j];
                            j = chosenTag.childNodes.length + 1;
                            if (chosenTag2.className != "currentSec") {
                                chosenTag2.src ="/img/" + chosenTag2.id + ".png";
                            }
                        }
                    }
                }
            }
        }
    }
	});
	
// HOME PAGE TABS

   $(".tabs li:eq(0) a").css("border-left", "none");
   
   $(".tabbedBox .tabs li a").click(function() { 	
			if(this.className=="tabWhat") {
				document.getElementById("heroBottom").style.backgroundColor="#00a2ea";
				}
				else if(this.className=="tabWhere") {
				document.getElementById("heroBottom").style.backgroundColor="#269a1e";
				}
				else if(this.className=="tabNews") {
				document.getElementById("heroBottom").style.backgroundColor="#de002a";
				}
				else if(this.className=="tabResources") {
				document.getElementById("heroBottom").style.backgroundColor="#5d0073";
				}
				else document.getElementById("heroBottom").style.backgroundColor="#072d78";
      openTab($(this)); return false; 		
   });   
   $(".tabbedBox .tabs li a:eq("+currentTab+")").click()
});

var currentTab = 0; // Set to a different number to start on a different tab.

function openTab(clickedTab) {
   var thisTab = $(".tabbedBox .tabs a").index(clickedTab);
   $(".tabbedBox .tabs li a").removeClass("active");
   $(".tabbedBox .tabs li a:eq("+thisTab+")").addClass("active");
   $(".tabbedBox .tabbed-content").hide();
   $(".tabbedBox .tabbed-content:eq("+thisTab+")").fadeIn();
   currentTab = thisTab;
}

//----change backgrounds for sponsor buttons-------//
var backgroundSrcs = new Array("https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor1.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor2.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor3.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor4.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor5.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor6.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor7.png","https://web32.secure-secure.co.uk/everychild.org.uk/img/sponsor8.png")


//Edit this line to list all of your related urls
var urls = new Array("https://services.everychild.org.uk/LoginManagement/sponsorachild_like_madhuri.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_madhuri.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_felix.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_felix.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_kamraj.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_kamraj.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_towera.aspx","https://services.everychild.org.uk/LoginManagement/sponsorachild_like_towera.aspx")

window.onload = function() { pickimage();}
function pickimage()
{
//This line picks an image at random from the list you entered above
rnd=(Math.round(Math.random()*(backgroundSrcs.length-1)));

var bgimage=backgroundSrcs[rnd];
var url=urls[rnd];

//This line applies the background image to the div
document.getElementById("sponsor_child").style.background = "url('" + bgimage + "') no-repeat 0 0";  
setHtml = '<a href="' + url  + '" id="sponsorLink"><span>Sponsor a child</span></a>';
document.getElementById('sponsor_child').innerHTML = setHtml;
}
