
//here you place the ids of every element you want.
var ids=new Array('post-entry','cforms');

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
	$primary = $('#primary'), $secondary = $('#secondary');
	$primary.height('auto');
if($primary.find('div.section').length == 1){
			$primary.find('div.section').height('auto');
		}
	checkHeight($primary, $secondary);
}

$(document).ready(function(){
	
	$('#primaryNav').superfish({ 
	    pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass 
	    delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
	    autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
	    dropShadows:   false,               // completely disable drop shadows by setting this to false 
	    disableHI:     false              // set to true to disable hoverIntent detection 
	});
	
	newsTicker.init('.testimonials');
	
	if ($('a[@rel="download"]').length == 1) {
		$('a[@rel="download"]').each(function(){
			window.open($(this).attr('href'));
		});
	}
	
	$primary = $('#primary'), $secondary = $('#secondary');
	
	checkHeight($primary, $secondary);
	
	if($secondary.find('div.section').length == $primary.find('div.section').length){
		
		$primary.find('div.section').each(function(i){
			if($secondary.find('div.section:eq(' + i + ')').height() > $primary.find('div.section:eq(' + i + ')').height()){
				$primary.find('div.section:eq(' + i + ')').height($secondary.find('div.section:eq(' + i + ')').height());
			} else {
				$secondary.find('div.section:eq(' + i + ')').height($primary.find('div.section:eq(' + i + ')').height());
			}
		});
	}
	
	$('#cforms a.back').prependTo('#cforms2form p.cf-sb');
	
});

function checkHeight($primary, $secondary){

	if($secondary.height() > $primary.height()){
		$primary.height($secondary.height());
		if($primary.find('div.section').length == 1){
			$primary.find('div.section').height($secondary.height() - 40);
		}
	}
}

var newsTicker = (function($){
	
	var $ticker, $current, interval;
	
	return {
		start: function(){
			$current = $ticker.find('li:visible');
			interval = window.setInterval(function(){
				newsTicker.next();
			}, 20000);
		},
		next: function(){
			if($current.next('li').length == 1){
				$current.fadeOut('slow', function(){
					$next = $current.next('li');
					$next.fadeIn('slow');
					$current = $next;
				});
			} else {
				$current.fadeOut('slow', function(){
					$next = $ticker.find('li:first');
					$next.fadeIn('slow');
					$current = $next;
				});
			}
			
		},
		init: function(selector){
			$ticker = $(selector);
			var height = 0, length = $ticker.find('li').length - 1;
			$ticker.find('li').each(function(){
				if($(this).height() > height){
					height = $(this).height();
				}
			});
			
			$ticker.parent('.section').height(height);

			var startIndex = Math.floor(Math.random()*length);

			$ticker.find('li:not(:eq(' + startIndex + '))').css({display: 'none'});
			this.start();
		}
	}
	
})(jQuery);

