var currentClip = "bottom_portfolio_i";
var bottomOpen = false;
var timer;

var originalText = "We built a sample content management system to show you how easy it is to manage bodies of content on your website. These systems are capable of editing all different types of multimedia content. Imagine that. Try me!";
var editable = false;


function validPage(id){
	switch(id){
		case "cms":
			return true;
			break;
		case "bottom_learn_more_interactive":
			return true;
			break;
		case "bottom_learn_more_print":
			return true;
			break;
		case "bottom_learn_more_video":
			return true;
			break;
		case "bottom_learn_more_innovation":
			return true;
			break;
		case "bottom_learn_more_marketing":
			return true;
			break;
		case "bottom_relations":
			return true;
			break;
		case "bottom_portfolio_i":
			return true;
			break;
		case "bottom_portfolio_p":
			return true;
			break;
		case "bottom_portfolio_v":
			return true;
			break;
		case "bottom_portfolio_m":
			return true;
			break;
		case "showAlert":
			return true;
			break;
		case "contactus":
			return true;
			break;
		case "clientlogin":
			return true;
			break;
		default:
			return false;
	}
	
}

SWFAddress.onChange = function(){
	if(validPage(SWFAddress.getValue().toString().split("/")[1])){
		if(SWFAddress.getValue().toString().split("/")[1] == "contactus"){
			shade('contact');
		}else if(SWFAddress.getValue().toString().split("/")[1] == "clientlogin"){
			shade('login');
		}else{
			unShade();
			openIt(SWFAddress.getValue().toString().split("/")[1]);
		}
	}
}

function page_init(){
		if(window.location.toString().split("?").length > 1){
			var pvar = window.location.toString().split("?")[1].split("=")[0];
		}
		
		document.getElementById("cmstest").style.wordWrap = "break-word";
		document.getElementById('cmstest').innerHTML = getCookie('cmsTBValue');
		if(document.getElementById('cmstest').innerHTML == ""){
			document.getElementById('cmstest').innerHTML = originalText;
			setCookie('cmsTBvalue',originalText);
		}else{
			document.getElementById('cmstest').innerHTML = getCookie('cmsTBValue');
		}
		
		
		if(validPage(pvar)){
		switch(pvar){
			case "cms":
				openIt('bottom_learn_more_interactive');
				slideLearnMoreTo('lm_interactive_',1,2);
				break;
			case "showAlert":
				shade("alertbox",window.location.toString().split("?")[1].split("=")[1]);
				break;
			default:
				openIt(pvar);
				break;
		}
		}
}

function setCMSValue(){
	if(trim(document.cmsform.formfield.value) == ""){
		document.cmsform.formfield.value = "You didn't type anything :( Try again?";
		setTimeout("document.cmsform.formfield.value = '';document.cmsform.formfield.focus();",1500);
	}else{
	document.getElementById('editcontrols').style.display = "none";
	document.getElementById('editme').style.display = "none";
	document.getElementById("cmstest").style.wordWrap = "break-word";
	setCookie('cmsTBValue',document.cmsform.formfield.value);
	document.getElementById('cmstest').innerHTML = document.cmsform.formfield.value + "<br><font style='margin-top:20px;'><i>Nice job! Now <a href='http://mocapoke.com/syck/index.php?cms'>refresh</a> your browser and navigate back here...</i></font>";
	editable = false;
	}
}

function resetCMSValue(){
	document.getElementById('editcontrols').style.display = "none";
	document.getElementById('editme').style.display = "block";
	document.getElementById("cmstest").style.wordWrap = "break-word";
	setCookie('cmsTBValue',originalText);
	document.getElementById('cmstest').innerHTML = originalText;
	editable = false;
}

