/****************************************
    Website Coded by Gelo Factory LLC
           All Rights Reserved
           (c)  Copyright 2007
         http://gelofactory.com/
****************************************/

$(function() {

if ($("a[rel*=lightbox]").length > 0) $("a[rel*=lightbox]").lightBox();

    if($("#picturesHeader").length || $(".pressImage").length) {
        $('.gallery a').lightBox();
        $('.large_image_link a').lightBox();
    }
});

$(function() {
    if($("#picturesHeader").length) {
        $(".pictures .gallery a").click(function () {
            var main_image_id = parseInt(jQuery(this).attr("id").replace("img_",""));
            var next_image = main_image_id + 4;
            while(main_image_id <= next_image)  {
                main_image_id++;
                var imagepath = jQuery(".pictures .thumbnail #img_"+main_image_id).attr("href");
                newImage(imagepath);
            }
            main_image_id = parseInt(jQuery(this).attr("id").replace("img_",""));
            var previous_image = main_image_id - 4;
            while(main_image_id >= previous_image)  {
                main_image_id--;
                var imagepath = jQuery(".pictures .thumbnail #img_"+main_image_id).attr("href");
                newImage(imagepath);
            }
       });
    }
});

/*jQuery($(function() {
    jQuery("#hide_show").click(function(event) {
        event.preventDefault();
        jQuery("#flashcontent").slideToggle();
    });

    jQuery("#flashcontent a").click(function(event) {
        event.preventDefault();
        jQuery("#flashcontent").slideUp();
    });
}));
*/
function getElementOfId(id) {
	var el = null;
	if (document.getElementById) {
		el = document.getElementById(id);
	} else if (document.all) {
		el = document.all[id];
	} else if (document.layers) {
		el = document.layers[el];
	}
	return el;
}

var newImageCount = -1;
var newImages = new Array();
function newImage(arg) {
	if (document.images) {
		newImageCount++;
		newImages[newImageCount] = new Image();
		newImages[newImageCount].src = arg;
		return newImages[newImageCount];
	}
}

// Preload Navigation Images
newImage(base_url+"./_img/previous.gif");
newImage(base_url+"./_img/next.gif");

var currentPage = new Array();
var totalPages = new Array();
var currentImage = new Array();
var totalImages = new Array();
var allImages = new Array();
var pageImages = new Array();

function setPictureAlbumName(nameID, albumName) {
	var el = getElementOfId(nameID);
	el.innerHTML = albumName;
}

function showPreviousPage(pageIndex) {
	if (typeof(currentPage[pageIndex]) != "undefined") if (currentPage[pageIndex] > 1) currentPage[pageIndex]--;
	redrawPages(pageIndex);
	redrawPageButtons(pageIndex);
}

function showNextPage(pageIndex) {
	if (typeof(currentPage[pageIndex]) != "undefined") if (currentPage[pageIndex] < totalPages[pageIndex]) currentPage[pageIndex]++;
	redrawPages(pageIndex);
	redrawPageButtons(pageIndex);
}

function showPreviousPageAudio(pageIndex) {
	showPreviousPage(pageIndex);
	showMusicPlayerConnectionSWF();
}

function showNextPageAudio(pageIndex) {
	showNextPage(pageIndex);
	showMusicPlayerConnectionSWF();
}

function showMusicPlayerConnectionSWF(albumID) {
	albumID = (albumID == null) ? pageAlbumIDMatrix['page' + currentPage['Audio']] : albumID;
	var so = new SWFObject("musicPlayerConnection.swf?album=" + albumID, "musicPlayerConnection", "1", "1", "7", "#000000");
	so.write("flashcontent");
}

function triggerTrack(albumID, trackID) {
	if ((audioPlayerPopup == null) || audioPlayerPopup.closed) {
		popupAudioPlayer(albumID, trackID);
	} else if (trackID) {
		audioPlayerPopup.focus();
		var so = new SWFObject("musicPlayerConnection.swf?track=" + trackID, "musicPlayerConnection", "1", "1", "7", "#000000");
		so.write("flashcontent");
	}
}

