/*
    Gallery functions and global vars for Gallery detail pages.
    Copyright (C) 2000-2008 Kohler Company.    All Rights Reserved.
    Author: Dennis Spaag
    Date Created: 01/07/08
 */

var inner1 = '<img src="/common/images/btn-gallery-';
var inner2 = '.jpg" width="225" height="80" alt="" border="0" id="galleryimg-';
var inner3 = '" onclick="changeGallery(\'';
var inner4 = '\'\);">';

function previousGallery() {
	setActiveGalleryId( getActiveGalleryId(), -1)
	setInnerGalleryImage(getActiveGallery());
}
function nextGallery() {
	setActiveGalleryId( getActiveGalleryId(), 1);
	setInnerGalleryImage(getActiveGallery());
}
function setInnerGalleryImage(id) {
	//alert(inner1 + id + inner2 + id + inner3);
	 $("#active-gallery-" + getActiveSection()).html(inner1 + id + inner2 + getActiveSection() + inner3 + id + inner4);
}
function changeGallery() {
	location.href='/galleryOfStyle/' + thisGallerySection + '/detail.cn?ID=' + getActiveGallery();
}

function writeInitialModernImageTag() {
    var thisIdx = 0;
    if (activeModern > 0) {
        thisIdx = activeModern;
    }  else { activeModern = 0; }
    $("#active-gallery-modern").html(inner1 + modern[thisIdx] + inner2 + "modern" + inner3 + modern[thisIdx] + inner4);
}
function writeInitialClassicImageTag() {
    var thisIdx = 0;
    if (activeClassic > 0) {
        thisIdx = activeClassic;   
    } else { activeClassic = 0; }
    $("#active-gallery-classic").html(inner1 + classic[thisIdx] + inner2 + "classic" + inner3 + classic[thisIdx] + inner4);
}

function setActiveGalleryId(id, num) {
	if (getActiveSection()=="modern") {
		if (id+num > modern.length-1) {
			activeModern = 0
		}
		else if (id+num < 0 ) {
			activeModern=modern.length-1;
		}
		else {
			activeModern = id+num;
		}
	}
	else {
		if (id+num > classic.length-1) {
			activeClassic = 0
		}
		else if (id+num < 0) {
			activeClassic = classic.length-1;
		}
		else {
			activeClassic = id+num;
		}
	}
}

function setActiveSection(section) {
    if (activeSection==null || activeSection != section) {

        activeSection = section;
        var nonactiveSection = "modern";
        if (activeSection=="modern") {
            nonactiveSection = "classic";
        }
        var onSrc = $('#gallery-tab-' + activeSection).attr('src').split('.');
        var offSrc = $('#gallery-tab-' + nonactiveSection).attr('src');
        $('#gallery-tab-' + activeSection).attr('src', onSrc[0] + "-on." + onSrc[1]);
        $('#gallery-tab-' + nonactiveSection).attr('src', offSrc.replace("-on.","."));
        $('#active-gallery-' + nonactiveSection).hide();
        $('#active-gallery-' + activeSection).show();
    }
}
function getActiveSection() {
	return activeSection;
}
function getActiveGalleryId() {
	if (getActiveSection()=="modern") {
		return activeModern;
	}
	return activeClassic;
}
function getActiveGallery() {
	if (getActiveSection()=="modern") {
		return modern[activeModern];
	}
	return classic[activeClassic];
}

// on-DOM load
$(function() {
    writeInitialModernImageTag();
    writeInitialClassicImageTag();
});
