var isfont =false;
var vwrpwidth,vleftwidth,vrightwidth,vhead, leftmarginright, rightmarginright;;
var bkhead,bkwrapper,bkleft, bkright, bkfooter, bkbottom;

function calValues() {

var vwraper,vleft,vright, ve;

ut = x1.unit;

var r = (ut=="em") ? getfontSizeRadio() : 1;

ve = x3.values.mid;
vwraper =x1.values.mid;
vleft =x2.values.mid;

var up = (ut=="em") ? r : 1;

  if (ut=="%") {
    vright = ((100 - vleft -ve)< 0) ? 0 : 100 - vleft - ve;
    }
    else
    {
    vright = ((vwraper - vleft -ve)/up < 0) ? 0 : (vwraper - vleft - ve)/up;
    }
    
 leftmarginright = (ut=="px") ? parseInt(ve/up) : formatDecimals(ve/up,2);
 
vwrpwidth = (ut=="em") ? formatDecimals(vwraper/up,2) : parseInt(vwraper/up);
vleftwidth = (ut=="em") ? formatDecimals(vleft/up,2) : parseInt(vleft/up);
vrightwidth = (ut=="em") ? formatDecimals(vright,2) : parseInt(vright);

vrightwidth = (ut=="%") ?  vrightwidth-0.5 : vrightwidth;
$("wrp").style.width = vwrpwidth + ut;
$("left").style.width = vleftwidth + ut;

$("left").style.marginRight = leftmarginright + ut;
$("right").style.width = vrightwidth + ut;
writetotxtarea ();
}

