$(document).ready(function () {
	
	/* Makes menu "interactive" */
	$('#menu .dropdown').each(function () {
		$(this).parent().eq(0).hover(function () {
			$('.dropdown:eq(0)', this).show();
		}, function () {
			$('.dropdown:eq(0)', this).hide();
		});
	});
	
	buildSitemap();
	fillRSS();
	
	if(iOS() == true){
		swapVideo();
	};
	
})

	function iOS(){
		return (
			//Detect iPad
			(navigator.platform.indexOf("iPad") != -1) ||
			//Detect iPhone
			(navigator.platform.indexOf("iPhone") != -1) ||
			//Detect iPod
			(navigator.platform.indexOf("iPod") != -1)
			);
	}

function swapVideo(){
	var url = $('.video object').attr('alt');
	var w = $('.video object').attr('width')
	var h = $('.video object').attr('height')
	$('.video').html('<video width="'+w+'" height="'+h+'" controls="controls" preload="auto"><source src="'+
	url
	+'" type="video/mp4" /></video>');	
}

function buildSitemap() {
	$('#footer').prepend($(document.createElement('div')).attr("id","sitemap"));
	$('#sitemap').prepend($(document.createElement('h2')).text("Sitemap"));
	
	ul1 = $(document.createElement('ul')).appendTo('#sitemap');
	ul2 = $(document.createElement('ul')).appendTo('#sitemap');
	ul3 = $(document.createElement('ul')).appendTo('#sitemap');
	
	smap = $('#menu').children();
	smap.each(function(i){
		if (i < 2) {
			$(this).clone().appendTo($(ul1));return;
		} else if (i < 4 ) {
			$(this).clone().appendTo($(ul2));return;
		} else if (i < smap.size()) {
			$(this).clone().appendTo($(ul3));return;
		} else {}
	});
}

function fillRSS() {
	var newsRSS = $('#news');
	var blogRSS = $('#blog');
	if(newsRSS.length>0) {
		newsRSS.append('<h2 class="loading">News</h2>');
		newsRSS.load('/includes/rss-news.php', function(){});
	}	
	if(blogRSS.length>0) {
		blogRSS.append('<h2 class="loading">Blog</h2>');
		blogRSS.load('/includes/rss-blog.php', function(){});
	}
}

// anti spam email addresses

var at = String.fromCharCode(64);
var d = 'concisegroup.com';

function emailLink(cl, w, title, ret_em)
{
	return '<a class="' + cl + '" href="mailto:' + w + at + d + '" title="' + title + '">' + ((ret_em) ? w + at + d : '') + '</a>';
}

//Front page slider

	//Variables
	interval = 4000 // Delay before fade
	fadeRate = 200 // Time taken to fade
	c = 0; // Starting Item
function cycleNext(){
	  if(c>=totalItems){n=0;}else{n=c+1;};

	  $('#start .about span:eq('+c+')').fadeOut(fadeRate, function(){
	   $('#start .about span:eq('+n+')').fadeIn(fadeRate);
	  });
	  c=n;
	t=setTimeout('cycleNext()', interval);
}





$(document).ready(function(){
	// 
	// totalItems=$('#start .about span').length-1;
	// $('#start .about span').not(':eq(0)').hide();
	// t=setTimeout('cycleNext()', interval);


// Wordpress Hack
	$('#single h1').wrapInner('<a href="./">');	

// Contact Hover box

	$('#menu a[href$="contact/"]').hover(function(){
		$('#callbox').show();	
	}, function(){
		$('#callbox').hide();	
	});
	
	// WP Video Thumbnails
	$('.post').not($('#single .post')).each(function(){
		if($('.videothumb',this).length>0){
			$('img:first',this).hide();
			$('.videothumb',this).show();
		}
		$('img',this).wrap('<a href="'+$('.more-link', this).attr('href')+'"></a>"');
	});

});


