// JavaScript Document
// łśćążsó
var DebugMode=true; //Show Alerts

function setBlur(){ 
	var x = document.getElementsByTagName('a');
	
	for (var i=0;i<x.length;i++){
		x[i].onfocus = function () { this.blur(); }
	}
}

function ReDisplay(id){
	if( id==ActiveMenu){return 0;}
	var Element=document.getElementById(id);
	if(Element.style.display=='none'){ Element.style.display='block';}
	else{Element.style.display='none';}
}

function MM_preloadImages() { //v3.0  
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function CheckFormContact(){
	var error = "";
	if (document.formb.formb_name.value==""){ error += "Please enter Your Name."; }
	if (document.formb.formb_email.value==""){ error += "\nPlease enter e-mail.";	}
	if (document.formb.formb_question.value==""){ error += "\nPlease enter Question.";}
	if (error!= "") { alert(error); return false;	}
	else { return true;	}
}

document.getElementsByClassName = function(clsName){ /*IE PATH*/
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

/* ================================================================================== */
/* =============================== Portfolio [START] ================================ */
/* ================================================================================== */
function OpacityOver(This){
	try{
		This.style.filter='alpha(opacity=40)';
		This.style.opacity='0.4';
	}catch(err){ if(DebugMode==true){ alert('OpacityOver: '+err); } }
}

function OpacityOut(This){
	try{
		This.style.filter='alpha(opacity=100)';
		This.style.opacity='1';
	}catch(err){ if(DebugMode==true){ alert('OpacityOut:' +err); } }
}


function portulSetOpacity(ID){
	try{
		var i, mainClass, elements;
		if(!ID){
			mainClass=document.getElementsByClassName('portul');
			if((mainClass.length<=0) || (mainClass==null)){ return false; }
			elements=mainClass[0].getElementsByTagName('img');
		}else{ elements=document.getElementById(ID).getElementsByTagName('img'); }
		for(i=0;i<elements.length;i++){
			elements[i].style.filter='alpha(opacity=40)';
			elements[i].style.opacity='0.4';
			
			//elements[i].setAttribute('onmouseover',"OpacityOut(this); this.style.cursor='pointer';");
			//elements[i].setAttribute('onmouseout',"OpacityOver(this);");
			
			elements[i].onmouseover = new Function("OpacityOut(this); this.style.cursor='pointer';");	
			elements[i].onmouseout = new Function("OpacityOver(this);");
		}
	}catch(err){ if(DebugMode==true){ alert('portulSetOpacity: '+err); } }
}

var expandSiteName=new Array();

function expandShow(Num){
	try{
		var Element;
		var ULid=expandSiteName[Num].expandlocation;
		
		//alert(ULid);
		for(var i=0;i<expandSiteName.length;i++){
			
			if((expandSiteName[i].expandlocation==ULid) && (expandSiteName[i].blockCreated==true)){
				Element = document.getElementById('portul_'+expandSiteName[i].id);
				
				//alert(Element.style.display);
				
				if(i!=Num){	Element.style.display='none'; }
				if(i==Num){
					//alert('portul_'+expandSiteName[i].id);
					if(Element.style.display=='none'){ Element.style.display='block'; 
					}else{ Element.style.display='none';  }
				} //if
			} //if
		} //for
	}catch(err){ if(DebugMode==true){ alert('expandShow: '+err); }}
}


function expandCreateBlock(Num){
try{
	var elements, elementsLength, str, strLeft, strRight;
	var onmouseover = new Array();
	var onmouseout = new Array();
	var onclick = new Array();
	
	elements=document.getElementById(expandSiteName[Num].expandlocation).getElementsByTagName('img');
	elementsLength=elements.length;
	for(i=0;i<elements.length;i++){
		onmouseover[i]=elements[i].getAttribute('onmouseover');
		if(!onmouseover[i]){ onmouseover[i]=elements[i].onmouseover;}
		/*strLeft=String(onmouseover[i]).indexOf('{')+1;
		strRight=String(onmouseover[i]).indexOf('}');
		onmouseover[i]=String(onmouseover[i]).slice(strLeft , strRight);*/
		onmouseover[i]=String(onmouseover[i]).slice(String(onmouseover[i]).indexOf('{')+1 , String(onmouseover[i]).indexOf('}'));
		
		
		onmouseout[i]=elements[i].getAttribute('onmouseout');
		if(!onmouseout[i]){ onmouseout[i]=elements[i].onmouseout;}
		onmouseout[i]=String(onmouseout[i]).slice(String(onmouseout[i]).indexOf('{')+1 , String(onmouseout[i]).indexOf('}'));
		
		onclick[i]=elements[i].getAttribute('onclick');
		if(!onclick[i]){ onclick[i]=elements[i].onclick;}
		onclick[i]=String(onclick[i]).slice(String(onclick[i]).indexOf('{')+1 , String(onclick[i]).indexOf('}'));
		//if(onclick[i]==''){alert('test: '+onclick[i]); }
	}





	var oldHTML, newHTML;
	oldHTML=document.getElementById(expandSiteName[Num].expandlocation).innerHTML;
	//expandSiteName[Num].active='true';
	newHTML = '<li class="portul_expand" id="portul_'+expandSiteName[Num].id+'">';
//expand
	newHTML+= '<div class="expand_up"></div>';
	newHTML+= '<div class="expand">';
	newHTML+= '<div class="expand_title">'+expandSiteName[Num].title+'</div>';
	//expand_img
	newHTML+= '<div class="expand_img">';
	newHTML+= '<ul id="expand_img_'+Num+'">';
			for(i=0;i<expandSiteName[Num].img.length;i++){
				newHTML+='<li><img src="'+expandSiteName[Num].imgfolder+expandSiteName[Num].img[i]+'" alt="" width="532" height="307" /></li>';
			}
	newHTML+= '</ul>';
	newHTML+= '<a class="expand_img_back" href="#" onclick="expandBack('+"'"+ Num +"'"+'); return false;"><img src="graph/shared/empty.gif" alt="" /></a>';
	newHTML+= '<a class="expand_img_next" href="#" onclick="expandNext('+"'"+ Num +"'"+'); return false;"><img src="graph/shared/empty.gif" alt="" /></a>';
    newHTML+= '</div>';
	//expand_img
	//expand_nav
	newHTML+= '<div class="expand_nav">';
	newHTML+= '<ul id="expand_navul_'+Num+'">';
			for(i=0;i<expandSiteName[Num].img.length;i++){
			  newHTML+='<li><a href="#" onclick="expandRun('+"'"+ Num +"','"+ i +"'"+'); return false;" onmouseover="LinkOver(this);" onmouseout="LinkOut(this);">screen '+(i+1)+'</a></li>';
			}
	newHTML+= '</ul>';
	newHTML+= '<a class="expand_nav_launch" href="'+expandSiteName[Num].websitehref+'" target="_blank">launch website</a>';
	newHTML+= '</div>';
	//expand_nav
	
                                  
	newHTML+= '</div>';
	newHTML+= '<div class="expand_dn"></div>';
//expand
	newHTML+= '</li>';
	//alert(newHTML);
	document.getElementById(expandSiteName[Num].expandlocation).innerHTML+=newHTML;
	
	document.getElementById('portul_'+expandSiteName[Num].id).style.display='none';
	document.getElementById('expand_img_'+Num).style.width=532*expandSiteName[Num].img.length+'px'; //Setting width
	
	
	//elements[i].style.color='#fe6206';
	var Link=document.getElementById('expand_navul_'+Num).getElementsByTagName('a');
		Link[0].style.color='#fe6206';
			//alert(MoveToSlide);
			//for(var i=0;i<elements.length;i++){
			
			
	
	for(i=0;i<elementsLength;i++){
		if(onmouseover[i]!='nul'){ elements[i].onmouseover = new Function(onmouseover[i]); }
		if(onmouseout[i]!='nul'){ elements[i].onmouseout = new Function(onmouseout[i]); }
		if(onclick[i]!='nul'){elements[i].onclick = new Function(onclick[i]); }
	}
	
	expandSiteName[Num].blockCreated=true;
	setBlur();
}catch(err){ if(DebugMode==true){ alert('expandCreateBlock: '+err); }}
} //function

function expandVerify(SiteName){
	try{
		
		/*airtec.id='airtec2';
		airtec.expandlocation='port2';
		airtec.title = '<b>Trivett - Australia’s largest prestige automotive group</b><br />Web Page Design';
		airtec.imgfolder= 'graph/portfolio/rydefurniture/';
		airtec.img= new Array('1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg');
		airtec.websitehref='http://cyrius.com.au';*/
		
		if((!SiteName.id) || (SiteName.id=='')){ return false; }
		if(!document.getElementById(SiteName.id)){ return false; }
		
		if((!SiteName.expandlocation) || (SiteName.expandlocation=='')){ return false; }
		if(!document.getElementById(SiteName.expandlocation)){ return false; }
		
		if((!SiteName.title) || (SiteName.title=='')){ return false; }
		if((!SiteName.imgfolder) || (SiteName.imgfolder=='')){ return false; }
		if((!SiteName.img) || (SiteName.img.length==0)){ return false; }
		if((!SiteName.websitehref) || (SiteName.websitehref=='')){ return false; }
		return true;
	}catch(err){ return false; }
	
}

function expandFirstClick(Num){
	try{
		document.getElementById(expandSiteName[Num].id).onclick = '';
		document.getElementById(expandSiteName[Num].id).onclick = new Function("expandShow('"+Num+"');");
		expandCreateBlock(Num);
		expandShow(Num);
	}catch(err){ if(DebugMode==true){ alert('expandFirstClick: '+err); }}
}

function portulSetPadding(Num){
	try{
		elements=document.getElementById(expandSiteName[Num].expandlocation).getElementsByTagName('li');
		
		for(i=0;i<3;i++){ // only for 3 !!!! 
			read=elements[i].getElementsByTagName('div');
			if(read.length==0){
				if(i==0){ elements[0].style.padding='0px 22px 7px 0px';}
				if(i==1){ elements[1].style.padding='0px 14px 7px 8px'; elements[1].style.backgroundPosition='8px 0px'; }
				if(i==2){ elements[2].style.padding='0px 6px 7px 16px'; elements[2].style.backgroundPosition='16px 0px'; }
			}
			if(elements.length-1==i){ break; }
		}
	}catch(err){ if(DebugMode==true){ alert('portulSetPadding: '+err); }}
}

function expandSetBlock(SiteName){
	try{
		var Result=expandVerify(SiteName);
		
		if(!Result){ return false; }
		var expandLength=expandSiteName.length;
		expandSiteName[expandLength]=SiteName; 
		//document.getElementById(SiteName.id).onclick= new Function("expandShow('"+expandLength+"');");
		document.getElementById(SiteName.id).onclick= new Function("expandFirstClick('"+expandLength+"');");
		//expandCreateBlock(expandLength);
		portulSetPadding(expandLength);
	}
	catch(err){ if(DebugMode==true){alert('expandSetBlock: '+err); }}
	
}
function expandRun(Num, MoveToSlide){
	try{
		if(expandSiteName[Num].active=='on'){ return false; }
		else{ expandSiteName[Num].active='on'; } //Security Multithread Reason;
		expandMove(Num, MoveToSlide);
	}catch(err){ if(DebugMode==true){ alert('expandRun: '+err); }}
}
function expandMove(Num, MoveToSlide){
	try{
		
		
		var CorrectPos=(-1)*MoveToSlide*532;
		var IMGul=document.getElementById('expand_img_'+Num);
		var position=IMGul.style.left;
		if(!position){ IMGul.style.left='0px';  position='0px'; /*return false;*/ }
		
		
		var newpos=position.slice(0, position.length-2);
		
		//alert('CorrectPos: '+CorrectPos+'|  newpos:'+newpos);
		if(CorrectPos==newpos){
			var elements=document.getElementById('expand_navul_'+Num).getElementsByTagName('a');
			//alert(MoveToSlide);
			for(var i=0;i<elements.length;i++){
				if(i!=MoveToSlide){ elements[i].style.color='#ffffff'; }
				else{ elements[i].style.color='#fe6206'; }
			}
			
			expandSiteName[Num].active='off'; 
			return false; 
		}
		if(CorrectPos>newpos){ //direction
			var newpos_int=parseInt(newpos)+30;
			//alert(newpos_int);
			if(newpos_int>=CorrectPos){  newpos=CorrectPos; }
			else{ newpos=parseInt(newpos)+30; }
			//alert('direction(left): '+newpos);
		}
		else{
			if(newpos-30<CorrectPos){  newpos=CorrectPos; }
			else{newpos-=30; }
		}
		
		
		//if(newpos>=CorrectPos){ 
			IMGul.style.left=newpos+'px';
			//self.setTimeout("expandMove("+Num+","+MoveToSlide+")", 30);
			self.setTimeout("expandMove("+Num+","+MoveToSlide+")", 30);
		//}
		//alert(newpos)
	}catch(err){ if(DebugMode==true){ alert('expandMove: '+err); }}
	
}


function expandBack(Num){
	//alert(ID);
	try{
		if(expandSiteName[Num].active=='on'){ return false; }
		var IMGul=document.getElementById('expand_img_'+Num);
		var position=IMGul.style.left;
		if(!position){ IMGul.style.left='0px'; /*return false;*/}
		
		position=position.slice(0, position.length-2);
		var Location=Math.abs(Math.round(position/532));
		if((Location>0) && (Location<expandSiteName[Num].img.length)){ Location-=1; }
		else{return false; }
		expandRun(Num, Location);
		
		
		//self.setTimeout("TopShowImg("+Img+","+Opacity+")", 40);
		//IMGul.style.left='-200px';
		//var main=document.getElementById(ID);//getElementsByTagName('ul');
		//var elements=document.getElementsByClassName('expand_img');
		//elements[0].style.display='none';
		//var elements=main.getElementByClassName('expand_img');//.getElementsByTagName('ul')
		//alert(elements.length);
	}catch(err){ if(DebugMode==true){ alert('expandBack'+err); }}
}

function expandNext(Num){
	//alert(ID);
	try{
		if(expandSiteName[Num].active=='on'){ return false; }
		var IMGul=document.getElementById('expand_img_'+Num);
		var position=IMGul.style.left;
		if(!position){ IMGul.style.left='0px'; /*return false;*/}
		
		position=position.slice(0, position.length-2);
		var Location=Math.abs(Math.round(position/532));
		if(Location<expandSiteName[Num].img.length-1){ Location+=1; }
		else{return false; }
		expandRun(Num, Location);
	}catch(err){ if(DebugMode==true){ alert('expandNext'+err); }}
}

function LinkOver(This){ This.style.color='#fe6206'; }
function LinkOut(This){ This.style.color='#ffffff'; }
/* ================================================================================== */
/* =============================== Portfolio [END] ================================== */
/* ================================================================================== */