var nt = 0;
function anotherclassname() {

nt = parseFloat(nt) + 1;
var str = $("html0").value;
$("html0").value = str.replace(/\d*\s*\"\s*>/g,nt+'">');
writetotxtarea();
}

function writeJS(){

nt =0;
 $("html0").value = layouthtml();
}

var tmpcode,clsbottom,lsheader,clswrapper,clsleft,clsright,clsfooter;
function writetotxtarea () {

var str = $("html0").value;
var vclass = str.match(/[\"\'](\w+)[\"\']/g);
if (vclass.length==5) {
    clswrapper = vclass[0].replace(/\"/g,"");
    clsheader = vclass[1].replace(/\"/g,"");
    clsleft = vclass[2].replace(/\"/g,"");
    clsright = vclass[3].replace(/\"/g,"");
    clsfooter = vclass[4].replace(/\"/g,"");
}
else
{
    clswrapper ="wrapper";
    clsheader ="header";
    clsleft = "left";
    clsright = "right";
    clsfooter = "footer";
}

getstartlayoutbkcolors();
var vleftmarginright = (leftmarginright==0) ? "" : "   margin-right: " + leftmarginright + ut+";" + "\n";

tmpcode = "." + clswrapper + "{"+ "\n"
			+ "   margin: 0px auto;" + "\n"			
			+ "   width: " + vwrpwidth + ut+";" + "\n"
			+ "   background-color: " + bkwrapper + "\n"
			+ "}" + "\n"
            +  "." + clsheader  + "{" + "\n"
            + "   float: left;" + "\n"
            + "   width: 100%;"  + "\n"  + vhdheight   
            + "   background-color: " + bkhead + "\n"
            + "}" + "\n"
			+ "." + clsleft + "{"+ "\n"
			+ "   float: left;"+ "\n" + vleftmarginright			
			+ "   width: "+ vleftwidth + ut+";" + "\n"	+ vmainheight		
			+ "   background-color: " + bkleft + "\n"
			+ "}" + "\n"
			+ "." + clsright + "{"+ "\n"
			+ "   float: right;"+ "\n" 			
			+ "   width: "+ vrightwidth + ut+";" + "\n" + vmainheight		
			+ "   background-color: " + bkright + "\n"
			+ "}" + "\n"
			+ "." + clsfooter + "{" + "\n"
			+ "   float: left;" + "\n"
            + "   width: 100%;" + "\n"  + vftheight          
			+ "   background-color: " + bkfooter  + "\n"
			+ "}"  + "\n"
			+ "body {" + "\n"
			+ "   padding: 0px;" + "\n"
			+ "   margin: 0px;" + "\n"
			+ "   font-size: " + vfont + ";" + "\n"
			+ "   background-color: " + bkbottom  + "\n"
			+ "}"  + "\n";
			
outputcode();

}

var vhdheight="";
var vmainheight="";
var vftheight="";
function changeheight() {
var mm = parseInt($("heith").value);
vhdheight = ((mm !="NaN") && (mm >0)) ? "   height: " + mm + "px;" + "\n" : "";

if (vhdheight!="") $("hd1").style.height = mm + "px";
mm = parseInt($("heitm").value);
vmainheight =((mm !="NaN") && (mm >0)) ? "   height: " + mm + "px;"+ "\n" : "";
if (vmainheight!="") $("left").style.height = mm + "px";
if (vmainheight!="") $("right").style.height = mm + "px";

mm = parseInt($("heitf").value);
vftheight = ((mm !="NaN") && (mm >0)) ? "   height: " + mm + "px;"+ "\n" : "";
if (vftheight!="") $("ft1").style.height = mm + "px";
writetotxtarea();
}

function outputcode() {
if ( tmpcode==null) return;
var csscode;

if ($("is_style").checked==true) {
csscode = "<style type='text/css'>" + "\n"	+ tmpcode + "</style>";		
} else{
csscode = tmpcode;
}

if ($("is_html").checked==true) {

csscode = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + "\n"
			+ '<html xmlns="http://www.w3.org/1999/xhtml">' + "\n"
			+ '<head>' + "\n"
			+ '<title>2 Column CSS Layout - concise design</title>' + "\n"
			+ "<style type='text/css'>" + "\n"	+ tmpcode + "</style>" + "\n"
			+ '</head>' + "\n"
			+ '<body>' + "\n"
			+ '<div class="' + clswrapper + '">' + "\n"
			+ '    <div class="' + clsheader + '">' + "\n"
			+ '        header' + "\n"
			+ '    <\/div>'  + "\n"  
			+ '        <div class="' + clsleft + '">' + "\n"
			+ '            left' + "\n"
			+ '        <\/div>' + "\n"
			+ '        <div class="' + clsright + '">' + "\n"
			+ '            right' + "\n"
			+ '        <\/div> ' + "\n"
			+ '    <div class="' + clsfooter + '">' + "\n"
			+ '        footer' + "\n"
			+ '    <\/div>' + "\n"
			+ '<\/div>' + "\n"
			+ '</body>' + "\n"
			+ '</html>' + "\n"
}

$("css0").value = csscode;

}

function layouthtml() {
var str='';
str+='	<div class="wrapper">' + "\n";
str+='	    <div class="header">' + "\n";
str+='	        header' + "\n";
str+='	    <\/div> ' + "\n";    
str+='	    <div class="left">' + "\n";
str+='	        left' + "\n";
str+='	    <\/div>' + "\n";
str+='	    <div class="right">' + "\n";
str+='	        right' + "\n";
str+='	    <\/div> '+ "\n";
str+='	    <div class="footer">' + "\n";
str+='	        footer' + "\n";
str+='	    <\/div>' + "\n";
str+='	<\/div>';
return str;
}

function unitclick(e) {
e = (e) ? e : ((window.event) ? window.event : "");
var o = getTargetElement(e); 

var ut = o.id;

x1.newunit=o.id;
x1.convertunit();
x2.newunit=o.id;
x2.convertunit();
x3.newunit=o.id;
x3.convertunit();
 
$("emfont").style.display = (ut=="em") ? "block" : "none";
}

function init() {
  
   var el =  $("unb").getElementsByTagName("li");      
  for(var i=0; i<el.length; i++){
  el[i].onclick = fontunit;
  }
   var el =  $("uns").getElementsByTagName("input"); 
  for(var i=0; i<el.length; i++){
  el[i].onclick = unitclick;
  }
  
  var e = $$($("up"),"div");

for(var i=0; i<e.length; i++){ 
e[i].onclick = fullscreen;

}

var ee = $$($("down"),"div");
for(var i=0; i<ee.length; i++){ 
ee[i].onclick = fullscreen;


}
 }

var ww,w,ut,x1,x2,x3,utfont;
var vfont;
var sldcolor = "#33ff33";

x1 = new slider();
x2 = new slider();
x3 = new slider();
x4 = new slider();

window.onload = function(){
start();
ut = "px";
utfont ="em";
vfont = "90%";
$(ut).checked =true;

ww = parseFloat(window.screen.width);
w = getstartValues(ut,1);
var g = getstartValues(ut,2);

x1.init({id:"point1",hassteparrows:true,style:{backgroundColor:"red",width:"300px"},
pointer:{backgroundColor:"#6699cc"},values:{min:10,mid:w,max:w,fontSize:"10px"}
,fire:calValues
,unit:"px"
});

x2.init({id:"point2",hassteparrows:true,style:{backgroundColor:"red",width:"300px"},
pointer:{backgroundColor:"#6699cc"},values:{min:10,mid:324,max:w,fontSize:"10px"}
,fire:calValues
,unit:"px"
});

x3.init({id:"gap",hassteparrows:true,style:{backgroundColor:"red",width:"150px"},
pointer:{backgroundColor:"#6699cc"},values:{min:0,mid:20,max:g,fontSize:"10px"}
,fire:calValues
,unit:"px"
});

x4.init({id:"font",style:{backgroundColor:"red",width:"150px"},
pointer:{backgroundColor:"#6699cc"},values:{min:0.5,mid:0.9,max:1,fontSize:"10px"}
,fire:calValues
,unit:"em"
});
var mtab = new movetabs();
mtab.b();
init();
}


function selitem(id, text,bkcolor) {
this.id =id;
this.text = text;
this.bkcolor = bkcolor;
}
var item = new Array;
var t2,t3;
function start() {	

t2 = new Bindtabs("tabco2",0,"click","b");
t2.c();
t3 = new Bindtabs("tabco3",1,"click","b");
t3.c();

getstartlayoutbkcolors();

c0 = new selitem('hd1','head',bkhead);
c1 = new selitem('left','left column',bkleft);
c2 = new selitem('right','right column',bkright);
c3 = new selitem('ft1','footer',bkfooter);
c4 = new selitem('wrp','margin gap',bkwrapper);
c5 = new selitem('btm1','sides column',bkbottom);

item = [c0,c1,c2,c3,c4,c5];
}

function getstartlayoutbkcolors() {

bkhead =getcolor($('hd1'));
bkwrapper = getcolor($('wrp'));
bkleft = getcolor($('left'));
bkright = getcolor($('right'));
bkfooter =getcolor($('ft1'));
bkbottom =getcolor($('btm1'));

}

