var dropdownIntervalID = 0;
var dropdownHeight = 1;
var DROPDOWNMAXHEIGHT = 1;
var dropingdown = false;
var dropdownSpeed = 8;
var thePage = 1;

function SetWhiteContentUp()
{
	if(dropdownHeight == DROPDOWNMAXHEIGHT)
	{
	    document.getElementById('minbtn'+thePage).src="images/btn_cf_max.png";
        dropdownHeight = 1;
	    document.getElementById('cf_page'+thePage).style.height = dropdownHeight + 'px';
	}
}
// called when min/max button for white dropdown is pressed. expands or contracts the div.
function Drop(poh,pos,page)
{
    if(dropingdown) return;
    dropingdown = true;

	thePage = page
    DROPDOWNMAXHEIGHT = poh;
    dropdownSpeed = pos;
//alert("current page:" + thePage + "\nmaximum height:" + DROPDOWNMAXHEIGHT + "\ndropdown speed:" + dropdownSpeed + "\ncurrent height:" + dropdownHeight)
    if(dropdownHeight == DROPDOWNMAXHEIGHT)
        dropdownIntervalID = setInterval('DropUpRun()', 11);
    else
    {
        document.getElementById('minbtn'+thePage).src="images/btn_cf_min.png";
        dropdownIntervalID = setInterval('DropDownRun()', 11);
    }
}
// helper function for Drop().
function DropUpRun()
{
    slider = document.getElementById('cf_page'+thePage);
    if(dropdownHeight <= 1)
    {
        dropingdown = false;
        dropdownHeight = 1;
        slider.style.height = '1px';
        clearInterval(dropdownIntervalID);
        document.getElementById('minbtn'+thePage).src="images/btn_cf_max.png";
    }
    else
    {
        dropdownHeight -= dropdownSpeed;
        if(dropdownHeight < 1)
            dropdownHeight = 1;
        slider.style.height = dropdownHeight + 'px';
    }
}
// helper function for Drop().
function DropDownRun()
{
    slider = document.getElementById('cf_page'+thePage);
    if(dropdownHeight >= DROPDOWNMAXHEIGHT)
    {
        dropingdown = false;
        dropdownHeight = DROPDOWNMAXHEIGHT;
        slider.style.height = DROPDOWNMAXHEIGHT+ 'px';
        clearInterval(dropdownIntervalID);
    }
    else
    {
        dropdownHeight += dropdownSpeed;
        if(dropdownHeight > DROPDOWNMAXHEIGHT)
            dropdownHeight = DROPDOWNMAXHEIGHT;
        slider.style.height = dropdownHeight + 'px';
   }
}
var currentPage = 1;
// sets the current and previous page. changes the color of the Ch buttons (orange and blue). shows the correct page (and bookmark), and sets the correct height of the dropdown.
function gotoPage(pageNum)
{
    SetWhiteContentUp();
    previousPage = currentPage;
    currentPage = pageNum;
    document.getElementById('btn_cf_' + previousPage).src="images/btn_cf_" + previousPage + "off.png";
    document.getElementById('btn_cf_' + currentPage).src="images/btn_cf_" + currentPage + "on.png";
	document.getElementById('cf_picture').style.backgroundImage = 'url(images/image_0' + jssection + '_' + currentPage + '.jpg)';
    displayPage();
    displaySubPage();
}
// displays the content that goes into the white dropdown.
function displayPage() {
document.getElementById('cf_page' + previousPage).style.display = 'none';
document.getElementById('btncontain' + previousPage).style.display = 'none';

    if(currentPage == 1) // remove IF when you want pages other than the first to display
    {
        document.getElementById('cf_page' + currentPage).style.display = 'block';
        document.getElementById('btncontain' + currentPage).style.display = 'block';
    }
}
// a bookmark for a page displays additional content (like a flash element). this shows a bookmark for the page it resides on.
function displaySubPage() {
	document.getElementById('bookmark'+(currentPage-1)).style.display = 'block';
	document.getElementById('bookmark'+(previousPage-1)).style.display = 'none';
}
// clears the default text 'username' found in the textfield for the Client Login popup.
function checkUsernameFocus() { if(document.getElementById('username').value == 'username') document.getElementById('username').value = '' }
// fills the textfield with 'username' if the textfield is left blank for the Client Login popup.
function checkUsernameBlur() { if(document.getElementById('username').value == '') document.getElementById('username').value = 'username'; }
// swaps the fake password textfield with a real one (that hides characters typed in) for the Client Login popup.
function checkPasswordFocus()
{
	document.getElementById('phopassword').style.display = 'none';
	document.getElementById('password').style.display = 'block';
	document.getElementById('password').focus();
}
// swaps back to fake password textfield if the user doesn't input anything into the true password textfield.
function checkPasswordBlur()
{
	if(document.getElementById('password').value == '')
	{
		document.getElementById('password').style.display = 'none';
		document.getElementById('phopassword').style.display = 'block';
	}
}
// handles the Client Login popup. hiding it onload. also revealing and hiding based on clicking "Client Login" and the "X".
$(document).ready(function(){
    $("#floatinglogin").hide();
    $("#floatinglogin #closeLogin").click(function(){
      $(this).parents("#floatinglogin").animate({ opacity: "hide" }, "slow");
    });
    $("#openLogin").click(function(){
      $("#floatinglogin").animate({ opacity: "show" }, "slow");
    });
});

// function to handle What's a Copperfin dropdown.
$(function() {
    $("#sliderclick").click(function(){
    if(document.getElementById('cf_contentSlider_frame').style.height != "262px")
    {
        $("#cf_contentSlider_frame").animate({ 
        height: "270px"
        }, 600 ).animate({ 
        height: "262px"
        }, 250 );
        
        $("#cf_blackBar_frame").animate({ 
        top: "270px"
        }, 600 ).animate({ 
        top: "262px"
        }, 250 );
    }
    else
    {
        $("#cf_contentSlider_frame").animate({ 
        height: "270px"
        }, 250 ).animate({ 
        height: "1px"
        }, 600 );

        $("#cf_blackBar_frame").animate({ 
        top: "270px"
        }, 250 ).animate({ 
        top: "0px"
        }, 600 );
    }
    });
});

// function to handle What's a Copperfin dropdown (home).
$(function() {
    $("#sliderclick_home").click(function(){
    
    $("#cf_contact_home").css('z-Index', '100');
    
    if(document.getElementById('cf_contentSlider_frame_home').style.height != "262px")
    {
        $("#cf_contentSlider_frame_home").animate({ 
        height: "270px"
        }, 600 ).animate({ 
        height: "262px"
        }, 250 );
        
        $("#cf_blackBar_frame_home").animate({ 
        top: "270px"
        }, 600 ).animate({ 
        top: "262px"
        }, 250 );
    }
    else
    {
        $("#cf_contentSlider_frame_home").animate({ 
        height: "270px"
        }, 250 ).animate({ 
        height: "1px"
        }, 600 );

        $("#cf_blackBar_frame_home").animate({ 
        top: "270px"
        }, 250 ).animate({ 
        top: "0px"
        }, 600 );
    }
    });
});
