//client area slider function
var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

window.addEvent('domready',function(){	
	$$('.structuretoggle').each(function(el){
		
		el.addEvent('click',function(){
		
			li = el.getParent();
			theLi = li.getParent();
										
			theContainer = li.getElements('div.m-slider-inner');
			theSlider = li.getElements('div.m-slider');
			theImg = el.getElementsByTagName('img');
			if(theContainer.length > 0){

				containerHeight = theContainer[0].getSize().y;
				//alert(theImg[0].getAttribute('src'));
				if(theImg[0].getAttribute('src').contains('/images/faq-arrow-down.gif'))
				{
					
					theParentContainer = li.getParents('div.m-slider');
					if (theParentContainer.length == 0)
					{
						theSlider[0].setStyle('height', containerHeight);
					}else
					{
						theParentContainer[0].setStyle('height','auto');
					}
					
					theSlider[0].tween('height',0);
					theImg[0].setAttribute('src','/images/faq-arrow-right.gif');	
						
					if (isIE6 == false){
					    theLi.setStyles({backgroundImage: 'url(/images/background-divider-large.png)'});  
					    theLi.setStyles({backgroundPosition: 'bottom left'}); 
					    theLi.setStyles({backgroundRepeat: 'repeat-x'});  									
				    }
				} else 
				{		
					
					theParentContainer = li.getParents('div.m-slider');
					if (theParentContainer.length > 0)
					{
						theParentContainer[0].setStyle('height','auto');
					}					
				
					theSlider[0].tween('height',containerHeight);
					theImg[0].setAttribute('src','/images/faq-arrow-down.gif');
					
					if (isIE6 == false){			
					    theLi.setStyles({backgroundImage: 'url(/images/faq-background.png)'});  
					    theLi.setStyles({backgroundPosition: 'top left'}); 
					    theLi.setStyles({backgroundRepeat: 'repeat'});  
					}						
				}
			}	
			
			return false;
		});
	});
});		
//end client area slider function
























function getName(s) {
    // function to get the filename of an image
    var d = s.lastIndexOf('.');
    return s.substring(s.lastIndexOf('/') + 1, d < 0 ? s.length : d);
}


function newssliders(newsquestionid)
{    
    var totalnews = $$("ul.news li").length;
    for (i=1;i<=totalnews;i++)
        {
            var container = 'newscontainer' + i;
            var subcontainer = 'newsanswer' + i;
            //var questioncontainer = 'newsquestion' + i;
            var containerbg = $(container).getStyle('backgroundImage');
  
                if (newsquestionid !== container)
                {
                    $(subcontainer).slide('out');
                    $(container).setStyles({
                        backgroundImage: 'none'
                    });    
                }
                else
                {
                    if (containerbg == 'url(/images/faq-background.png)')
                        {
                            $(container).setStyles({
                                backgroundImage: 'none'
                            });  
                        }
                    else
                        {
                            $(container).setStyles({
                                backgroundImage: 'url(/images/faq-background.png)'
                            });  
                        }                           
                }
        }  
}


function faqsliders(faqquestionid)
{    
    var totalfaqs = $$("ul.faqQAs li").length;  
    for (i=1;i<=totalfaqs;i++)
        {
            var container = 'faqcontainer' + i;
            var subcontainer = 'faqanswer' + i;
            //var questioncontainer = 'faqquestion' + i;
            var arrowimage = 'faqarrow' + i;
            var containerbg = $(container).getStyle('backgroundImage');
            var imagename = getName(document.images[arrowimage].src);     
  
                if (faqquestionid !== container)
                {
                    $(subcontainer).slide('out');
                    $(container).setStyles({
                        backgroundImage: 'none'
                    });    
                    document.images[arrowimage].src = '/images/faq-arrow-right.gif';
                }
                else
                {
                    if (containerbg == 'url(/images/faq-background.png)')
                        {
                            $(container).setStyles({
                                backgroundImage: 'none'
                            });  
                        }
                    else
                        {
                            $(container).setStyles({
                                backgroundImage: 'url(/images/faq-background.png)'
                            });  
                        }   
                    
                    if (imagename == 'faq-arrow-right')
                    {   
                        document.images[arrowimage].src = '/images/faq-arrow-down.png';
                    }
                    else
                    {   
                        document.images[arrowimage].src = '/images/faq-arrow-right.png';
                    }
                }
        } 
}

                
function clientareasliders(faqquestionid)
{       
    var totalcaitems = 3;  
    for (i=1;i<=totalcaitems;i++)
        {
            var container = 'cacontainer' + i;
            var subcontainer = 'cacontent' + i;
            //var questioncontainer = 'caheader' + i;
            var arrowimage = 'caarrow' + i;
            var containerbg = $(container).getStyle('backgroundImage');
            var imagename = getName(document.images[arrowimage].src);     
  
                if (faqquestionid !== container)
                {
                    $(subcontainer).slide('out');
                    $(container).setStyles({
                        backgroundImage: 'none'
                    });    
                    document.images[arrowimage].src = '/images/faq-arrow-right.gif';
                }
                else
                {
                    if (containerbg == 'url(/images/faq-background.png)')
                        {
                            $(container).setStyles({
                                backgroundImage: 'none'
                            });  
                        }
                    else
                        {
                            $(container).setStyles({
                                backgroundImage: 'url(/images/faq-background.png)'
                            });  
                        }   
                    
                    if (imagename == 'faq-arrow-right')
                    {   
                        document.images[arrowimage].src = '/images/faq-arrow-down.gif';
                    }
                    else
                    {   
                        document.images[arrowimage].src = '/images/faq-arrow-right.gif';
                    }
                    
                }
        } 
}


