function check_input(){
    var Correct = true;
    var email = document.emailForm.email.value;
    var name = document.emailForm.name.value;
    var msgbody = document.emailForm.msgbody.value;
    if(name.length < 2){
        alert("Please enter your name");
        return false;
    }
    if(!((email.indexOf(".") > 2) && (email.indexOf("@") > 0))){
        alert("Please enter an valid email address.");
        return false;
    }
    if(msgbody.length < 2){
        alert("Please enter your message");
        return false;
    }
    var inputElement = document.createElement("input");
    inputElement.type = "hidden";
    inputElement.name = "action";
    inputElement.value = "sendcontact";
    document.emailForm.appendChild(inputElement);
    return Correct;
}
function getPosition(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = leftValue;
    return parseInt(finalvalue);
}
function getYPosition(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = topValue;
    return parseInt(finalvalue);
}
function when_ready(readyCall) {
                if(document.addEventListener)
                    document.addEventListener("DOMContentLoaded",function() {
                        document.removeEventListener("DOMContentLoaded",arguments.callee,false);
                        readyCall();
                    },false);
                else if(document.attachEvent) {//for IE
                    if(document.documentElement.doScroll && window.self==window.top) {
                        (function() {
                            try {
                                document.documentElement.doScroll("left");
                            }catch(ex) {
                                setTimeout(arguments.callee,1);
                                return;
                            }
                           readyCall();
                        })();
                    }else {//maybe late but also for iframes
                        document.attachEvent("onreadystatechange",function() {
                            if(document.readyState==="complete") {
                                document.detachEvent("onreadystatechange", arguments.callee);
                                readyCall();
                            }
                        });
                    }
                }
}

function valign_menubar(){
    var mainpage = document.getElementById("mainpage");
    var leftValue = getPosition(mainpage);
    document.getElementById("menubar").style.left = leftValue + 1 +  "px";
    document.getElementById("menubar").style.visibility = "visible";
    scrollable.init();
     var window_width = alertSize();
    if(window_width < (95 * 12 +2)){ document.getElementById("menubar").style.width =window_width - 18 + "px";}
    
     var window_height = getWindowHeight();
     var followY = getYPosition(document.getElementById("follow_anchor"));
     var footerY = getYPosition(document.getElementById("footer_padding"));
     var diff = window_height + followY - footerY - 64;
     if(diff> 0)
    document.getElementById("footer_padding").style.height = ( window_height + followY - footerY - 64 )+ "px";

    
}
function do_resize(){
    valign_menubar();
    var window_width = alertSize();
    if(95 * 12 + 1 > window_width  ){ document.getElementById("menubar").style.width =window_width - 18 + "px";}
    else{ document.getElementById("menubar").style.width=95 + "em";}
}
function start_roll(val){
    scrollable.do_scroll(val);
}
var a,b,c,d,e,f,g,h;
var scrollable = { 
    "selected" : "",
    "clicked" : "",
    "page" :{},
    "init" : function(){
        this.page = document.getElementById("page");
        a = document.getElementById("a");
        b = document.getElementById("b");
        c = document.getElementById("c");
        d = document.getElementById("d");
        e = document.getElementById("e");
        f  = document.getElementById("f");
        g = document.getElementById("g");
        h = document.getElementById("h");
    },
    "clicked_on": function(){
        a.className = "off"; c.className = "off"; e.className = "off"; g.className = "off";
        if(this.clicked == "project_anchor"){
             b.className = "on"; f.className = "on";d.className = "off"; h.className = "off";   
        }else{
             d.className = "on"; h.className = "on";b.className = "off"; f.className = "off";   
        }
    },
    "scroll_to" : function(targetid){
        this.clicked = targetid;
        this.clicked_on();
        var targetObj = document.getElementById(targetid);

        var targetPos = getYPosition(targetObj)  - 70;
        var curPos = parseInt(this.page.scrollTop)  ;

        var distance = (targetPos > curPos) ? targetPos - curPos : curPos - targetPos;
        if(distance == 0){
            return;
        }
        if(distance < 100){
            this.page.scrollTop = targetPos;
            return;
        }
        var speed = Math.round(distance / 30);
        var step = Math.round(distance / 25);
        
        var timer = 0;
        var leapY =(targetPos > curPos) ? curPos + step : curPos - step;
        //alert(curPos + " -  " + targetPos + " = " + distance + "     leap = " + leapY);
        
        if(targetPos > curPos){
            for(var i = curPos; i < targetPos; i+= step){
                setTimeout("start_roll(" + leapY +")" , timer * speed);
                leapY += step;
                if(leapY > targetPos) leapY = targetPos; timer++;
            }return ;
        }
        for(var i = curPos; i > targetPos; i-= step){
            setTimeout("start_roll(" + leapY +")" , timer * speed);
            leapY  -= step;
            if(leapY < (targetPos )) leapY = targetPos; timer++;
        }
    },
    "do_scroll" : function(val){
        this.page.scrollTop = val;
    }
}

function do_scroll(){
    var mainpage = document.getElementById("mainpage");
    alert(getYPosition(mainpage));

    var project_anchor = document.getElementById("project_anchor");
    alert(getYPosition(project_anchor));
    mainpage.style.marginTop = "-100px";
    alert(getYPosition(project_anchor));
}

function alertSize() {
  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;
  }
  //window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
    return myWidth;
}
function getWindowHeight() {
  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;
  }
  //window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
    return parseInt(myHeight);
}
