/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by ----- filename.js -----
 */

/* ----- slide8.js ----- */
var numImages = 13;


// create array for (numImages) banner images
var matrix = new Array(numImages);
for (i = 0; i < numImages; i++) {
  // we need an Image, href, title, clicktrack, tracking on each entry
  matrix[i] = new Array(5);
}


//variables are easier to maintain 
j = 0; 
// new logos
// Limo Lissotschenko Mikrooptik GmbH
// holds an image
matrix[j][0] = new Image();
// holds the image source 
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/01_Limo.jpg";
// holds the external link
matrix[j][1] = "http://www.limo.de";
// holds the title
matrix[j][2] = "Limo Lissotschenko Mikrooptik GmbH";
// holds clicktrack class
matrix[j][3] = "clicktrack ct_limo";
// optional calling google page tracker API
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/limo');";
// increment variable
j++;

// Laservision
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/02_laservision.jpg";
matrix[j][1] = "http://www.uvex-laservision.de";
matrix[j][2] = "LASERVISION";
matrix[j][3] = "clicktrack ct_laservision";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/laservision');";
j++;

// LASER COMPONENTS GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/03_laser_components.jpg";
matrix[j][1] = "http://www.lasercomponents.com";
matrix[j][2] = "LASER COMPONENTS GmbH";
matrix[j][3] = "clicktrack ct_laser";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/lasercomponents');";
j++;

// FISBA Optik
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/04_fisba.jpg";
matrix[j][1] = "http://www.fisba.com";
matrix[j][2] = "FISBA Optik";
matrix[j][3] = "clicktrack ct_fisba";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/fisba');";
j++;

// Qioptiq Photonics GmbH & Co.Kg
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/05_Qioptiq.jpg";
matrix[j][1] = "http://www.qioptiq-shop.com";
matrix[j][2] = "Qioptiq";
matrix[j][3] = "clicktrack ct_qioptiq";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/qioptiq');";
j++;

// Opsira GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/06_opsira.jpg";
matrix[j][1] = "http://www.opsira.de";
matrix[j][2] = "Opsira GmbH";
matrix[j][3] = "clicktrack ct_opsira";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/opsira');";
j++;

// miCos GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/07_miCos.png";
matrix[j][1] = "http://www.micos-online.com";
matrix[j][2] = "miCos GmbH";
matrix[j][3] = "clicktrack ct_micos";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/micos');";
j++;

// JMAnalytik AG
// matrix[j][0] = new Image();
// matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/08_JMAnalytik.jpg";
// matrix[j][1] = "http://www.j-m.de";
// matrix[j][2] = "JMAnalytik AG";
// matrix[j][3] = "clicktrack ct_JMAnalytik";
// matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/JMAnalytik');";
// j++;

// Piezosystem Jena GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/09_piezosystem.jpg";
matrix[j][1] = "http://www.piezosystem.de";
matrix[j][2] = "Piezosystem Jena GmbH";
matrix[j][3] = "clicktrack ct_piezosystem";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/piezosystem');";
j++;

// Lucas components GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/10_Lucas.jpg";
matrix[j][1] = "http://www.lucas-jena.de";
matrix[j][2] = "Lucas components GmbH";
matrix[j][3] = "clicktrack ct_Lucas";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/Lucas');";
j++;

// Vistec Electron Beam GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/11_Vistec.jpg";
matrix[j][1] = "http://www.vistec-semi.com";
matrix[j][2] = "Vistec Electron Beam GmbH";
matrix[j][3] = "clicktrack ct_vistec";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/vistec');";
j++;

// SVS-Vistek GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/12_SVS-Vistek.jpg";
matrix[j][1] = "http://www.svs-vistek.com";
matrix[j][2] = "SVS-Vistek GmbH";
matrix[j][3] = "clicktrack ct_SVS-Vistek";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/SVS-Vistek);";
j++;

// S&R Optik GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/13_SR-Optik.jpg";
matrix[j][1] = "http://www.sr-optic.com";
matrix[j][2] = "S&R Optik GmbH";
matrix[j][3] = "clicktrack ct_SR-Optik";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/SR-Optik');";
j++;

// S1 Optics GmbH
matrix[j][0] = new Image();
matrix[j][0].src = "http://optecnet.de/portal_skins/custom/ads_2011/14_S1 Optics.jpg";
matrix[j][1] = "http://www.s1optics.com";
matrix[j][2] = "S1 Optics GmbH";
matrix[j][3] = "clicktrack ct_S1 Optics";
matrix[j][4] = "javascript: pageTracker._trackPageview ('/ausgehend/S1 Optics');";
j++;


// compareFunction for array.sort
function randOrd() {
  return (Math.round(Math.random())-0.5); 
} 

// randomize the array
matrix.sort( randOrd );



