function setStyle( type ,rows ){
	makeMenu( type,rows );
	seqMain( type );
	seqVirt( type );
	seqHead( type );
	seqColumDetail( type );
	roundBox ( type );
	seqColum( 'colum1', type );
	seqColum( 'colum2', type );
	imgPosition( type );
}
function imgPosition( type ){
	var img = getElementsByClass( 'left' );
	var img2 = getElementsByClass( 'right' );
	if( img.length != 0 ){
		for( i= 0; i<img.length;i++){
			if(type == 'mirror'){
				img[i].style.cssFloat = 'right';
				img[i].style.styleFloat = 'right';
			}else{
				img[i].style.cssFloat = 'left';
				img[i].style.styleFloat = 'left';
			}
		}
	}
	if( img2.length != 0 ){
		for( i= 0; i<img2.length;i++){
			if(type == 'mirror'){
				img2[i].style.cssFloat = 'left';
				img2[i].style.styleFloat = 'left';
			}else{
				img2[i].style.cssFloat = 'right';
				img2[i].style.styleFloat = 'right';
			}
		}
	}
}
function seqColum( row, type ){

	var colum = document.getElementById( row );
	if( colum != null){
		var columMenu = new Array();
		var allElements = colum.getElementsByTagName("*");
		for( i = 0, j= 0;i < allElements.length; i++){
			if(allElements[i].className == 'side'){
				columMenu[j] = allElements[i];
				j++;
			}
		}
		if(columMenu.length != 0){
			var sumHeight = 0;
			for( i=0; i<columMenu.length; i++ ){
				sumHeight += $(columMenu[i]).height()+5; 
			}
			for( i=0; i<columMenu.length; i++){
				var distance = 0;
				if( type == 'mirror' ){
					columMenu[i].style.position = 'relative';
				}else{
					columMenu[i].style.position = '';
				}
				for(j=0;j<i+1;j++){
					distance += $(columMenu[j]).height()+5;
				}
				distance = -distance*2+$(columMenu[i]).height()+5+sumHeight;
				if( type == 'mirror' ){
					columMenu[i].style.top = distance+'px';
				}else{
					columMenu[i].style.top = '';
				}
			}
		}
	}
}
function getElementsByClass(searchClass) {
    var classElements = new Array();
    var allElements = document.getElementsByTagName("*");
    for (i = 0, j = 0; i < allElements.length; i++) {
	if (allElements[i].className == searchClass) {
	    classElements[j] = allElements[i];
	    j++;
	}
    }
    return classElements;
}
function seqColumDetail( type ){
	var colum = getElementsByClass('side');
	if(colum != null ){
		for( i=0; i < colum.length; i++ ){
			var title = colum[i].getElementsByTagName('h2');
			var content = colum[i].getElementsByTagName('ul');
			var line  = content[0].getElementsByTagName('li');
			if( type == 'mirror' ){
				title[0].style.position = 'relative';
				content[0].style.position = 'relative';
				title[0].style.top = $(content[0]).height()+'px';
				content[0].style.top = '-'+$(title[0]).height()+'px';
				var sumLineHeight = 0;
				for( j=0;j<line.length;j++){
					sumLineHeight += $(line[j]).height();
				}
				for( j=0; j<line.length; j++){
					var distance = 0;
					for( k = 0; k<j+1; k++){
						distance += $(line[k]).height();
					}
					distance = -distance*2+$(line[j]).height()+sumLineHeight;
					var lineHeight = $(line[j]).height();
					line[j].style.position = 'relative';
					line[j].style.top = distance + 'px';
				}
			}else{
				title[0].style.position = '';
				content[0].style.position = '';
				title[0].style.top = '';
				content[0].style.top = '';
				for( j=0; j<line.length;j++){
					line[j].style.position = '';
					line[j].style.top = '';
				}
			}
		}
	}
}