function makeEditable(){
	document.getElementById('editcontrols').style.display = "block";
	document.getElementById('editme').style.display = "none";
	if(editable == false){
		editable = true;
		document.getElementById('cmstest').innerHTML = "<form name='cmsform'><textarea maxlength='220' onkeyup='return ismaxlength(this)'"+
			" style='"+
			"font-family:Arial;"+
			"line-height: 18pt;"+
			"font-size:9pt;"+
			"width:450px;"+
			"word-wrap:break-word;"+
			"color:#7c7a7a;"+
			"height:100px;"+
			"border:8px solid red;"+
			"background-color:##fff;'"+
		 	"name='formfield' class='cmstext'>"+document.getElementById('cmstest').innerHTML+"</textarea></form>";
		document.cmsform.formfield.focus();
		document.cmsform.formfield.select();
	}else{
		editable = false;
	}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function swapClips(newClip){
	if(currentClip != newClip){
		
		new Effect.Fade(currentClip,{duration:0.2});
	
		currentClip = newClip;
		setTimeout("changeAndFadeIn("+newClip+")",200);
	}
}

function changeAndFadeIn(divToFade){
	new Effect.Appear(divToFade,{duration:0.2});
}

function slideLinkUp(linkID){
	new Effect.Morph(linkID,{style: 'top:273px; height:93px;', duration:0.5});
}


function openIt(pageId) {
	 switch(pageId){
	 	case "bottom_learn_more_interactive":
	 		moveTo(0);
	 		document.title = "Syck | Web Services";
	 		SWFAddress.setValue("bottom_learn_more_interactive");
	 		break;
	 	case "bottom_learn_more_print":
	 		moveTo(1);
	 		document.title = "Syck | Design Services";
	 		SWFAddress.setValue("bottom_learn_more_print");
	 		break;
	 	case "bottom_learn_more_video":
	 		moveTo(2);
	 		document.title = "Syck | Video Services";
	 		SWFAddress.setValue("bottom_learn_more_video");
	 		break;
	 	case "bottom_portfolio_i":
	 		moveTo(3);
	 		document.title = "Syck | Portfolio";
	 		SWFAddress.setValue("bottom_portfolio_i");
	 		break;
	 	case "bottom_learn_more_innovation":
	 		moveTo(4);
	 		document.title = "Syck | About Branding";
	 		SWFAddress.setValue("bottom_learn_more_innovation");
	 		break;
	 	case "bottom_learn_more_marketing":
	 		moveTo(5);
	 		document.title = "Syck | About Marketing";
	 		SWFAddress.setValue("bottom_learn_more_marketing");
	 		break;
	 	case "bottom_relations":
	 		moveTo(6);
	 		document.title = "Syck | Public Relations";
	 		SWFAddress.setValue("bottom_relations");
	 		break;
	 }
     if(!bottomOpen){
     	new Effect.Morph('viewbox', {
  		style: 'height:601px;', // CSS Properties
  		duration: 0.8 // Core Effect properties
		});
			setTimeout("scrollWindowTo('viewbox'); bottomOpen=true;",800);
	}else{
		if(f_scrollTop()+f_clientHeight() < document.body.scrollHeight){
			scrollWindowTo('viewbox'); 
			bottomOpen=true;
		}
	}
	swapClips(pageId);
}

var topBottomLinks = new Array("web_bottom_link","relations_bottom_link","print_bottom_link","video_bottom_link","home_bottom_link","innovation_bottom_link","marketing_bottom_link");

function dropAllLinks(){
	for(var i = 0; i<topBottomLinks.length; i++){
		new Effect.Morph(topBottomLinks[i],{style: 'top:340px;height:1px;', duration:0.2});
	}
}

function scrollWindowTo(objectId){
	new Effect.ScrollTo(objectId);
}

function blindIt(pageId){
	new Effect.BlindUp(pageId, { duration: 3.0 });
}
function closeIt() {
	bottomOpen = false;
     new Effect.Morph('viewbox', {
  		style: 'height:1px;', // CSS Properties
  		duration: 0.8 // Core Effect properties
		});
}
function moveTo(val){
	dropAllLinks();
	switch(val){
		case 0:
			setTimeout("slideLinkUp(\"web_bottom_link\")",1200);
	 		document.title = "Syck | Web";
			break;
		case 1:
			setTimeout("slideLinkUp(\"print_bottom_link\")",1200);
	 		document.title = "Syck | Design";
			break;
		case 2:
			setTimeout("slideLinkUp(\"video_bottom_link\")",1200);
	 		document.title = "Syck | Video";
			break;
		case 3:
			setTimeout("slideLinkUp(\"home_bottom_link\")",1200);
	 		document.title = "Syck | Ideas on Purpose";
			break;
		case 4:
			setTimeout("slideLinkUp(\"innovation_bottom_link\")",1200);
	 		document.title = "Syck | Process";
			break;
		case 5:
			setTimeout("slideLinkUp(\"marketing_bottom_link\")",1200);
	 		document.title = "Syck | Marketing";
			break;
		case 6:
			setTimeout("slideLinkUp(\"relations_bottom_link\")",1200);
	 		document.title = "Syck | Public Relations";
			break;
	}
	new Effect.Move('main-content', { x: - val * 980 +2940, mode: 'absolute', duration:1.5});
}

var markImagesArray = new Array();
markImagesArray[0] = new Array("G7_Mark_ComAsia");
markImagesArray[1] = new Array("G7_Mark_DLife");
markImagesArray[2] = new Array("G7_Mark_Wrap");
markImagesArray[3] = new Array("G7_Mark_Street2","G7_Mark_Street111");
markImagesArray[4] = new Array("G7_Mark_Promo");

var folioInterLogos = new Array();
var folioInterBlurbs = new Array();
var folioInterLinks = new Array();
var folioInterPrevs = new Array();

folioInterLogos[1] = "internal_pages/images/Cap_logo.png";
folioInterBlurbs[1] = "Capital Innovations is an employee-owned specialist manager of Infrastructure Investments.";
folioInterLinks[1] = "http://mocapoke.com/client/corpinn";
folioInterPrevs[1] = "internal_pages/images/Cap_inter.jpg";

folioInterLogos[2] = "internal_pages/images/Darq_logo.png";
folioInterBlurbs[2] = "Darqlight studios is a broadcast and motion graphics studio which produces beautiful video excellence.";
folioInterLinks[2] = "http://darqlight.com";
folioInterPrevs[2] = "internal_pages/images/Darq_inter.jpg";

folioInterLogos[3] = "internal_pages/images/elite_logo_plain.png";
folioInterBlurbs[3] = "Elite Billiards is a billiards hall with locations in Milltown & Edison, NJ";
folioInterLinks[3] = "http://elitebilliards.com";
folioInterPrevs[3] = "internal_pages/images/Elite_inter.jpg";

folioInterLogos[4] = "internal_pages/images/Ice_logo.png";
folioInterBlurbs[4] = "Ice Marketing plays a key role in making sure our clients get the exposure they deserve.";
folioInterLinks[4] = "http://icemg.com";
folioInterPrevs[4] = "internal_pages/images/Ice_inter.jpg";

folioInterLogos[5] = "internal_pages/images/Mim_logo.png";
folioInterBlurbs[5] = "Mimexa is an import/export company specializing in hardware sales and distribution.";
folioInterLinks[5] = "http://mimexa.com";
folioInterPrevs[5] = "internal_pages/images/Mimexa_inter.jpg";

folioInterLogos[6] = "internal_pages/images/Moca_logo.png";
folioInterBlurbs[6] = "Mocapoke makes sexy websites. Mocapoke makes your web experience the simplest, most rewarding experience it can be.";
folioInterLinks[6] = "http://mocapoke.com";
folioInterPrevs[6] = "internal_pages/images/Moca_inter.jpg";

folioInterLogos[7] = "internal_pages/images/UNDAGRND_logo_plain.png";
folioInterBlurbs[7] = "Undaground Flavor is a revolutionary apparel company with an urban vibe and a crispity clean presence.";
folioInterLinks[7] = "http://undagroundflavor.com";
folioInterPrevs[7] = "internal_pages/images/Unda_inter.jpg";

folioInterLogos[8] = "internal_pages/images/Winex_logo_plain.png";
folioInterBlurbs[8] = "Winex global is an innovative and ground-breaking wine stock exchange.";
folioInterLinks[8] = "http://winexglobal.com";
folioInterPrevs[8] = "internal_pages/images/Winex_inter.jpg";


function rotateFolioInter(src){
	$('portfolio_rightcol').fade({duration:0.2});
	setTimeout("changeAndFade('"+folioInterPrevs[src]+"')",200);
	document.getElementById('portfolio_logo').src = folioInterLogos[src];
	document.getElementById('portfolio_golink').href = folioInterLinks[src];
	document.getElementById('portfolio_small_text').innerHTML = folioInterBlurbs[src];
}

function swapMarkFolio(src,index){
	
	
	$('folio_mktg_right').fade({duration:0.2});
	
	setTimeout("changeAndFadeMark('"+src+"',"+index+")",200);
}
function changeAndFade(src){
	document.getElementById('portfolio_rightcol').style.backgroundImage = "url('"+src.toString()+"')";
	new Effect.Appear('portfolio_rightcol',{duration:0.2});
}

function changeAndFadeMark(src,index){
	var rString = "";
	for(var i=0;i<markImagesArray[index].length;i++){
		rString += "<a class='mark_link2' href=\"javascript:swapMarkFolio('internal_pages/images/"+markImagesArray[index][i]+".jpg',"+index+");\"></a>";
	}
	if(markImagesArray[index].length > 1){
		document.getElementById("mark_links").innerHTML = rString;
	}else{
		document.getElementById("mark_links").innerHTML = null;
	}
	document.getElementById('folio_mktg_right').style.backgroundImage = "url('"+src.toString()+"')";
	new Effect.Appear('folio_mktg_right',{duration:0.2});
}


function slideLearnMoreTo(lmname,pid,lmid){
	new Effect.Move('learnmore_container'+pid, { x: - (lmid-1) * 980, mode: 'absolute', duration:0.5});
	adjustTabs(lmname,lmid);
}

//TABS
function adjustTabs(lmname,id){
	for(var i = 1; i<=4; i++){
		if(i == id){
			toggleState(lmname+''+i,"selected");
			document.getElementById(lmname+''+i).setAttribute("onMouseOut","toggleState('"+lmname+""+i+"','selected');");
			document.getElementById(lmname+''+i).onmouseout =  new Function("toggleState('"+lmname+""+i+"','selected');");
		}else{
			toggleState(lmname+''+i,"regular");
			document.getElementById(lmname+''+i).setAttribute("onMouseOut","toggleState('"+lmname+""+i+"','regular');");
			document.getElementById(lmname+''+i).onmouseout =  new Function("toggleState('"+lmname+""+i+"','regular');");
		}
	}
}

function toggleState(object,state){
	switch(state){
		case "over":
			document.getElementById(object).style.backgroundPosition = "center left";
			break;
		case "regular":
			document.getElementById(object).style.backgroundPosition = "bottom left";
			break;
		case "selected":
			document.getElementById(object).style.backgroundPosition = "top left";
			break;
	}
	
}

function slidePrintTo(val){
	new new Effect.Move('folio_print_slide', { x: - (val) * 980, mode: 'absolute', duration:0.5});
}


var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
  	
  }
 }

