/* Author: Michael Becker

*/
var browser_issue_exists = false;

var default_img = 'img/bg_default_img2.jpg';

//var browser = jQuery.uaMatch(navigator.userAgent).browser;

// use jquery's built in $.browser property to check for IE
if ($.browser.msie)
{
	//console.log("There are better browsers you know");
	
	if ($.browser.version<9)
	{
		//console.log("Not only does your browser suck but you are using an old version of it!");
		// use static image on homepage
		browser_issue_exists = true;
	}
}
// check for iOS browsers & chrome (chrome has issues displaying f/s background video?)
/*if (( navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i) ) || (navigator.userAgent.match(/Chrome/))) {
  browser_issue_exists = true;
}*/

// check for chrome, as it has issues displaying resized bg video in html (as of the time this was built)
if (navigator.userAgent.match(/Chrome/)) {
  browser_issue_exists = true;
}

// on init
//---------------------------------------------------------
 $(function() {
	
	// prep social icons
	$('.nav-twitter-icon').css({ "opacity": 0.4, "display": "inline-block"});
	$('.nav-linkedin-icon').css({ "opacity": 0.4, "display": "inline-block"});
	
	// add social icon event handlers
	$('.nav-twitter-icon').hover(
		function () {
			$(this).stop().animate({"opacity": 1}, 'fast');
		},
		function () {
			$(this).stop().animate({"opacity": 0.4}, 'fast');
		}
	);
	
	$('.nav-linkedin-icon').hover(
		function () {
			$(this).stop().animate({"opacity": 1}, 'fast');
		},
		function () {
			$(this).stop().animate({"opacity": 0.4}, 'fast');
		}
	);

	// determine which page this is and load functions accordingly
	var bodyID = $("body").attr("id");		
	
	// auto select nav items
	// http://docs.jquery.com/Tutorials:Auto-Selecting_Navigation#The_New_Solution
	var path = location.pathname.substring(1);
	
	if ( path )
		$('#nav-links a[href$="' + path + '"]').attr('class', 'selected');		
	
	// based on which page loads this file, call only the necessary page functions
	//---------------------------------------------------------
	switch (bodyID){
		
		case "home" :
			
			//$('body').css({"background": "url(/img/bg_default_img2.jpg) no-repeat"})
			
			if (!browser_issue_exists) {
				//console.log('activating :: fs image');
				var videobackground = new $.backgroundVideo('$(body)', {
						"width": 1280,
						"height": 720,
						"path": "video/",
						"filename": "ii_video_bg",
						"types": ["mp4","ogg","webm"]
				});
				/*$('body').prepend('<div class="video-background"></div>');
				$('.video-background').videobackground({
					videoSource: ['video/ii_video_bg.mp4',
						'video/ii_video_bg.webm', 
						'video/ii_video_bg.theora.ogv'],
					loop: true,
					poster: 'img/bg_default_img2.jpg',
					resize: true,
					loadedCallback: function() {
						//$(this).videobackground('mute', {controlPosition: '#main'});						
						$(this).animate({opacity: 1}, 4000);
						
					}
				});*/
			} else {
				// no native video support available :(
				// add f/s image plugin here
				//console.log('video unavailable');
				activateFsImg();
			}
					
		   
		   // hover animation for index cta
		   $(".index-cta").hover(function(){
				$(this).stop().animate({"opacity": 1.0}, 'fast');
			},function(){
				$(this).stop().animate({"opacity": 0.4}, 'fast');
			});
		   
		   // hover animation for index cta
		   $(".index-h2").hover(function(){
				$(".index-cta").stop().animate({"opacity": 1.0}, 'fast');
			},function(){
				$(".index-cta").stop().animate({"opacity": 0.6}, 'fast');
			});
			
			break;
		
		case "about" :
			
			// nothing special here!
			
			break;
		
		case "team" :
			
			// add hover fade effect to images
			$('.team-thumb-img').hover(
				function () {
					$(this).stop().animate({"opacity": 0.6}, 'fast');
				},
				function () {
					$(this).stop().animate({"opacity": 1}, 'fast');
				}
			);
			
			break;
		
		case "profile" :		
			
			// force selected state on profile page
			$('#nav-links li a.team').addClass('selected');
			
			break;
			
		case "work" :
		
			// initialize scrollable with mousewheel support
			$(".scrollable").scrollable({ vertical: true, mousewheel: false });
			
			// add hover fade effect to images
			$('.item-img').hover(
				function () {
					$(this).stop().animate({"opacity": 0.6}, 'fast');
				},
				function () {
					$(this).stop().animate({"opacity": 1}, 'fast');
				}
			);
			
			break;
			
		case "casestudy" :
		
			// force selected state on profile page
			$('#nav-links li a.work').addClass('selected');
			
			
			// add hover fade effect to images
			$('.cs-thumb').hover(
				function () {
					$(this).stop().animate({"opacity": 0.6}, 'fast');
				},
				function () {
					$(this).stop().animate({"opacity": 1}, 'fast');
				}
			);
			
			break;
			
		case "contact" :
			
			$("#fname").alphanumeric({ichars:'0123456789.@#/\{}[]&$%!()*^?><,.:;"|+=_~`\"'}); 	// don't allow numbers in name fields
			$("#lname").alphanumeric({ichars:'0123456789.@#/\{}[]&$%!()*^?><,.:;"|+=_~`\"'}); 
			$("#email").alphanumeric({ichars:'#/\{}[]&$%!()*^?><,:;"|+=_~`\'"'}); 	// don't allow numbers in name fields
			$("#emailConfirm").alphanumeric({ichars:'#/\{}[]&$%!()*^?><,:;"|+=_~`\'"'}); 	// don't allow numbers in name fields
			$("#phone").numeric({allow:"-"});
			
			// activate custom select styling
			//http://labs.abeautifulsite.net/projects/js/jquery/selectBox/
			$("SELECT").selectBox();
			$("SELECT").selectBox('settings', { menuTransition: 'slide', menuSpeed: 'normal'});
			
			break;		
	}
	
 }); 


// moves shadowbox close button to top right
function moveCloseLink(){ 
    var cb=document.getElementById('sb-nav-close'); 
    var tb=document.getElementById('sb-title'); 
    if(tb) tb.appendChild(cb); 
}

// activate the f/s bg image plugin
function activateFsImg() {
	$.supersized({
		slides  :  	[ {image : default_img, title : 'Influence Interactive'} ]
	});	
}


/*if (Modernizr.video) {
  // let's play some video!
} else {
  // no native video support available :(
  // maybe check for QuickTime or Flash instead
}*/


