/**
	Update Build Info after test & upgrading 
	new JQuery versions
	----------------------------------------
	Built off of JQuery framework: v 1.2.3
	Built off of sIFR framework: v 2.0.5
*/

// All functions that must be run on doc ready.
	// @SEE ../global.js
	Lightbox.settings.defaults.width = 400;
	Lightbox.settings.defaults.height = 470;	
/* Replacement calls. Please see documentation for more information. */
$(document).ready
(
	function () {
		
		removeLinkBorders();
		removeTabBorders();
		addHomeLink();
		loadNews();
		//addTargets();
		
		$('a[rel=certdemo-form]').click(function() {

		    Lightbox.pull('../../common/forms/certdemo/form.html', { width: 400, height: 470 }); // @NOTE: Provide the path to your form html file here.
		    return false;  

		});
		
	//	$("#register").load("../../system/php/registration.inc");
		// Add the functionality to "close" the Register window
	//	$("#div_register_close").click(function (){alert('here'); $("#register").fadeOut("slow");});
		// When you click on a resource-link class anchor
		$(".resource-link").click(function ()
		{
		
		var fn = this.href.substring(this.href.lastIndexOf('=')+1,this.href.length);
		
		elqCode = $(this).attr('rel');
		  
	//	  var top = (($(window).height() - $("#register").height())/2 ) + $(window).scrollTop() + "px";
	//	  var left = (($(window).width() - $("#register").width())/2) + "px";
		  
	//	  $("input[@id=inquiryForm-cancel]").click(function () 
	//	  {
	//		$("#register").fadeOut("slow");
	//	  });
	//      $("form.registration-form").submit(function()
	//	  {
	//	      if(validateForm($(this),0,true) == true)
	//	      { 
	//	         window.open('../../system/php/download.php?reg=1&first_name=' + document.getElementById('first_name').value + '&last_name=' + document.getElementById('last_name').value + '&state=' + document.getElementById('state').value + '&company=' + document.getElementById('company').value + '&title=' + document.getElementById('title').value + '&phone=' + document.getElementById('phone').value + '&email=' + document.getElementById('email').value + '&fn=' + fn,"resourcecenter");
	//	         checkForCookie();
	//	         $('#register').fadeOut("slow");
	//	         return false;
	//	         
	//	      }
	//	      else
	//	       return false
	//	  });
		  
		  if(checkCookieSet == true)
		  {
		  // window.open('../../system/php/download.php?fn='+fn,'resourcecenter');
		    $.post('../../system/php/download.php', 
		               {fn: fn}, 
		               function(data)
		               {  
		                 window.open(data, "resourcecenter");         
		               }
		             );

		  }
		  else
		  {
			//loadRegForm($('#register'));
			
			 
			 
		    Lightbox.pull('../../common/forms/form_v2/registration.html', { width: 500, height: 600 }); // @NOTE: Provide the path to your form html file here.
		    return false;
			
		
		  }
		    return false;
		});
		
		

		

		
		if(typeof sIFR == "function"){
		// This is the preferred "named argument" syntax
			sIFR.replaceElement(named({sSelector:"h2.contentTitle", sFlashSrc:"/themes/site_themes/net.approva/assets/media/swf/frutiger65.swf", sColor:"#000000", sWmode:"transparent", sFlashVars:"offsetTop=2&letterSpacing=-1"}));
			// sIFR.replaceElement(named({sSelector:"h3.headerTag", sFlashSrc:"/themes/site_themes/net.approva/assets/media/swf/frutiger65.swf", sColor:"#000000", sWmode:"transparent", sFlashVars:"offsetTop=2"}));
		};
		
		applySlideToggles();
		
		// @TODO: Let's make this dynamic
		if (document.getElementById('TabbedPanels1')) {
			var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
		}
		
		/*
		function(){
			$("#main-nav li").hover(
				function(){ $("ul", this).fadeIn("fast"); }, 
				function() { } 
			);
			if (document.all) {
				$("#main-nav li").hoverClass ("sfHover");
			}
		} 
		*/
	// start kgd
		$("*[@class=file-link]").click(function () {
												 return getFile(reg,$(this));
												 });
		
		$("a[@class=contact-link]").click(function () {											
			loadContactForm();
		});
		
	// Validate support form (1)
		if ($("form[@id=supForm]")) {
			$("form[@id=supForm]").submit(
			function() {
  				return validateForm($(this));
			});
		
			$("input[@id=supForm-cancel]").click(
			function () {
				unloadForm($("form[@id=supForm]"));
			});
		}
		
		
	// Validate demo form (2)
	if ($("form[@id=demoForm]")) {
		$("form[@id=demoForm]").submit(function() {
  			return validateForm($(this),8);
		});
		
		$("input[@id=demoForm-cancel]").click(function () {
							
							unloadForm($("form[@id=demoForm]"));
							
							});		
	}
	// Validate call form (3)
	if ($("form[@id=callForm]")) {
		$("form[@id=callForm]").submit(function() {
  			return validateForm($(this),7);
		});
		
		$("input[@id=callForm-cancel]").click(function () {
							
							unloadForm($("form[@id=callForm]"));
							
							});		
	}
		
	// Validate email form (4)
	if ($("form[@id=generalForm]")) {
		$("form[@id=generalForm]").submit(function() {
  			return validateForm($(this),1);
		});
		
		$("input[@id=generalForm-cancel]").click(function () {
							
							unloadForm($("form[@id=generalForm]"));
							
							});				   
	}
	
	
	if ($("form[@id=salesForm]")) {
		$("form[@id=salesForm]").submit(function() {
  			return validateForm($(this),2);
		});
		
		$("input[@id=salesForm-cancel]").click(function () {
							
							unloadForm($("form[@id=salesForm]"));
							
							});				   
	}
	if ($("form[@id=serviceForm]")) {
		$("form[@id=serviceForm]").submit(function() {
  			return validateForm($(this),3);
		});
		
		$("input[@id=serviceForm-cancel]").click(function () {
							
							unloadForm($("form[@id=serviceForm]"));
							
							});				   
	}
	if ($("form[@id=rndForm]")) {
		$("form[@id=rndForm]").submit(function() {
  			return validateForm($(this),4);
		});
		
		$("input[@id=rndForm-cancel]").click(function () {
							
							unloadForm($("form[@id=rndForm]"));
							
							});				   
	}
	if ($("form[@id=mediaForm]")) {
		$("form[@id=mediaForm]").submit(function() {
  			return validateForm($(this),5);
		});
		
		$("input[@id=mediaForm-cancel]").click(function () {
							
							unloadForm($("form[@id=mediaForm]"));
							
							});				   
	}
	if ($("form[@id=feedbackForm]")) {
		$("form[@id=feedbackForm]").submit(function() {
  			return validateForm($(this),6);
		});
		
		$("input[@id=feedbackForm-cancel]").click(function () {
							
							unloadForm($("form[@id=feedbackForm]"));
							
							});				   
	}

	if ($("form[@id=emailForm]")) {
		$("form[@id=emailForm]").submit(function() {
  			return validateForm($(this));
		});
		
		$("input[@id=emailForm-cancel]").click(function () {
							
							unloadForm($("form[@id=emailForm]"));
							
							});				   
	}
	// Validate login form (5)
	if ($("form[@id=loginForm]")) {
		$("form[@id=loginForm]").submit(function() {
  			return validateForm($(this));
		});
		
		$("input[@id=loginForm-cancel]").click(function () {
							
							unloadForm($("form[@id=loginForm]"));
							
							});
	}
	// Validate registration form (6)
	if ($("form[@id=regForm]")) {
		$("form[@id=regForm]").submit(function() {
  			return validateForm($(this));
		});
		
		$("input[@id=regForm-cancel]").click(function () {
							
							unloadForm($("form[@id=regForm]"));
							
							});
	}
	// Validate applicant form (7)
	if ($("form[@id=appForm]")) {
		$("form[@id=appForm]").submit(function() {
  			return validateForm($(this),9);
		});
		
		$("input[@id=appForm-cancel]").click(function () {
							
							unloadForm($("form[@id=appForm]"));
							
							});
	}
	// end kgd
	
	loadRolodeck();

	}
);

