﻿var idSelected = "";
var BOR = 5;
var BOR2 = BOR * 2;
var HEI = 57;
function HideContent(d) { document.getElementById(d).style.display = "none"; }
function ShowContent(d) { document.getElementById(d).style.display = "block"; }
function ReverseDisplay(d) { if (document.getElementById(d).style.display == "none") ShowContent(d); else HideContent(d); }
function SetBorder(id) {
    var newSelection = document.getElementById(id);
    var currentSelected = document.getElementById(idSelected);
    if (currentSelected != null && newSelection != null) {
        var wC = currentSelected.width;
        currentSelected.border = 0; currentSelected.width = wC + BOR2; currentSelected.height = HEI;
        var wN = newSelection.width; var hN = HEI;
        newSelection.border = BOR; newSelection.width = wN - BOR2; newSelection.height = hN - BOR2;
        idSelected = id;
    }
}
function SetBorderFirstArtwork(id, width) {
    var newSelection = document.getElementById(id);
    var wN = width; var hN = HEI;
    newSelection.border = BOR; newSelection.width = wN - BOR2; ; newSelection.height = hN - BOR2;
    idSelected = id;
}
function DisplayArtwork(identifier, setBorderFirstArtork) {
    if (!setBorderFirstArtork) SetBorder(identifier);
    AC_FL_RunContent2(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
			'width', '688',
			'height', '520',
			'src', 'ImageViewer',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'ImageViewer',
			'bgcolor', '#FFFFFF',
			'name', 'ImageViewer',
			'menu', 'false',
			'allowFullScreen', 'false',
			'allowScriptAccess', 'sameDomain',
			'movie', 'ImageViewer',
			'salign', '',
            'FlashVars', 'xmlPath=ImageViewerData.aspx?identifier=' + identifier
			);
    GetArtworkData(identifier);
    PrintActual();
}

function GetArtworkData(identifier) {
    AlonsoBedolla.ArtworkData.GetData(
                    identifier,
                    OnGetArtworkDataSuccess,
                    OnGetArtworkDataFailure,
                    "<%= DateTime.Now %>");
}

function OnGetArtworkDataSuccess(result, context, methodName) {
    if (result != "") {
        var id = result.ID;
        var title = result.Title;
        var year = result.Year;
        var width = result.Width;
        var height = result.Height;
        var depth = result.Depth;
        var content = result.Content;
        var type = result.Type;
        var support = result.Support;
        var medium = result.Medium;
        var status = result.Status;
        var collectorCode = result.CollectorCode;
        var city = result.City;
        var legend = result.Legend;
        var serie = result.Serie;
        var about = result.About;

        spaTitle.innerHTML = title;
        spaID.innerHTML = id;
        spaYear.innerHTML = (year == "") ? "" : "/ " + year;
        spaMediumSupport.innerHTML = (medium == "") ? support : medium + " on " + support;
        spaDimensions.innerHTML = (width == "" || height == "" || depth == "") ? "" : "/ " + width + "&#8221; x " + height + "&#8221; x " + depth + "&#8221;";
        spaStatus.innerHTML = status;
        spaLegend.innerHTML = "";
        if (legend != "") spaLegend.innerHTML = "@ " + '<a href="Contact.aspx">' + legend + '</a>';

        if (about == "") {
            spaSerie1.innerHTML = "";
            spaSerie2.innerHTML = "";
            spaAbout.innerHTML = "";
            HideContent('divAbout'); ShowContent('divNoAbout');
            HideContent('divAboutLegend');
        }
        else {
            ShowContent('divAboutLegend'); HideContent('divNoAbout');
            spaSerie1.innerHTML = serie;
            spaSerie2.innerHTML = serie;
            spaAbout.innerHTML = about;
        }
        ShowContent('divDetails');
    } else {
        divAviso.innerHTML = "No data";
    }
}

function OnGetArtworkDataFailure(error, context, methodName) {
    divAviso.innerHTML = error.get_message();
}

function Total() { return $('.pni').length; }
function ActualIndex() {
    var i = 0;
    var t = Total();
    for (i = 0; i < t; i++) {
        var b = $('.pni')[i].border;
        if (b > 0) return i;
    }
    return 0;
}
function ActualID() {
    var i = ActualIndex();
    return $('.pni')[i].id;
}
function ElID(i) { return $('.pni')[i].id; }
function Next() {
    var actual = ActualIndex();
    var total = Total();
    if (actual < (total - 1)) {
        var nuevoIndice = actual + 1;
        var nuevoID = ElID(nuevoIndice);
        DisplayArtwork(nuevoID, false);        
        VerificaMovimientoPanel('Next');
    }
}
function Back() {
    var actual = ActualIndex();
    if (actual > 0) {
        var nuevoIndice = actual - 1;
        var nuevoID = ElID(nuevoIndice);
        DisplayArtwork(nuevoID, false);
        VerificaMovimientoPanel('Back');
    }
}
function First() {
    stepcarousel.stepTo('carousel', 1);
    var nuevoID = ElID(0);
    DisplayArtwork(nuevoID, false);
}
function Last() {
    stepcarousel.stepTo('carousel', spaTotalPanels);
}
function VerificaMovimientoPanel(accion) {
    var seleccionado = ActualIndex() + 1;   
    if (accion == 'Next') {
        if (seleccionado > spaLastPanel) {
            stepcarousel.stepBy('carousel', 3);
        }
    }
    else {
        if (seleccionado < spaCurrentPanel) {
            stepcarousel.stepBy('carousel', -3);
        }
    }    
}
function PrintActual() {
    var cp = 1 + ActualIndex(); cp = cp + "&nbsp;"; document.getElementById("spaCurrentPanel").innerHTML = cp;
}