function faqslidersclientarea(faqquestionid)
{
    // get total number of items    
    var totalfaqs = $$("ul.faqQAs li").length; 
    var totaltoreduceby = 0;  
    
    // loop through each item to get the total height of the contained faq slides, this is so we can modify the containing
    // slider by this amount when we click between each item.
    for (z=1;z<=totalfaqs;z++)
    {
        if (totaltoreduceby === 0)
        {
            // check background status of each item
            faqcontainerbg = $('faqcontainer' + z).getStyle('backgroundImage');
            // if background is set
            if (faqcontainerbg == 'url(/images/faq-background.png)')
            {
                // add to the totaltoreduceby variable the height of the selected / open item
                totaltoreduceby = $('faqanswer' + z).offsetHeight;
            }
        }
    }  
        
        // loop through each item again, this time so we slide or shrink them as required
        for (i=1;i<=totalfaqs;i++)
            {
                // set and collect the variables required, including the current background status and arrow image status
                var container = 'faqcontainer' + i;
                var subcontainer = 'faqanswer' + i;
                //var questioncontainer = 'faqquestion' + i;
                var arrowimage = 'faqarrow' + i;
                var containerbg = $(container).getStyle('backgroundImage');
                var imagename = getName( document.images[arrowimage].src); 
                var newheightforfaqslider = 0;

                // if the selected faqquestion is the same as the one at this point of the loop
                if (faqquestionid == container)
                {
                    // calculate the new height of the container slider
                    var getheightofanswer = $(subcontainer).offsetHeight;
                    var getheightoffaqslider = $('cacontent3').offsetHeight;
                    if (containerbg == 'url(/images/faq-background.png)')
                    // then the layer is selected, so when clicked again we need to reduce the height of the main container slider
                    {
                        newheightforfaqslider = (getheightoffaqslider - getheightofanswer - 20);
                        // set the new height and slide to that height
                        $('cacontent3').style.height = newheightforfaqslider + 'px'; 
                        $('cacontent3').slide('in');
                    }
                    else
                    {
                    // then the layer is NOT selected, so when clicked again we need to increase the height, but reduce any others
                        newheightforfaqslider = (newheightforfaqslider + getheightoffaqslider + getheightofanswer - 20 - totaltoreduceby);
                        // set the new height and slide to that height
                        $('cacontent3').style.height = newheightforfaqslider + 'px'; 
                        $('cacontent3').slide('in');
                    }
                }
                    // if the selected faqquestion is NOT the same as the one at this point of the loop
                    if (faqquestionid !== container)
                    {
                        // slide the no selected faqquestion back up, clear the background and reset the arrow image
                        $(subcontainer).slide('out');
                        $(container).setStyles({
                            backgroundImage: 'none'
                        });    
                        document.images[arrowimage].src = '/images/faq-arrow-right.gif';
                        
                    }
                    else
                    // then the selected faqquestio is the same as the point in the loop
                    {
                        // if the background is set then the item is already open, so the click action is to close the item
                        // clear the background, or if its not currently selected (the click is to open it) set the background
                        if (containerbg == 'url(/images/faq-background.png)')
                            {
                                $(container).setStyles({
                                    backgroundImage: 'none'
                                });  
                            }
                        else
                            {
                                $(container).setStyles({
                                    backgroundImage: 'url(/images/faq-background.png)'
                                });  
                            }   
                        
                        // as abvoe, if the the arrow is right the item isn't selected so the click is to open it so we set the arrow to down
                        // else, the arrow is down and item is open, so the click was to close, so we set the arrow to right.
                        if (imagename == 'faq-arrow-right')
                        {   
                            document.images[arrowimage].src = '/images/faq-arrow-down.gif';
                        }
                        else
                        {   
                            document.images[arrowimage].src = '/images/faq-arrow-right.gif';
                        }
                        
                    }
            } 
}