﻿//------: CHECK BROWSER
var version = "";
var browser ="";
var isIE6 = false;

function getBrowser() {	
	if (navigator.appVersion.indexOf("MSIE")>0){
		version = parseFloat(navigator.appVersion.split("MSIE")[1]);  
		browser = "MSIE";
	} else {
		browser = "not MSIE"
	}
}
getBrowser();

if(browser=="MSIE"){
	if(version<7){
		isIE6 = true;
	}
}
//document.getElementById("Debug").innerHTML =  Debug
var TopPos = 213;
var selectedObject;
var dummies = 0;
var t;
var countDummies = 1;
var dX = 153;
var dy = 161;
var ItemsPerRow = 6;
var Timer = 0;
var TimeOutDuration = 100;
var TimerProject = 0;
var dummiesAppeared = false;
var expandProjectDuration = 0.5;
var changeDirectionAtItem = ItemsPerRow-1; // Change direction of the expanding item, based on the item's position.

var AwardLinkSelected;

function AppearItems(str,instant){        
    if (Projects[TimerProject]){
        if(instant){
            for(z=1;z<=Projects.length;z++){
                $(str+z).style.display = "block";
            }
            TimerProject = Projects.length;
        } else {
            Effect.Appear(str+(TimerProject+1), { duration: 0.2 });
            TimerProject = TimerProject + 1;
            clearTimeout(Timer);
            Timer = setTimeout("AppearItems('"+str+"')",TimeOutDuration);
        }
    } 
    if(TimerProject == Projects.length){
        AppearDummies();
    }
}
function placeDummies(ObjtoAddChild, num, CurrentX, CurrentY){
    var row = Math.ceil(num/ItemsPerRow);
    var columnPosition = num + ItemsPerRow - row*ItemsPerRow;
    dummies = ItemsPerRow - columnPosition;
    if(dummies>0){
        for(var i=0; i<dummies; i++){
            var D = document.createElement("div");
            D.innerHTML = '<div id=\"Dummies'+(i + 1)+'\" class=\"ProjectItem\" style=\"left:'+ CurrentX +'px; top:'+CurrentY+'px; display:none;\"><div style=\"position:absolute; left:6px; top:6px; z-index:1;\"></div></div>';
            ObjtoAddChild.appendChild(D);
            CurrentX = CurrentX + dX;
        }
    }
    
}
function createFooter(CurrentY){
    var D = document.getElementById("FooterWrapper");
    D.innerHTML = '<div class=\"Footer\" style=\"position:absolute; left:5px; top:' + Number(CurrentY + TopPos) + 'px;\"><div class=\"relative\"><div class=\"email\">e-mail us at  <a href=\"mailto:sales@linakis.com\">sales@linakis.com</a></div><div class=\"GooglePlus\"><g:plusone count=\"false\" size=\"small\"></g:plusone></div><a title="Find us on the map" href=\"http://www.google.com/maps/ms?f=q&hl=en&ie=UTF8&om=1&msa=0&msid=111854107654684105672.00044d9296d0be9627b8c&z=17" target=\"_blank\">{L+A}, 8, Arkadiou str.,15124 Athens, Greece</a><span class="FooterLinksGrey"><a href="/Agency.aspx">OUR AGENCY</a> | <a href="/Clients.aspx">CLIENTS</a> | <a href="/Default.aspx">PROJECTS</a> | <a href="/Awards.aspx">AWARDS</a> | <a href="/Contact.aspx">CONTACT US</a></span></div></div>';
	setGooglePlus();
}

