﻿<!--

/*
PAGE INITIALIZATION 
*/ 


function window_onload(active_menu) {

if (active_menu)
{
    mainmenuid = active_menu.id;
    active_menu.bgColor="#996633";
}
else 
    mainmenuid = "";

if (mainmenuid == "menu_svc" )
{
    service_menuid = "newborn";
    service(service_menuid);
}
else
{
    service_menuid = "";

    service_menuIndex = -1;
    if (mainmenuid == "menu_svc" )
        SetServiceMenuIndex();

    createMovie();
    startMovie();
}

}

/*
MENU FUNCTIONS 
*/ 

function entermenu(obj)
{
    if (obj.id != mainmenuid)
    {
        obj.bgColor="#cc8844";
    };
};

function leavemenu(obj)
{
    if (obj.id != mainmenuid)
    {
        obj.bgColor="#cc9966";
    };
};

//  activate a service 
function service(section)
{
    stopMovie();
    
    //  hide service 
    if (service_menuid != "")
    {
        //document.getElementById(service_menuid).style.backgroundColor = "";
        document.getElementById(service_menuid).style.color="";
        document.getElementById(service_menuid+"_svc").style.visibility = "hidden";
        document.getElementById(service_menuid+"_svc").style.display = "none";
    }

    //  set curent service 
    service_menuid=section;
    SetServiceMenuIndex();

    //  show service 
    //document.getElementById(service_menuid).style.backgroundColor = "#996633";
    document.getElementById(service_menuid).style.color="black";
    document.getElementById(service_menuid+"_svc").style.visibility = "";
    document.getElementById(service_menuid+"_svc").style.display = "";

//  create movie for the service     
    createMovie();
    startMovie();
    
}
function SetServiceMenuIndex()
{
    switch(service_menuid)
    {
    case "newborn":
    service_menuIndex = 0;
    break;
    case "portrait":
    service_menuIndex = 1;
    break;
    case "aniversaries":
    service_menuIndex = 2;
    break;
    case "stock":
    service_menuIndex = 3;
    break;
    case "animal":
    service_menuIndex = 4;
    break;
    }
}

/*
MOVIE FUNCTIONS 
*/ 

//  create movie section 
function createMovie()
{
    //m_up = document.getElementById('movie_up');
    m_pics = document.getElementById('movie_pic');
    //m_low = document.getElementById('movie_low');
    
    var prefix = "";
    var pics_count = m_pics.childNodes.length;
    //  remove all pictures 
    for (var i = 0;i<pics_count;i++)
        m_pics.removeChild(m_pics.childNodes[0]);


    //  calculate count pics in movie and prefix 
    pics_count = GetPicCount();
    
//  add all pictures 3 times
    var stepcount = 0;
    while (stepcount < 3)
    {
        for (var i = 0;i<pics_count;i++)
        {
            var img = document.createElement("img");

            var alink = document.createElement("a");
            alink.href="javascript:viewPic("+i.toString()+");";
            img.onmouseover = stopMovie;
            img.onmouseout = startMovie;
            
            img.src = "img/"+GetSmallPicName(i);
            img.alt = GetPicDisplay(i);
            
            img.style.border = movie_imageBorder.toString()+"px outset #dddddd";
            img.style.verticalAlign = "middle";
            
            alink.appendChild(img);
            m_pics.appendChild(alink);
        }
        stepcount++;
    }


    //  reset movie form offset 0 
    m_pics.style.left = 0;
    movie_left = 0;
    
}

//  stop movie timer 
function stopMovie()
{
    if (timerID)
        window.clearInterval(timerID);
    timerID = undefined;
    
}
//  start movie timer 
function startMovie()
{
    timerID = window.setInterval("runmovie()", movie_interval);
}
//  move movie slide 
function runmovie()
{
    var pics_count = GetPicCount();
    //  calculate firstPictureIndex 
    var totalWidth = 0;
    var firstPictureIndex = -1;
    while (firstPictureIndex == -1)
    {
        for (var i = 0;i<pics_count;i++)
        {
            totalWidth += m_pics.childNodes[i].childNodes[0].width+movie_imageBorder*2;
            if (totalWidth > 0-movie_left)
            {
                firstPictureIndex = i;
                break;
            }
        }
    }

    if (firstPictureIndex == pics_count-1)
    {
        movie_left = 0;
    }else 
    {
        movie_left -= m_pics.childNodes[firstPictureIndex].childNodes[0].width+movie_imageBorder*2;
    }

     if (m_up)
        m_up.style.left = movie_left.toString()+"px";
     if (m_pics)
        m_pics.style.left = movie_left.toString()+"px";
     if (m_low)
        m_low.style.left = movie_left.toString()+"px";
   
}