var audioPlayerPopup = null;
function popupAudioPlayer(albumID, trackID) {
	audioPlayerPopup = window.open('audio_player.php?album=' + albumID + '&track=' + trackID, 'name', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=470,height=52');
	if (window.focus) audioPlayerPopup.focus();
}


function playTrack(albumId, trackID) {
    document.getElementById("musicPlayer").triggerTrack(albumId, trackID);
    //$("#musicPlayer").triggerTrack(albumId, trackID);
}

function onSwfLoad() {
   document.getElementById("musicPlayer").filterAlbum(document.getElementById("music_id").innerHTML);
}

function redrawPages(pageIndex) {
	for (var whichPage = 1; whichPage <= totalPages[pageIndex]; whichPage++) {
		var el = getElementOfId('page' + whichPage);
		el.style.display = (whichPage == currentPage[pageIndex]) ? 'block' : 'none';
	}
}

function redrawPageButtons(pageIndex) {
	var previousEl = getElementOfId('previousButton');
	var nextEl = getElementOfId('nextButton');
	previousEl.style.display = (currentPage[pageIndex] == 1) ? 'none' : 'block';
	nextEl.style.display = (currentPage[pageIndex] == totalPages[pageIndex]) ? 'none' : 'block';
}

function showPreviousImage(pictureID) {
	if (typeof(currentImage[pictureID]) != "undefined") if (currentImage[pictureID] > 0) currentImage[pictureID]--;
	redrawImage(pictureID);
	redrawImageButtons(pictureID);
	setCloseOverlayLink(pictureID);
}

function showNextImage(pictureID) {
	if (typeof(currentImage[pictureID]) != "undefined") if (currentImage[pictureID] < (totalImages[pictureID] - 1)) currentImage[pictureID]++;
	redrawImage(pictureID);
	redrawImageButtons(pictureID);
	setCloseOverlayLink(pictureID);
}

function redrawImage(pictureID) {
	showPictureContentOverlay(null, pictureID, currentImage[pictureID], true);
}

function redrawImageButtons(pictureID) {
	var previousEl = getElementOfId('previousImageButton');
	var nextEl = getElementOfId('nextImageButton');
	previousEl.style.display = (currentImage[pictureID] == 0) ? 'none' : 'block';
	nextEl.style.display = (currentImage[pictureID] == (totalImages[pictureID] - 1)) ? 'none' : 'block';
}

var nonPageImageHREF = "pictures.php";
var nonPageImageOnClick = "";
var pageImageHREF = null;
var pageImageOnClick = null;
var imagesPerPage = 12;
function setCloseOverlayLink(pictureID) {
	var el = getElementOfId('closeOverlayLink');
	if (el) {
		if (typeof(pageImages[currentImage[pictureID]]) == "undefined") {
			if (el.href != nonPageImageHREF) {
				pageImageHREF = el.href;
				pageImageOnClick = el.onclick;
				el.href = nonPageImageHREF+"?album="+currentAlbum+"&page="+(Math.floor(currentImage[pictureID]/imagesPerPage)+1);
				el.onclick = nonPageImageOnClick;
			}
		} else {
			if ((el.href != pageImageHREF) && (pageImageHREF != null)) {
				el.href = pageImageHREF;
				el.onclick = pageImageOnClick;
			}
		}
	}
}

function textEntryRollOver(entryID) {
	el = getElementOfId(entryID);
	if (el) el.style.backgroundColor = '#333';
}

function textEntryRollOut(entryID) {
	el = getElementOfId(entryID);
	if (el) el.style.backgroundColor = '#000';
}

function hideLoadingCaption() {
	var loadingEl = getElementOfId('loading_caption');
	if (loadingEl) loadingEl.style.display = 'none';
}

function showContentOverlay(overlayID, hideDivID) {
	var overlayEl = getElementOfId(overlayID);
	var closeOverlayEl = getElementOfId('closeOverlay');
	if (overlayEl && closeOverlayEl) {
		overlayEl.style.display = 'block';
		closeOverlayEl.style.display = 'block';
	}
	if (hideDivID) {
		var hideDivEl = getElementOfId(hideDivID);
		if (hideDivEl) hideDivEl.style.display = 'none';
	}
}

function hideContentOverlay(overlayID, hideDivID, spacerImageID) {
	var overlayEl = getElementOfId(overlayID);
	var closeOverlayEl = getElementOfId('closeOverlay');
	if (overlayEl && closeOverlayEl) {
		overlayEl.style.display = 'none';
		closeOverlayEl.style.display = 'none';
	}
	if (hideDivID) {
		var hideDivEl = getElementOfId(hideDivID);
		if (hideDivEl) hideDivEl.style.display = 'block';
	}
	if (spacerImageID) {
		var spacerImageEl = getElementOfId(spacerImageID);
		if (spacerImageEl) spacerImageEl.src = '_img/spacer.gif';
	}
}

function showPictureContentOverlay(overlayID, pictureID, whichCurrentImage, useAllImages) {
	useAllImages = (typeof(useAllImages) == "undefined") ? false : useAllImages;
	var pictureEl = getElementOfId(pictureID);
	if (pictureEl) pictureEl.src = (useAllImages) ? allImages[whichCurrentImage] : pageImages[whichCurrentImage]
	if (overlayID != null) showContentOverlay(overlayID);
	currentImage[pictureID] = whichCurrentImage;
}

function showVideoContentOverlay(overlayID) {
	showContentOverlay(overlayID);
}

function writeYouTubeCode(youTubeCode) {
    var youTubeUrl = youTubeCode.replace("watch?v=", "v/");
	document.write("<object width='425' height='350' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0' type='application/x-oleobject'>\n");
	document.write("<param name='movie' value='" + youTubeUrl + "&autoplay=1'></param>");
	document.write("<param name='bgcolor' value='#000000'></param>");
	document.write("<embed src='" + youTubeUrl + "&autoplay=1' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' align='' width='425' height='350' bgcolor='#000000'></embed>");
	document.write("</object>");
}

function writeQuicktimeCode(mediaPath, w, h) {
	h += 16;
	QT_WriteOBJECT(mediaPath, w, h, ''
	, 'CONTROLLER', 'TRUE'
	, 'OBJ#AUTOPLAY', 'true'
	, 'EMB#BGCOLOR', '#000000'
	, 'TARGET', 'myself'
	, 'EMB#BORDER', '0'
	, 'TYPE', 'video/quicktime');
}

function writeWindowsMediaCode(mediaPath, w, h) {
	h += 70;
	document.write("<object id=\"mediaPlayer\" width=\"" + w + "\" height=\"" + h + "\" classid=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\">\n");
	document.write("<param name=\"fileName\" value=\"" + mediaPath + "\">\n");
	document.write("<param name=\"animationatStart\" value=\"true\">\n");
	document.write("<param name=\"transparentatStart\" value=\"true\">\n");
	document.write("<param name=\"autoStart\" value=\"true\">\n");
	document.write("<param name=\"ShowControls\" value=\"true\">\n");
	document.write("<param name=\"ShowDisplay\" value=\"false\">\n");
	document.write("<param name=\"ShowStatusBar\" value=\"true\">\n");
	document.write("<param name=\"loop\" value=\"0\">\n");
	document.write("<param name=\"bgcolor\" value=\"#000000\">\n");
	document.write("<embed type=\"application/x-mplayer2\" pluginspage=\"http://microsoft.com/windows/mediaplayer/en/download/\" id=\"mediaPlayer\" name=\"mediaPlayer\" displaysize=\"4\" autosize=\"0\" bgcolor=\"black\" showcontrols=\"1\" showtracker=\"1\" showdisplay=\"0\" showstatusbar=\"1\" videoborder3d=\"0\" width=\"" + w + "\" height=\"" + h + "\" src=\"" + mediaPath + "\" autostart=\"1\" designtimesp=\"5311\" loop=\"0\" bgcolor=\"#000000\">\n");
	document.write("</embed>\n");
	document.write("</object>\n");
}



function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
                fillSectionDropDown();
            }
            func();

        }
    }
}
/*
addLoadEvent(function() {
	if (location.href.indexOf("audio_player.php") == -1) {
		if (document.all) {
			top.window.moveTo(0,0);
			top.window.resizeTo(screen.availWidth, screen.availHeight);
		} else if (document.layers || document.getElementById) {
			if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
				top.window.moveTo(0,0);
				top.window.outerHeight = screen.availHeight;
				top.window.outerWidth = screen.availWidth;
			}
		}
	}
})*/

