
$(pageSetup);
function pageSetup() {
var tempy = 0;
$("#showAll").show();
$("#hideAll").hide();
try {
$(".collapsable").each(function(index, element) {
$(this).hide();
$(".button a", element).bind("click", function(e) {hide(element); return(false);});
});
$("#hideAll").bind("click", function(e) {hideAll(); this.blur(); return(false);});
$("#showAll").bind("click", function(e) {showAll(); this.blur(); return(false);});
var quesDivs = $("[id^='ques']");
$("[id^='ques']").each(function() {
ques = this.getAttribute("id");
ans = ques.replace("ques", "ans");
$('#' + ques).bind("click", function(e) {
showHide(this);
this.blur();
return(false);});
})}

catch(e) {
alert(e.toString());
}
var myParams = stripURLparams();
if(myParams["ques"] !== undefined && myParams["ques"] !== ""){
$('#ans' + myParams["ques"]).show();
}else if(myParams["topic"] !== undefined && myParams["topic"] !== ""){
$('a[name="' + myParams["topic"] + '"]').parents('[class="collapsable"]').show();
}
}
function movePage(){
jQuery(document).scrollTop(170);
}
function showAll(){
var openDivs = $("div[id^='ans']")

for(var i = 0; i < openDivs.length; i++)
{
$("#" + openDivs[i].getAttribute("id")).slideDown();
}

$("#showAll").hide();
$("#hideAll").show();
}
function hideAll(){
var openDivs = $("div[id^='ans']")
for(var i = 0; i < openDivs.length; i++)
{
$(openDivs[i]).slideUp("normal");
}

$("#showAll").show();
$("#hideAll").hide();
}
function showHide(div) {

ques = div.id;
ans = ques.replace(/ques/g, "ans");
var openDivs = $(".collapsable:visible");

if(openDivs.length == 1) {

$(openDivs[0]).slideUp("normal", function(e) {$("#" + ans).slideDown(movePage);});
}else if(openDivs.length > 1) {

hideAll();
$(openDivs[0]).slideUp("normal", function(e) {$("#" + ans).slideDown(movePage);});
}
else {

$("#" + ans).slideDown(movePage);
}
}
function hide(div) {

$(div).slideUp();
}
function stripURLparams() {
var params, pString, keyPair;
var pArray = new Array;
params= window.location.href;
pString = params.split("?");

if(pString[1] === undefined)
{
return pArray;
}

params = pString[1];

if(params=="")
{
return pArray;
}

params = params.replace(/&amp;/g,"&");
pString = params.split("&");

for(var i = 0; i < pString.length; i++)
{
keyPair = pString[i].split("=");
pArray[keyPair[0]] = keyPair[1];
}
return pArray;
}

