function prepareWorkSlide() {
	var contentdiv = document.getElementById("content");
	var menudiv = document.getElementById("menu");
	
	var iWidth = window.screen.width;
	
	if (iWidth <= 1024) {
		var nodivs = 4;
	}
	else {
		var nodivs = 6;
	}
	
	var contentdivs = contentdiv.getElementsByTagName("div");
	
	for(i=0;i<contentdivs.length;i++) {
		if(i>=nodivs) {
			contentdivs[i].style.display = "none";
		}
	}
		
	var nextlink = document.createElement("a");
	nextlink.setAttribute("href", "javascript://");
	nextlink.setAttribute("id", "nextlink");
	nextlink.style.display = "block";
	var nextlinktext = document.createTextNode("Next >");
	
	var prevlink = document.createElement("a");
	prevlink.setAttribute("href", "javascript://");
	prevlink.setAttribute("id", "previouslink");
	prevlink.style.display = "none";
	var prevlinktext = document.createTextNode("< Previous");
	
	if(contentdivs.length <= nodivs) {
		nextlink.style.display = "none";
	}
	
	var curlocation = 0;
	var curpage = 1;
	var pages = Math.ceil(contentdivs.length/nodivs);
	
	nextlink.onclick = function() {
		if(curpage < pages) {
			curlocation = curlocation+nodivs;
			++curpage;
			
			hideDivs(curlocation, curlocation+(nodivs-1));
		}
		
		/*alert("Pages: "+pages);
		alert("Curpages:"+curpage);*/
		
		if(curpage == pages) {
			nextlink.style.display = "none";	
		}
		
		if(curpage > 1) {
			prevlink.style.display = "block";
		}
	}
	
	prevlink.onclick = function() {
		var from = curlocation - nodivs;
		var to = curlocation+(nodivs-1)-nodivs;
		
		hideDivs(from, to);
		curlocation = curlocation-nodivs;
		--curpage;
		
		/*alert("Pages: "+pages);
		alert("Curpages:"+curpage);*/
		
		if(curpage == 1) {
			prevlink.style.display = "none";
		}
		
		if(curpage < pages) {
			nextlink.style.display = "block";
		}
	}
	
	nextlink.appendChild(nextlinktext);
	contentdiv.appendChild(nextlink);
	
	prevlink.appendChild(prevlinktext);
	contentdiv.appendChild(prevlink);
	
}

function hideDivs(from, to) {
	var contentdiv = document.getElementById("content");
	var contentdivs = contentdiv.getElementsByTagName("div");
	
	for(i=0;i<contentdivs.length;i++) {
		if(i>=from && i<=to) {
			contentdivs[i].style.display = "block";
		} else if (i>to || i<from) {
			contentdivs[i].style.display = "none";
		}
	}
}

// open new window
function externalLinks() {
 if (!document.getElementsByTagName("a")) return false;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(externalLinks);
addLoadEvent(prepareWorkSlide);
	
	
	
	
	