function whichIsBigger( a, b){
	if( (a-b) > 0 ){
		return a;
	}else{
		return b;
	}
}
function heightLine(){
	var main = document.getElementById('main');
	var colum1 = document.getElementById('colum1');
	var colum2 = document.getElementById('colum2');
	var mainHeight = parseInt($(main).height());
	var colum1Height = parseInt($(colum1).height());
	var colum2Height = parseInt($(colum2).height());
	var height = whichIsBigger( mainHeight, whichIsBigger(colum1Height,colum2Height));
	height += 'px';
	main.style.height = height;
	colum1.style.height = height;
	colum2.style.height = height;
}
function seqHead( type ){
	var title = document.getElementById('title');
	var titleHeight = $(title).height();
	var explanation = document.getElementById('explanation');
	var explanationHeight = $(explanation).height();
	var menu = document.getElementById('menu');
	if( menu != null){ var menuHeight = $(menu).height();}
	title.style.position = "relative";
	explanation.style.position = "relative";
	if( menu != null){ menu.style.position = "relative";}
	if( type == 'mirror' ){
		if( menu != null){
			title.style.top = menuHeight+'px';
			explanation.style.top = menuHeight+'px';
			menu.style.top = '-'+(titleHeight+explanationHeight)+'px';
		}else{
			title.style.top = '';
			explanation.style.top = '';			
		}
	}else{
		title.style.top = explanationHeight+'px';
		explanation.style.top = '-'+titleHeight+'px';
		if( menu != null){ menu.style.position = '';}
	}
}
function seqVirt( type ){
	var header = document.getElementById('header');
	var headerHeight = $(header).height();
	var middle = document.getElementById('middle');
	var middleHeight  = $(middle).height();
	var footer = document.getElementById('bottom');
	var footerHeight = $(footer).height();
	header.style.position = "relative";
	middle.style.position = "relative";
	footer.style.position = "relative";
	if( type == 'mirror'){
		footer.style.top = '-'+(middleHeight+headerHeight)+'px';
		middle.style.top = footerHeight+'px';
		header.style.top = footerHeight+'px';
	}else{
		header.style.top = '-'+middleHeight+'px';
		middle.style.top = headerHeight+'px';	
		footer.style.position = '';
	}
}
function seqMain( type ){
	var middle = document.getElementById('middle');
	var colum1 = document.getElementById('colum1');
	var colum1Width = $(colum1).width();
	var colum2 = document.getElementById('colum2');
	var colum2Width = $(colum2).width();
	var main = document.getElementById('main');
	var mainWidth = $(main).width();
	if( type == 'mirror' ){
		main.style.position = 'absolute';
		main.style.left = colum2Width+'px';
		colum1.style.position ='absolute';
		colum1.style.left = (mainWidth+colum2Width)+'px';
		colum2.style.position = '';
		colum2.style.left = '';
		heightLine();
	}else{
		main.style.position = 'absolute';
		main.style.left = colum1Width+'px';
		colum1.style.position ='absolute';
		colum1.style.left = '0px';
		colum2.style.position = 'relative';
		colum2.style.left = colum1Width+mainWidth+'px';
		heightLine();
	}
	middle.style.position = 'relative';
}
function makeMenu( type ,rows ){
	if( type == 'mirror'){
		var arrow = 'right';
	}else{
		var arrow = 'left';
	}
	var menu = document.getElementById('menu');
	if( menu != null){
		var headerWidth = $(document.getElementById('header')).width();
		var menuli = menu.getElementsByTagName('li');
		var menuliHeight = $(menuli[0]).height();
		var menuHeight  = ((menuliHeight+4)*Math.floor( menuli.length/rows+0.999 ));
		if( rows < menuli.length ){
			var menuliWidth = Math.floor( headerWidth/rows ) - 4;
		}else{
			var menuliWidth = Math.floor( headerWidth/menuli.length ) - 4;
		}
		for( i =0; i<menuli.length;i++){
			menuli[i].style.width = menuliWidth+'px';
			menuli[i].style.display = 'inline';
			menuli[i].style.cssFloat = arrow;
			menuli[i].style.styleFloat = arrow;
		}
		menu.style.height = menuHeight+'px';
	}
}
function roundBox( type ){
	var arrow;
	if( type == "mirror" ){
		arrow  = "bite bottom 7px";
		arrow2 = "bite top 7px";
	}else{
		arrow  = "top 7px";
		arrow2 = "bottom 7px";
	}
	$('p#explanation').uncorner();
	$('p#explanation').corner( arrow2);
	$('ul.menu li').uncorner();
	$('ul.menu li').corner( arrow );
	$('h3#footer').uncorner();
	$('h3#footer').corner( arrow);
	var colum1 = document.getElementById( 'colum1' );
	if( colum1 != null){
		h2s = colum1.getElementsByTagName( 'h2' );
		for( $i = 0; $i<h2s.length; $i++ ){
			$( h2s[$i] ).uncorner();
			$( h2s[$i] ).corner( arrow );
		}
	}
	var colum2 = document.getElementById( 'colum2' );
	if( colum2 != null){
		var colum2 = document.getElementById( 'colum2' );
		h2s = colum2.getElementsByTagName( 'h2' );
		for( $i = 0; $i<h2s.length; $i++ ){
			$( h2s[$i] ).uncorner();
			$( h2s[$i] ).corner( arrow );
		}
	}
}