function sndCMSReq(cmstext) {
    xmlhttp.open('post', 'setcms.php?cmsvalue='+cmstext);
    xmlhttp.send(null);
    originalText = cmstext;
}


//PRELOAD ASSETS
if (document.images)
{
  pic1= new Image(520,505); 
  pic1.src="images/right2.png"; 
}

//CLIENT ATTRIBUTES
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}



function shade(boxname,message){
	document.getElementById('relationcontainer').style.display = "block";
	scrollWindowTo('top');
	switch(boxname){
		case 'contact':
			document.title = "Syck | Contact Us";
			SWFAddress.setValue("contactus");
			new Effect.Appear("contactform",{duration:0.6, delay:0.5});
			new Effect.Fade("loginform",{duration:0.6});
			break;
		case 'alertbox':
			new Effect.Appear("alertbox",{duration:0.6, delay:0.5});
			setTimeout("unShade()",3500);
			break;
		case 'login':
			document.title = "Syck | Client Login";
			SWFAddress.setValue("clientlogin");
			new Effect.Fade("contactform",{duration:0.6});
			new Effect.Appear("loginform",{duration:0.6, delay:0.5});
			break;
	}
	new Effect.Appear("shader",{duration:0.6});
}

function unShade(){

	document.title = "Syck | Ideas on Purpose";
	setTimeout("document.getElementById('relationcontainer').style.display = \"none\";",300);
	new Effect.Fade("contactform",{duration:0.3});
	new Effect.Fade("loginform",{duration:0.3});
	new Effect.Fade("alertbox",{duration:0.3});
	new Effect.Fade("shader",{duration:0.6, delay:0.5});
}

function getVar(name)
         {
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
         }

