var DGI = DGI || {};


DGI = DGI.prototype = {
	init: function(){
		DGI.listeners();
		DGI.initQuotes();
	},
	listeners: function(){
		$(".logo, .nocolor").click(function(){
			window.location = '/index.php';
		});
		$(".logo").mouseover(function(){
			DGI.logoAnimation();
		});
		$("#seeBox, #red").click(function(){
			window.location = "/our-work.php"
		});
		$("#clientsBox, #blue").click(function(){
			window.location = "/clients.php"
		});
		$("#meetBox, #purple").click(function(){
			window.location = "/meet-the-team.php"
		});
		$("#getBox, #green").click(function(){
			window.location = "/contact.php"
		});
		$(".sample").click(function(){
			window.location = $(this).attr('href');
		});
		$("#red,#blue,#purple,#green,#seeBox,#clientsBox,#meetBox,#getBox").mouseover(function(){
			DGI.moveBox(this.id)
		});
		
		$(".left .arrowLink").click(function(){window.location = '/our-work.php'});
		$(".right .arrowLink").click(function(){DGI.openSite($(this).attr('href'));});
		
		$(".person").click(function(){DGI.showBio($(this).attr('index'))});
		
		$(".fb").click(function(){DGI.openSite("http://www.facebook.com/DGInteractive");});
	},
	
	logoAnimation:function(){
		var logo = $(".logo");
		logo.unbind('mouseover');
		var nocolor = $(".nocolor");
		nocolor.removeAttr("style").css({'height':'60px','top':'0'});
		logo.removeAttr("style").css('height','0');
		nocolor.show();//.delay(400).animate({'height':'0'},1000);
		logo.delay(395).animate({'height':'60px'},1000,function(){$(".logo").mouseover(function(){DGI.logoAnimation();}); nocolor.fadeOut('slow');});
	},
	homeAnim:function(){
		var logo = $(".logo");
		logo.unbind('mouseover');
		var nocolor = $(".nocolor");
		logo.delay(1000).animate({'height':'60px'},1000,function(){$(".logo").mouseover(function(){DGI.logoAnimation();}); nocolor.fadeOut('slow');});		
	},
	
	openSite:function(url){
		window.open(url);
	},
	
	moveBox: function(id){
		var obj = $("#" + id);
		obj.unbind('mouseover');
		if (obj.css('left') == 'auto') {
			obj.animate({
				top: '+=10',
				right: '-=10'
			}, 200, function(){
				obj.animate({
					top: '-=10',
					right: '+=10'
				}, 200, function(){
					obj.mouseover(function(){
						DGI.moveBox(id)
					})
				});
			})
		}
		else{
			obj.animate({
				top: '+=10',
				left: '+=10'
			}, 200, function(){
				obj.animate({
					top: '-=10',
					left: '-=10'
				}, 200, function(){
					obj.mouseover(function(){
						DGI.moveBox(id)
					})
				});
			})
			
		}
		
	},
	
	showBio: function(i){
		var bio = $(".bio");
		var person = $(".person");
		person.removeClass("selected").removeClass("selectedR");
		bio.hide();
		if(i < 4) person.eq(i).addClass("selected");
		else person.eq(i).addClass("selectedR");
		bio.eq(i).fadeIn('250');
	},
	
	quotes: $("#mainBox .copy"),
	currentQuote: 0,
	initQuotes: function(){
		setTimeout(function(){DGI.rotateQuote()},'8000');
	},
	
	rotateQuote: function(){
		if (DGI.currentQuote >= DGI.quotes.length - 1) {
		DGI.quotes.eq(DGI.currentQuote).hide('250');
		DGI.quotes.eq(0).show('250');
		DGI.initQuotes();
		
		return false;
		}
		else{
		DGI.quotes.eq(DGI.currentQuote).hide('250');
		DGI.currentQuote++;
		DGI.quotes.eq(DGI.currentQuote).show('250');
		DGI.initQuotes();
		}
	},
	
	showWork:function(id){
		switch(id){
			case "s1": window.location="/case-studies/inetbets-ad.php"; break;
			case "s2": window.location="/case-studies/inetbets-logo.php"; break;
			case "s3": window.location="/case-studies/lg-mobile.php"; break;
			case "s4": window.location="/case-studies/zenith.php"; break;
			case "s5": window.location="/case-studies/lg-hdtv.php"; break;
			case "s6": window.location="/case-studies/canon-hd.php"; break;
			case "s7": window.location="/case-studies/hotel-magician.php"; break;
			case "s8": window.location="/case-studies/canon-lifesciences.php"; break;
			case "s9": window.location="/case-studies/newtek.php"; break;
			case "s10": window.location="/case-studies/canon-brochures.php"; break;
			case "s11": window.location="/case-studies/bosco.php"; break;
			default:window.location="/case-studies/bosco.php";break;
		}
	}
}

$(function(){DGI.init();});

