How to get Fancybox working with my Javascript?
I really hope this is the correct place for this.... I'm pretty much a novice at JQuery, but I seem to have come off allright with Javascript. I wrote a gallery that works something like a Rubiks-cube, where the rows and column contents can get swapped around.
Here's a link: http://www.taunise.com/testi/index.html
What I'd like to do is implement fancybox so I can get the nice popup fullsize images for each gallery item.
My problem is, I load the images dynamically by calling a function on pageload that pulls the image code out of the array and into the divs.
I can't seem to get fancybox working with this....I am thinking it might be because of the dynamic content.
Anyone got an insight? feel free to rip apart my code....
here' the jist of my javascript:
- $(document).ready(function() {
- /*
- * Examples - images
- */
- $("a#example2").fancybox({
- 'titleShow' : false,
- 'transitionIn' : 'elastic',
- 'transitionOut' : 'elastic'
- });
-
- });
- // setup the main array
- var row1Array = Array("<a id=\"example2\" href=\"images/image1.jpg\"><img src=\"images/image1_thumb.jpg\" /></a>", "<img src=\"images/image2_thumb.jpg\" />", "<img src=\"images/image3_thumb.jpg\" />", "<img src=\"images/image4_thumb.jpg\" />", "<img src=\"images/image5_thumb.jpg\" />", "<img src=\"images/image6_thumb.jpg\" />");
- var row2Array= Array("<img src=\"images/image7_thumb.jpg\" />", "<img src=\"images/image8_thumb.jpg\" />", "<img src=\"images/image9_thumb.jpg\" />", "<img src=\"images/image10_thumb.jpg\" />", "<img src=\"images/image11_thumb.jpg\" />", "<img src=\"images/image12_thumb.jpg\" />");
- var colArray = Array("<img src=\"images/image13_thumb.jpg\" />", row1Array[2], row2Array[2], "<img src=\"images/image16_thumb.jpg\" />", "<img src=\"images/image17_thumb.jpg\" />", "<img src=\"images/image18_thumb.jpg\" />");
-
- function iniGallery() {
- insertArray("row1");
- insertArray("row2");
- insertArray("col");
- }
-
- // insert the array into the DIV smalltest object
- function insertArray(toChange)
- {
- var theText = ""; // set the theText output to an empty string otherwise it would start with null.
-
- if (toChange == "row1") {
- // create the array of text to insert
- theText = row1Array[0];
- //alert(theText);
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img1").appendChild(insertText);
- document.getElementById('row1img1').innerHTML = theText;
- // create the array of text to insert
- theText = row1Array[1];
-
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img2").appendChild(insertText);
- document.getElementById('row1img2').innerHTML = theText;
-
- // create the array of text to insert
- theText = row1Array[2];
-
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img3").appendChild(insertText);
- document.getElementById('row1img3').innerHTML = theText;
-
- //update col
- colArray[1] = row1Array[2];
- }
- else if (toChange == "row2") {
- // create the array of text to insert
- theText = row2Array[0];
- //alert(theText);
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img1").appendChild(insertText);
- document.getElementById('row2img1').innerHTML = theText;
- // create the array of text to insert
- theText = row2Array[1];
-
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img2").appendChild(insertText);
- document.getElementById('row2img2').innerHTML = theText;
-
- // create the array of text to insert
- theText = row2Array[2];
-
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img3").appendChild(insertText);
- document.getElementById('row2img3').innerHTML = theText;
- colArray[2] = row2Array[2];
- }
- else if (toChange == "col") {
- // create the array of text to insert
- theText = colArray[0];
- //alert(theText);
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img1").appendChild(insertText);
- document.getElementById('colimg1').innerHTML = theText;
-
- theText = colArray[1];
- //alert(theText);
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img1").appendChild(insertText);
- document.getElementById('row1img3').innerHTML = theText;
-
- theText = colArray[2];
- //alert(theText);
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img1").appendChild(insertText);
- document.getElementById('row2img3').innerHTML = theText;
-
- // create the array of text to insert
- theText = colArray[3];
-
- // create the createTextNode
- var insertText = document.createTextNode(theText);
- //document.getElementById("row1img2").appendChild(insertText);
- document.getElementById('colimg4').innerHTML = theText;
-
- }
-
- }
- function next(arrayName) {
- var tempArray = Array();
- //var i = 0;
- //alert(row1Array.length);
- if (arrayName == "row1") {
- for (i = 0; i < row1Array.length; i++) {
- tempArray[i] = row1Array[i];
- }
- for (n = 1; n < row1Array.length; n++) {
- row1Array[n] = tempArray[n-1];
- }
- row1Array[0] = tempArray[row1Array.length - 1];
- colArray[1] = row1Array[2];
- insertArray("row1");
-
- }
- else if (arrayName == "row2") {
- for (i = 0; i < row2Array.length; i++) {
- tempArray[i] = row2Array[i];
- }
- for (n = 1; n < row2Array.length; n++) {
- row2Array[n] = tempArray[n-1];
- }
- row2Array[0] = tempArray[row2Array.length - 1];
- colArray[2] = row1Array[2];
- insertArray("row2");
- }
- else if (arrayName == "col") {
- for (i = 0; i < colArray.length; i++) {
- tempArray[i] = colArray[i];
- }
- for (n = 1; n < colArray.length; n++) {
- colArray[n] = tempArray[n-1];
- }
- colArray[0] = tempArray[colArray.length - 1];
- row2Array[2] = colArray[2];
- row1Array[2] = colArray[1];
- insertArray("col");
- }
- }
-
- function previous(arrayName) {
- var tempArray = Array();
- //var i = 0;
- //alert(row1Array.length);
- if (arrayName == "row1") {
- for (i = 0; i < row1Array.length; i++) {
- tempArray[i] = row1Array[i];
- }
- for (n = 0; n < row1Array.length-1; n++) {
- row1Array[n] = tempArray[n+1];
- }
- row1Array[row1Array.length - 1] = tempArray[0];
- colArray[1] = row1Array[2];
- insertArray("row1");
-
- }
- else if (arrayName == "row2") {
- for (i = 0; i < row2Array.length; i++) {
- tempArray[i] = row2Array[i];
- }
- for (n = 0; n < row2Array.length-1; n++) {
- row2Array[n] = tempArray[n+1];
- }
- row2Array[row2Array.length - 1] = tempArray[0];
- colArray[2] = row1Array[2];
- insertArray("row2");
- }
- else if (arrayName == "col") {
- for (i = 0; i < colArray.length; i++) {
- tempArray[i] = colArray[i];
- }
- for (n = 0; n < colArray.length-1; n++) {
- colArray[n] = tempArray[n+1];
- }
- colArray[colArray.length - 1] = tempArray[0];
- row2Array[2] = colArray[2];
- row1Array[2] = colArray[1];
- insertArray("col");
- }
- }