function setGooglePlus(){
	(function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
}
		
function AppearDummies(){
    var Dobj = document.getElementById("Dummies"+countDummies);
    if(Dobj){
	    Effect.Appear("Dummies"+countDummies, { duration: 0.2 });
	    countDummies++;
		clearTimeout(Timer);
		Timer = setTimeout("AppearDummies()",TimeOutDuration);					
	}
	else
	{
	    dummies = 0;
        countDummies = 1;
        dummiesAppeared = true;
	}
}

function ChangeOpacity(From, To, id) {
    var object = document.getElementById(id);
    new Effect.Opacity(object, { from: From, to: To, duration: 0.5 });   
}

function showhideAwarded(cases){
	if(cases=="hide"){
		$$('a.awarded').each(Element.hide);
	} else {
		$$('a.awarded').each(Element.show);
	}
}

function ShowMore(Num, PageURL, onPageLoad){
    clearTimeout(t);
    for(var i=1;i<=Projects.length;i++){
        var id = "ProjectImage"+i;
        ChangeOpacity(1, 0.1, id);
        
        var linkObj = "ProjectLink"+i;
        document.getElementById(linkObj).style.display = "none";

    } 
	
	
	showhideAwarded('hide');
    
    resetSelected();
    
    ChangeOpacity(0.1, 1,"ProjectImage"+Number(Num));
    
    var objParent = document.getElementById("Project" + Num);
    objParent.style.zIndex = 1000;
    
    var objIFrame = document.getElementById("iFrame" + Num);
    objIFrame.style.display = "block"; 
    
    var direction = checkObjPosition(Num);
    
    if(direction == "right"){
		 objIFrame.style.left = "3px";
		new Effect.Morph(objIFrame, {style:'width:453px;', duration:expandProjectDuration});

    } else {
		objIFrame.style.right = "3px";
		new Effect.Morph(objIFrame, {style:'width:453px;', duration:expandProjectDuration});
    }
        
    selectedObject = objIFrame;
    
    if(onPageLoad){ // To show specifically a single project on page load:
        var row = Math.ceil(Num/ItemsPerRow) - 1;
        var objY = row * dy + TopPos;
        window.scrollTo(0, objY);
    }  
    
    t = setTimeout ("createIFrame('"+PageURL+"')", 500);
}

function createIFrame(PageURL){
    if(selectedObject!=null){
        selectedObject.innerHTML = '<iframe width=\"100%\" height=\"154\" id=\"theIFrame\" src=\"'+ PageURL +'\" scrolling=\"no\" frameborder=\"0\"></iframe>';
    }
}
function resetSelected(){
    for(var i=1;i<=Projects.length;i++){
        var objParent = document.getElementById("Project" + i);
        objParent.style.zIndex = 1;        
        
        var objIFrame = document.getElementById("iFrame" + i);
        objIFrame.style.backgroundColor = "#ffffff";
        objIFrame.style.width = "142px";
        objIFrame.style.display = "none";
        objIFrame.innerHTML = "";
    }
    selectedObject = null;
}
function resetAll(){
    resetSelected();
    for(var i=1;i<=Projects.length;i++){
        var id = "ProjectImage"+i;              
        ChangeOpacity(0.1, 1, id);
        
        var linkObj = "ProjectLink"+i;
        document.getElementById(linkObj).style.display = "block";   
		
		showhideAwarded('show');    
    }
}

function checkObjPosition(Num){
    var row = Math.ceil(Num/ItemsPerRow);
    var columnPosition = Num + ItemsPerRow - row*ItemsPerRow;
    if(columnPosition>=changeDirectionAtItem){
        return "left";
    } else {
        return "right";
    }
}

function closeSeeMore(){
    clearTimeout(t);
    var str = selectedObject.id;
    var Num = Number(str.substring(6));
    var direction = checkObjPosition(Num);

	

    selectedObject.innerHTML = "";
    
    if(direction == "right"){
		new Effect.Morph(selectedObject, {style: 'width:145px;',	duration: expandProjectDuration });
    } else {
		new Effect.Morph(selectedObject, {style: 'width:145px;',	duration: expandProjectDuration });
    }
    $(selectedObject).fade({duration: expandProjectDuration});    
    t = setTimeout ("resetAll()", 500);
}

function navigateURL(theURL){
    clearTimeout(t);
    
    if(selectedObject){
        selectedObject.innerHTML = "";
    }
    if(document.getElementById("slider")){
       // ChangeOpacity(1, 0, "slider");
	   document.getElementById("slider").style.display = "none";
    }
	ChangeOpacity(1, 0, "Projects");

    t = setTimeout ("redirect('"+theURL+"')", 500);
}

function redirect(theURL){
    window.location = theURL;
}

function GotoProject(Num) {
	document.location.href="Default.aspx?P=" + Num;
}

function fireEvent(id, evt) {
	var fireOnThis = document.getElementById(id);

	if( document.createEvent ) {
	  var evObj = document.createEvent('MouseEvents');
	  evObj.initEvent( evt, true, false );
	  fireOnThis.dispatchEvent(evObj);
	} else if( document.createEventObject ) {
	  fireOnThis.fireEvent('on'+evt);
	}
	fireOnThis.click();
	
}

function PlaceProjects(instant, IsAward) {
    document.getElementById("Loader").style.display="none";

    var ProjLength=Projects.length;
    var StartX=0;
    var correction;
    if(isIE6){
        correction = -20;
    } else {
        correction = 0;
    }
    var StartY = TopPos + correction;
    var n;
    var CurrentX=StartX;
    var CurrentY = StartY;
    var P=document.getElementById("Projects");
    var D=document.createElement("div");

    if(ProjLength>0) {
        while(P.hasChildNodes()) {
            P.removeChild(P.lastChild);
        }

        for(var i=0;i<ProjLength;i++) {
        	var D = document.createElement("div");
        	if (ProjectsAwards[i] == "1") {
        		D.innerHTML = '<div id=\"Project' + (i + 1) + '\" class=\"ProjectItem\" style=\"left:' + CurrentX + 'px; top:' + CurrentY + 'px; display:none;\"><div style=\"position:relative\"><div class=\"iFrame\" id=\"iFrame' + (i + 1) + '\"></div><div style=\"position:absolute; left:6px; top:6px; z-index:1;\"><a title="Find out more..." id=\"ProjectLink' + (i + 1) + '\" onclick=\"ShowMore(' + Number(i + 1) + ',\'' + ProjectsFrames[i] + '\');\" class=\"ProjectLink\" href=\"javascript:void(0);\"><span class=\"ItemDescr\">' + ProjectsText[i] + '</span><img src=\"Assets/Images/Blank.gif\" alt=\"\" width=\"142\" height=\"150\" border=\"0\" /></a></div><div style=\"position:absolute; left:6px; top:6px; z-index:2;\"><a class=\"awarded\" onclick=\"ShowMore(' + Number(i + 1) + ',\'' + ProjectsFrames[i] + '\');\" href=\"javascript:void(0);\" title="\Awarded!"\>&nbsp;</a></div></div><img id=\"ProjectImage' + (i + 1) + '\" style=\"margin-top:4px;\" src=\"' + Projects[i] + '\" alt=\"\" /></div>';
        	}
        	else {
        		if (IsAward == true) {
        			D.innerHTML = '<div id=\"Project' + (i + 1) + '\" class=\"ProjectItem\" style=\"left:' + CurrentX + 'px; top:' + CurrentY + 'px; display:none;\"><div style=\"position:relative\"><div class=\"iFrame\" id=\"iFrame' + (i + 1) + '\"></div><div style=\"position:absolute; left:6px; top:6px; z-index:1;\"><a title="Find out more..." id=\"ProjectLink' + (i + 1) + '\" onclick=\"GotoProject(' + Projects[i] + ');\" class=\"ProjectLink\" href=\"javascript:void(0);\"><span class=\"ItemDescr\">' + ProjectsText[i] + '</span><img src=\"Assets/Images/Blank.gif\" alt=\"\" width=\"142\" height=\"150\" border=\"0\" /></a></div></div><img id=\"ProjectImage' + (i + 1) + '\" style=\"margin-top:4px;\" src=\"' + ProjectsFrames[i] + '\" alt=\"\" /></div>';
        		}
        		else {
        			D.innerHTML = '<div id=\"Project' + (i + 1) + '\" class=\"ProjectItem\" style=\"left:' + CurrentX + 'px; top:' + CurrentY + 'px; display:none;\"><div style=\"position:relative\"><div class=\"iFrame\" id=\"iFrame' + (i + 1) + '\"></div><div style=\"position:absolute; left:6px; top:6px; z-index:1;\"><a title="Find out more..." id=\"ProjectLink' + (i + 1) + '\" onclick=\"ShowMore(' + Number(i + 1) + ',\'' + ProjectsFrames[i] + '\');\" class=\"ProjectLink\" href=\"javascript:void(0);\"><span class=\"ItemDescr\">' + ProjectsText[i] + '</span><img src=\"Assets/Images/Blank.gif\" alt=\"\" width=\"142\" height=\"150\" border=\"0\" /></a></div></div><img id=\"ProjectImage' + (i + 1) + '\" style=\"margin-top:4px;\" src=\"' + Projects[i] + '\" alt=\"\" /></div>';
				}
        		
        	}

            P.appendChild(D);

            CurrentX=CurrentX+dX;
            n = (i+1)%(ItemsPerRow);

            if(n == 0) {            
                CurrentX=StartX;
                CurrentY=CurrentY+dy;
            }
        }

    }

    placeDummies(P,i,CurrentX,CurrentY);
    var F=document.createElement("div");
    F.innerHTML="<div id=\"FooterWrapper\"></div>";
    P.appendChild(F);
    if(n==0){
        createFooter(CurrentY-45-dy);
    } else {
        createFooter(CurrentY-45);
    }
    if(instant){
        AppearItems("Project",true);
    } else {
       AppearItems("Project",false);
    }
}

function DoLightBox(Item,W,H) {
	Lightview.show({
		href: Item,
		rel: 'iframe',
		options: {closeButton: 'small', width: W, height: H }
	});
}

function DoPopup(theURL, theWinName, theLeft, theTop, theWidth, theHeight, resize, scrollbar, statusbar, menu, tools, locationbar, dirs) {
	// EXAMPLE DoPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'yes', 'no', 'no', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER
	if (theLeft == -1 && theTop == -1) {
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	window.open(theURL, theWinName, "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=' + resize + ',scrollbars=' + scrollbar + ',status=' + statusbar + ',menubar=' + menu + ',toolbar=' + tools + ',location=' + locationbar + ',directories=' + dirs + '");
}

var HeighttoStartProjects;
var h1, h2;
var Timer;

function showArea(Show2AsWell) {
	document.getElementById("Loader").style.display = "none";
	var h = document.getElementById("Td1").clientHeight + 8; //Get actual height of Awards div
	HeighttoStartProjects = h+5;

	$('ContentsWrap').morph('height:' + h + 'px;'); //Morph to that height
	ChangeOpacity(0, 1, "ContentsWrap");
	if (Show2AsWell) {
		Timer = setTimeout("showArea2()", 1000);
	}
	else {
		Timer = setTimeout("createFooter(" + HeighttoStartProjects + ")", 1000);
	}
}

function showArea2() {
	clearTimeout(Timer);
	h2 = document.getElementById("Td2").clientHeight + 8; //Get actual height of div
	h1 = document.getElementById("Td1").clientHeight + 8; //Get actual height of div
	HeighttoStartProjects = h1 + h2+8;
	document.getElementById("Div2").style.top = TopPos + h1  + 3 + "px";
	$('Div2').morph('height:' + h2 + 'px;'); //Morph to that height
	ChangeOpacity(0, 1, "Div2");
	Timer = setTimeout("createFooter(" + HeighttoStartProjects + ")", 1000);
}


function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
