function isiOS() {
	if ((navigator.userAgent.match(/iPhone/i) != null) ||
				(navigator.userAgent.match(/iPad/i) != null) ||
				(navigator.userAgent.match(/iPod/i) != null)) {
		return true;
	}
	else {
		return false;
	}
}

function isAndroid() {
	var ua = navigator.userAgent.toLowerCase();
	var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
	return isAndroid;
}

function isWindows() {
	if (navigator.appVersion.indexOf("Win") != -1) {
		return true;
	}
	else {
		return false;
	}
}

$(document).ready(function () {
	$('#homeGallery').cycle({
		timeout: 6000,
		fx: 'scrollDown',
		easing: 'easeOutExpo',
		speed: '1200',
		before: function (curr, next, opt, ff) {
			var idx = $('#homeGallery a').index(next);
			$('#homepageMenu li').eq(idx).siblings().animate({ width: 320 }, 250);
			$('#homepageMenu li').eq(idx).animate({ width: 370 }, 250);
		}
				
		
	});
	
	$("a.youTubeVideo").click(function()
  {

      $.fancybox({

        'padding'             : 0,

        'autoScale'   				: false,

        'transitionIn'        : 'none',

        'transitionOut'       : 'none',

	      'overlayColor'        : '#000',

	      'overlayOpacity'      : '0.75',

        'title'               : this.title,

        'width'               : 640,

        'height'              : 390,

        'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),

        'type'                : 'swf',    // <--add a comma here

        'swf'                 : {'allowfullscreen':'true'} // <-- flashvars here

      });



      return false;

    });

	$.ajax({
		url: 'https://api.twitter.com/1/statuses/user_timeline.json',
		type: "GET",
		data: "include_entities=true&include_rts=true&screen_name=recognition1st&count=5",
		dataType: 'jsonp',
		cache: true,
		error: function (xhr, status, error) {

		},
		success: function (results) {
			addTweets('twitterFeed', results);
			$('#twitterFeed').cycle({
				timeout: 4600,
				fx: 'scrollRight',
				easing: 'easeOutExpo',
				speed: '2000'
			});
		}
	});

	if ((isAndroid() == false) && (isiOS() == false)) {
		$("#topNav > ul > li > .sub").css({ 'opacity': '0' });
		$("#topNav > ul > li").hoverIntent(megaDropDownConfig);
	}
});


function addTweets(toDiv, newTweets) {
	var newTweetString = '';
	for (xx in newTweets) {
		newTweetString += '<div class="tweet">';
		newTweetString += '    <a href="' + getlink(newTweets[xx].text) +'">' + newTweets[xx].text + '</a>';
		newTweetString += '</div>';
	}
	$('#' + toDiv).html(newTweetString);
}

if (isWindows() == true) {
	Cufon.replace('.footerLinkText strong, #twitterFeedUser, #headerContactContainer, #homepageMenu, #headerTitle, h2, h3, h1#mainTitle');
	//Cufon.replace('#topNav a', {hover: true});
}

function autolink(s) {
	var hlink = /\s(ht|f)tp:\/\/([^ \,\;\:\!\)\(\"\'\<\>\f\n\r\t\v])+/g;
	return (s.replace(hlink, function ($0, $1, $2) {
		s = $0.substring(1, $0.length);
		// remove trailing dots, if any
		while (s.length > 0 && s.charAt(s.length - 1) == '.') s = s.substring(0, s.length - 1);
		// add hlink
		return " " + s.link(s);
	}
	));
}

function getlink(s) {
	var hlink = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	var results = hlink.exec(s);
	if((results != null) && (results.length > 0)) {
		return results[0];
	} else {
		return "#";
	}
}
