var preloadFlag = false;
function preloadImages() {
if (document.images) {
    topNav2Bg_over = newImage("images/topNav2Bg.jpg");
    
    preloadFlag = true;
}
}


get_element = document.all ?
function (s_id) { return document.all[s_id] } :
function (s_id) { return document.getElementById(s_id) };

function getWidth(name) {    
	/*var tmpElem = get_element(name);	*/
	var tmpElem= document.getElementById(name);
	return tmpElem.offsetWidth;

}

function setWidth(name1,name2) {
	var tmpElem1 = get_element(name1);
	var width1 = getWidth(name1);
	var tmpElem2 = get_element(name2);
	var width2 = getWidth(name2);
	
	tmpElem2.style.width = 920-width1+"px";
}

function getHeight(name) {    
	var tmpElem = get_element(name);
	if(tmpElem.currentStyle) return tmpElem.offsetHeight;       
	else return parseInt(document.defaultView.getComputedStyle(tmpElem, "").getPropertyValue("height")); 
	
}

function setHeight(name) {
	var tmpElem = get_element(name);
	var height = getHeight(name);
	
	//alert('wrapper ='+height);
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	if(height>=myHeight)
		tmpElem.style.height = height+"px";
	else tmpElem.style.height = myHeight+"px";
	//alert('wrapper ='+height);
}

function setHeight2(name1, name2, name3){
	var tmpElem = get_element(name1);
	var height1 = getHeight(name1);
	var height2 = getHeight(name2);
	var height3 = getHeight(name3);
	
	//alert('leftNav = '+height1);
	//alert('middlePart = '+height2);
	//alert('rightPart = '+height3);
	
	// middle content is the longest
	if ( (height1<height2) && (height3<height2))
		tmpElem.style.height = height2-24+"px";
	// right content is the longest
	else if ( (height1<height3) && (height2<height3))
		tmpElem.style.height = height3-24+"px";
	// LeftNav should be the longest
	else if( (height1>=height2) && (height2>=height3))
		tmpElem.style.height = height1+"px";
	else if( (height1>=height2) && (height2<height3))
		tmpElem.style.height = height1+"px"; 
	else if ( (height1>=height3) && (height2<height3))
		tmpElem.style.height = height1-24+"px";
	
		//alert("tmpElem="+tmpElem.style.height);
}

function setHeight3(name1, name2){
	var tmpElem = get_element(name1);
	var height1 = getHeight(name1);
	var height2 = getHeight(name2);
	
	//alert ('left : ' + height1);
	//alert ('right: ' + height2);
	
	if(height1<height2 && (height2 - height1 > 24))
		tmpElem.style.height = height2-24+"px";
	else tmpElem.style.height = height1+"px";
	
}

function openNewWinNoOptions(url,w,h){
	myWidth = 800;
	myHeight = 600;
    
	if(url != null){//if url is supplied continue
		if(w != null){myWidth=w;}	//define w if it is not already defined
		if(h != null){myHeight=h;}	//define h if it is not already defined
		window.open(url,'_blank','width='+ this.myWidth +',height='+this.myHeight+',resizable=no,scrollbars=no'+
				',toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
	}else{//tell the user that no parameters have been passed.
		window.alert("No URL specified. - Cannot continue");
	}
}

function addBtmShadow(name1,name2){
	var tmpElem1 = get_element(name1);
	var tmpElem2 = get_element(name2);
	var height = getHeight(name1);
	
	//alert('wrapper ='+height);
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	if(height<myHeight){
		var oldHTML = tmpElem2.innerHTML;
		var newHTML = "<img src='../images/bottomShadow.jpg'>";
		tmpElem2.innerHTML = newHTML;
	}

}

function hideSeperator1(sep1,sep2, image2){
    //alert("image2 " + image2);
    var tmpSep1 = get_element(sep1);
    var tmpSep2 = get_element(sep2);
 
     tmpSep1.style.background = "url(" + image2 +") repeat-x top left;";
     tmpSep2.style.background = "url(" + image2 +") repeat-x top left;";
}

function showSeperator1(sep1,sep2){
    var tmpSep1 = get_element(sep1);
    var tmpSep2 = get_element(sep2);
    
   tmpSep1.style.background="none";
   tmpSep2.style.background="none";
}

var dd;

function hideSeperator2(sep1, image1){
    //alert("image1 " + image1);
    var tmpSep1 = document.getElementById(sep1);  
    tmpSep1.style.background = "url(" + image1 +") repeat-x top left;";
}

function showSeperator2(sep1){
    var tmpSep1 = get_element(sep1); 
     tmpSep1.style.background="none";        
}


function fnBodyOnLoad() {
    //setWidth('breadcrumbText', 'breadcrumbDiv');
    //setHeight2('nav1', 'middlePart', 'rightPart');
    setTimeout('fnRunMediaJQ();', 200);
}
function fnRunMediaJQ() {
    //try { jQuery('a.media').media(); }
    //catch (e) { alert('Could not load media: \n\n' + e.message); }
}


jQuery().ready(function() {
    //fnBodyOnLoad()

    jQuery('a.media').media();

    // See below for new event track
    //jQuery(".takeaction a").click(function() {
        //pageTracker._trackEvent("Pregnancy Predictor Click Through", jQuery(this).text(), "Question 0");
        //return true;
    //});

});


//Made from the pregnancy predictor flash. PageViews are made as the user clicks through the page using the next button
var label;

function callGoogleTrack(Page) {
    pageTracker._trackPageview('/trying-to-have-a-baby/pregnancy-predictor/' + Page);
}



function  trackPregnancyResultsFromFlash(userAnswers){
	    var category = "Pregnancy Predictor";
   		var actions = "Full Answer String";
		var answers = userAnswers
		 
	 	pageTracker._trackEvent(category, actions, answers, null)
}


function getPPPageFromFlash() {
    
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    var flashMovie = (isIE) ? window["flashMovie"] : document["flashMovie"];
    flashMovie.getUserPage();

    // response from flash will call sendUserPage
}

function sendUserPage(frameNumber) {
    var category = "Pregnancy Predictor";
    var actions = "Surprised by Results Click Through";
    var question;

    var link = jQuery(".takeaction a." + label)

    switch(frameNumber)
    {
    case 1:
        //execute code block 1
        question = 1;
        break;
    case 10:
        question = 2;
        break;
    case 19:
        question = 3;
        break;
    case 28:
        question = 4;
        break;
    case 37:
        question = 5;
        break;
    case 46:
        question = 6;
        break;
    case 55:
        question = -1;
        break;
    }


    try {
        pageTracker._trackEvent(category, actions, jQuery(link).text(), question)
        setTimeout('document.location = "' + jQuery(link).attr("href") + '"', 500)
    } catch (err) { }
    
    
    
    
}

jQuery().ready(function() {
    // capture all links from the takaction module on the pregnancy predictor page. 
    // Get the page the user is on the pp module and track as an event with google.
    jQuery(".takeaction a").click(function() {
        label = jQuery(this).attr("class");
        getPPPageFromFlash();
        return false;
    });
});