// use for uniform naming 
// for (i = 0; i < numImages; i++)
// {
//   dimages[i]=new Image();
//   dimages[i].src="images/image"+(i+1)+".jpg";
// }


var curImage = -1;
var curLink = -1;

function swapPicture() {
 
  // id bannerLink and bannerImage must be present in source document
  if (document.getElementById("bannerLink") && document.getElementById("bannerImage"))
  {
    var nextImage = curImage + 1;
    var nextLink = curLink + 1;
    
    // check for wrapping
    if (nextImage >= numImages) {
      // randomize array again if all images are displayed and the sequence begins from the start
      // note that old_array: last image = new_array: first image can occur
      matrix.sort( randOrd );
      nextImage = 0;
      if (nextLink >= numImages)
      nextLink = 0;
    }
    // if (document.all && matrix[nextImage][0] && matrix[nextImage][0].complete)
    if (matrix[nextImage][0])
    {
      var target = 0;
      var link = 0;
      var title = 0;

      if (document.getElementById("bannerImage"))
        target = document.getElementById("bannerImage");
      if (document.getElementById("bannerLink"))
        link = document.getElementById("bannerLink");
  
      // make sure target is valid.  It might not be valid if the page has not finished loading
      if (target)
      {
        // matrix [..][0] holds image and image source
        target.src = matrix[nextImage][0].src;
        curImage = nextImage;
	
        if (link) {
          // matrix [..][1] holds link
	  link.href = matrix[nextLink][1];

          // matrix [..][2] holds link title
          link.title = matrix[nextLink][2];

          // matrix [..][3] holds clicktrack class
          // document.getElementById("bannerLink").setAttribute("class", "myclass");
          // link.class = matrix[nextLink][3];
          // below was working
          // link.setAttribute("class", matrix[nextLink][3]);
          link.setAttribute("class", matrix[nextLink][3]);
          
          //google tracking code
          //link.setAttribute("onClick", matrix[nextLink][4]);

	  curLink = nextLink;
	}
      }
      else {
        setTimeout("swapPicture()", 250);
      }

      setTimeout("swapPicture()", 5000);

    }
    else
    {
      setTimeout("swapPicture()", 250);
    }
  }
}
// moved to main body onload tag
// setTimeout("swapPicture()", 500);


/* ----- jquery.clicktrack.js ----- */
(function($){
	
/*

copyright 2008 rebecca murphey
http://blog.rebeccamurphey.com
licensed under creative commons share alike 3.0: http://creativecommons.org/licenses/by-sa/3.0/
usage instructions at http://blog.rebeccamurphey.com

*/

$.fn.clicktrack = function(config) {
	
	if (typeof(config) == 'string') { 
		var options = { remoteScript: config }; 
	} else if (typeof(config) == 'object') {
		var options = config;
	} else {
		return $(this); // need to have a remote script to do anything; abort if we don't have one
	}
	
	
	// you can override the defaults by passing a configuration object when calling the plugin. 
	// for example: 
	//
	//		$('a.clicktrack').clicktrack({remote_script: 'foo.php', sendOnce: false});
	//
	// this will send the clicktrack to the server every time the link is clicked, rather than sending it once
	
	var defaults = {
		remoteScript: null,			// the location of the remote script on your server; 
									// this can also be passed as a string argument (see above)
		prefix: 'ct_',				// the prefix for additional class names that should be passed to the server  
		extraData: null,			// extra data to be sent to the remote script
		callback: function() {},	// a callback function to be executed when the remote script succeeds
		dataType: 'json',			// the format of the data you expect to get back from the remote script
		sendOnce: false,			// whether clicktracks should be sent once (true) or for every click (false)
		preventDefault: false		// whether clicks on clicktrack links should be prevented from taking the user to another page (true)
									// or be followed as expected (false)
	};
	
	var settings = $.extend(defaults, options, true);
	
	var source = document.location.toString();
	
	return $(this).click(function(e) {
		
		if (settings.preventDefault) { e.preventDefault(); }

		var $this = $(this);
        
		if (! $this.hasClass('js_no_clicktrack')) {

			if (settings.sendOnce) { $this.addClass('js_no_clicktrack'); }

			var href = $this.attr('href');
	
			var classNames = $this.attr('class').split(' ');
			var classArray = [];
	
			$.each(classNames, function(i,v){
				if (v.match(settings.prefix)){
					classArray.push(v);
				}
			});
	
			var default_data = {
				classes: classArray,
				source: source,
				target: href
			};
	
			var clicktrack_data = $.extend(default_data,settings.extraData);

                        // http://api.jquery.com/jQuery.param/
                        // var shallowEncoded = $.param(clicktrack_data);

			
			$.post(
				settings.remoteScript,
				clicktrack_data,
				settings.callback,
				settings.dataType
			);
		}
		
		if (settings.preventDefault) { return false; } else { return true; }
		
		window.location = href; 
	})	
}

})(jQuery)