function fasterMovie()
{
    movie_speed++;
}
function slowerMovie()
{
    movie_speed--;
    if (movie_speed < 1)
        movie_speed = 1;
}
function startstopMovie()
{
    if (timerID)
        stopMovie();
    else 
        startMovie();
}

/*
PICTURE VIEWER
*/

//  Block the right click menu 
function rightclick()
{
    alert("Copyright Cristian Chivoiu. It is illegal to copy without written permission. Violators will be punished");
    return false;
}

//  handle a click in the movie section 
function viewPic(obj)
{
    preview_picIndex = obj;
    runpreview();
}


//  preview picture 
function runpreview()
{
    window.open("Preview.htm?idx="+service_menuIndex+"&pic="+preview_picIndex, "picpreview", "channelmode=no,directories=no,location=no,menubar=no,toolbar=no,resizable=yes,scrollbars=no,status=no", false);
}


/*
PREVIEW WINDOW FUNCTIONS
*/

function ParseParameters()
{
    //  extract parameters 
    var s = window.location.search.split("?");
    //  remove ?
    if (s.length > 1)
        s = s[1];
    else 
        s = s[0];
    
    var params = s.split("&");
    for (var i = 0;i<params.length;i++)
    {
        //  extract menu index 
        s = ParseMenuIndex(params[i]);
        if (s)
        {
            service_menuIndex = new Number(s);
            continue;
        }
        //  extract picture index     
        s = ParsePicIndex(params[i]);
        if (s)
        {
            preview_picIndex = new Number(s);
            if (preview_picIndex >= GetPicCount())
                preview_picIndex = new Number(preview_picIndex % GetPicCount());
            continue;
        }
        preview_minsize = true;
        s = ParseSize(params[i]);
        if (s)
            preview_minsize = false;
            
    }
}

function ParseMenuIndex(par)
{
    var sdx = par.split("idx=");
    if (sdx.length > 0)
        return sdx[1];
    return undefined;
}
function ParsePicIndex(par)
{
    var sdx = par.split("pic=");
    if (sdx.length > 0)
        return sdx[1];
    return undefined;
}
function ParseSize(par)
{
    var sdx = par.split("size=");
    if (sdx.length > 0)
        return sdx[1];
    return undefined;
}

function previewImg()
{
    document.getElementById("img1").src = "img/"+GetLargePicName(preview_picIndex);
    document.getElementById("picTitle").innerHTML = GetPicDisplay(preview_picIndex);
    document.getElementById("ctgTitle").innerHTML = GetPicCategory();
}

function GetPicCount()
{
    if (service_menuIndex < 0)
    {
        return moviepics_count;
    }
    else 
    {
        return portfolio_counts[service_menuIndex];
    }
}

function GetSmallPicName(index)
{
    if (service_menuIndex < 0)
        return moviepic_small[index];
    else 
        return portfoliopic_small[service_menuIndex][index];
}

function GetPicDisplay(index)
{
    if (service_menuIndex < 0)
        return moviepic_display[index];
    else 
        return portfoliopic_display[service_menuIndex][index];
}
function GetLargePicName(index)
{
    if (service_menuIndex == -1)
        return moviepic_large[index];
    else 
        return portfoliopic_large[service_menuIndex][index];
}
function GetPicCategory()
{
    if (service_menuIndex == -1)
    {// moview preview 
        return movie_category;
    }
    else
    {// portfolio preview 
        return portfolio_category[service_menuIndex];
    }
}

function previewNext()
{
    preview_picIndex = (preview_picIndex + 1) % GetPicCount();
    previewImg();
}
function previewPrev()
{
    preview_picIndex = preview_picIndex - 1;
    if (preview_picIndex < 0)
        preview_picIndex = GetPicCount()-1;
    previewImg();
}


//  active main menu 
var mainmenuid;
//  time id 
var timerID = undefined;
//  current left position 
var movie_left = 0;

var movie_speed = 1;

var movie_imageBorder = 3;

//  movie, upper side 
var m_up;
//  movie, middle side 
var m_pics;
//  moview, lower side 
var m_low;

//  picture index sent to preview window 
var preview_picIndex;

//  current service submenu id 
var service_menuid = "";
var service_menuIndex = -1;


//  preview window variables 
var preview_minsize = true;


//-->