function loadRolodeck () {
	var imageArray = new Array(	{img:"/assets/images/promos/analyst-corner_gartner-report.jpg", link:"/system/php/register.php?fn=1cc3f3fa162330b5c5aef65b27399ecb"}
						);
	
	//{img:"/assets/images/promos/analyst-corner.gif", link:"http://response.approva.net/content/GartnerMarketScopeAE"},
	var card = Math.floor(Math.random() * imageArray.length);
	
	$('#rolodeck').attr('href',imageArray[card].link);
	$('#deckslot').attr('src',imageArray[card].img);
}

queuePos = 0;

imageArray = new Array({img:"/assets/images/promos/analyst-corner_gartner-report.jpg", link:"/system/php/register.php?fn=1cc3f3fa162330b5c5aef65b27399ecb"} //"/assets/images/promos/analyst-corner.gif", link:"http://response.approva.net/content/GartnerMarketScopeAE"}
					);

function fadeloadRolodeck () {
		
	queuePos++;
		
	if (queuePos == imageArray.length) {queuePos = 0;}
	
	$("#deckslot").fadeOut(1000);	

	
	var s = setTimeout('changeDeck()', 1000);	
	var f = setTimeout('$("#deckslot").fadeIn()',1000);

	var a = setTimeout("loadRolodeck()",10000);
	
	
}
function changeDeck() {
	$('#rolodeck').attr('href',imageArray[queuePos].link);
	$('#deckslot').attr('src',imageArray[queuePos].img);
}

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};