$(document).ready(function() {
	// Door animation
	/*$("#header").after('<div id="loader"></div>');
	$("#loader").click(function() {
		$(this).fadeOut("slow");
	})
	.html('Insert loader here.').after('<div id="door"></div>');
	
	$("#door").click(function() {
		$("#door-left").animate({left: "-2000px"}, 2000);
		$("#door-right").animate({right: "-2000px"}, 2000);
		$("#fade").stop().animate({opacity: "0"}, 3000, "swing");
		setTimeout("$('#door').hide()", 3000);
		setTimeout("$('#fade').hide()", 3000); 
	})
	.append('<div id="door-inner"><div id="door-left"></div><div id="door-right"></div></div>')
	.after('<div id="fade"></div>');*/
	
	$("#runme").click(function() {
		$.preloadCssImages({statusTextEl: '#textStatus', statusBarEl: '#status'});	
	});

	// Floating bubbles
	$('div.bubble').bubble({
		'trigger' : '.trigger', // selector for the trigger element
		'popup' : '.popup', // selector for the actual bubbe (within div.bubble)
		'distance' : 10, // distance in px it will travel
		'hideDelay' : 500, // time before hiding
		'effectTime' : 250 // total time for effect
	});

	/**************************************** ROOM UNO ****************************************/

	// Set clock
	playTime2();	
	
	// Chatbox global vars
	var pHeight = 0;
	var serviceMe = 0;
	var serviceLevel = 1;
	var forminput =
	'env_report=REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER&' +
	'recipients=support@mojo301.com&' +
	'derive_fields=realname=name, email=email&' +
	'mail_options=Exclude=x;y,NoEmpty&' +
	'subject=New enquiry received!&' +
	'template_list_sep=<br />&' +
	'mail_options=HTMLTemplate=enquiry.htm,TemplateMissing=N/A,NoPlain&';
	var userinput = forminput;
	
	if (location.hash.slice(1) == "contact-us" && $("#chatbox").css("display") == "none") {
		initializeChatBox();
		pHeight = $("#chatwindow-message-inner").innerHeight();
	}
	
	$("#receptionist,#main-nav img[alt=Contact Us]").click(function() {
		if ($("#chatbox").css("display") == "none") {
			initializeChatBox();
			pHeight = $("#chatwindow-message-inner").innerHeight();
		}
	});
	
	$("#chatbox #chathead a").click(function() {
		$("#chatbox")
		.animate({marginTop: "240px"}, {duration: 1000, easing: "easeInOutCirc"})
		setTimeout(function() {
			$("#chatbox").css({display: "none"});
			$("#chatwindow-message-inner").css({marginTop: "0px"});
		}, 1000)
	});

	$("#chatinput").keyup(function(event) {
		if(event.keyCode == 13) {
			$("#chatsend").click();
		}
	});
	
	$("#chatcontrols img").hover(function() {
		var temp = $(this).attr("src").split("/");
		temp = temp[3].split(".");
		temp = temp[0].split("-");
		$(this).attr({src: "images/uno/chat/chat-" + temp[1] + "2.png"}); 
		$(this).attr({id: temp[1]});
		$(this).after('<div class="cc-hover">' + returnChatControl($(this).attr("id")) + '</div>')
		.parent("a").children("div").fadeIn(2000);
	}, function() {
		$(this).attr({src: "images/uno/chat/chat-" + $(this).attr("id") + ".png"}); 
		$(this).parent("a").children("div").css({display: "none"});
	});
	
	$("#chatcontrols a").click(function() {
		if ($(this).children("img").attr("id") == "enquiry")
			$("#chatinput").attr({value: "service"});
		else if ($(this).children("img").attr("id") == "contact")
			$("#chatinput").attr({value: "contact"});
		else
			$("#chatinput").attr({value: "help"});		
		$("#chatsend").click();
		
	});
	
	$("#chatsend").click(function() {
		if ($("#chatinput").val() != "") {
			var hideDistance = 0;
			
			$("#chatwindow-message-inner").append("<p class=\"newmsg\"><b class=\"usermsg\">You say:</b> " + getEmoticon($("#chatinput").val()) + "</p>");

			pHeight = pHeight + $("#chatwindow-message-inner").children("p:last").innerHeight()
			if (pHeight > 130) {
				//hideDistance = $("#chatwindow-message-inner").children("p:last").innerHeight();
				hideDistance = pHeight - 130;
				$("#chatwindow-message-inner").animate({marginTop: "-="+hideDistance+"px"});
				pHeight = pHeight - hideDistance;
			}
			
			if (serviceMe == 1) {
				var returnMsg = validateChatMsg($("#chatinput").val(), serviceLevel).split("|");
				if (returnMsg[2] > serviceLevel) {
					userinput = userinput + returnMsg[3] + '=' + $("#chatinput").val();
					serviceLevel++;
					if (serviceLevel == 5) {
						serviceMe = 0;
						serviceLevel = 1;
						$.ajax({
							type: "POST",
							url: "forms/formmail.php",
							data: userinput,
							success: function() {
								userinput = forminput;								
							}
						});
					} else {
						userinput = userinput + '&';					
					}
				}
			} else {
				var returnMsg = processChatMsg($("#chatinput").val()).split("|");
			}

			setTimeout(function() {
				$("#chatstatus").css({display: "block"});
			}, 2000);
			
			setTimeout(function() {
				$("#chatwindow-message-inner").append('<p class="newmsg"><b>Alessandra says:</b> ' + returnMsg[0] + '</p>');
				pHeight = pHeight + $("#chatwindow-message-inner").children("p:last").innerHeight()
				if (pHeight > 130) {
					//hideDistance = $("#chatwindow-message-inner").children("p:last").innerHeight();
					hideDistance = pHeight - 130;
					$("#chatwindow-message-inner").animate({marginTop: "-="+hideDistance+"px"});
					pHeight = pHeight - hideDistance;
				}
				$("#chatstatus").css({display: "none"});
				$("#chatinput").focus().select();
			}, returnMsg[1])

			if ($("#chatinput").val().match(/service/gi) && serviceMe == 0)			
				serviceMe = 1;
		}
	});
	
	$("#chatinput")
	.focus(function() { $(this).addClass("chatfocus"); })
	.blur(function() { $(this).removeClass("chatfocus"); });
	
	$("#chatsend").hover(function() { 
		$(this).removeClass("chatsend1");
		$(this).addClass("chatsend2");
		$(this).css({cursor: "pointer"});
	}, function() { 
		$(this).removeClass("chatsend2");
		$(this).addClass("chatsend1");
		$(this).css({cursor: "default"});
	});
	
	$("#chathead img").hover(function() { 
		$(this).attr({src: "images/uno/chat/close2.png"});
		$(this).css({cursor: "pointer"});
	}, function() { 
		$(this).attr({src: "images/uno/chat/close1.png"});
		$(this).css({cursor: "default"});
	});
	
	$("#receptionist, #stv-btn").hover(function() { 
		$(this).css({cursor: "pointer"});
	}, function() { 
		$(this).css({cursor: "default"});
	});
	

	/**************************************** ROOM DOS ****************************************/
	
	$("#p-txt-1").text("");
	
	// Play about us animation
	var blnAboutUs = 0;
	$("#main-nav li a[href=#about-us]").click(function() {
		if (blnAboutUs == 0) {
			playAboutUs();
			blnAboutUs = 1;
		}
	});
	
	
	/**************************************** ROOM TRES ****************************************/

	var folioOn = 0;
	$("#main-nav li a").eq(2).click(function() {
		if (folioOn == 0) {
			folioOn = 1;
			setTimeout(function() {
				$("#stv-btn").click();		
			}, 1500);
		}
	});

	// Perform animations when organizer is turned on
	// Initialize object properties first
	$("#stv-screen[class=screenoff]").css({opacity: 0});
	$("#tv2-screen").css({opacity: 0});
	$("#tv2-screen-inner").css({height: "30px", width: "0px"});
	
	$("#webgallery,#graphixgallery").append("<ul></ul>");

	$("#webgallery").jcarousel({
		/*animation: 1500,
		auto: 2,
		easing: "BounceEaseOut",*/
		initCallback: mycarousel_initCallback,
		itemLoadCallback: mycarousel_itemLoadCallback,
		visible: 4,
		wrap: "both"
	});

	$("#graphixgallery").jcarousel({
		/*animation: 1500,
		auto: 2,
		easing: "BounceEaseOut",*/
		initCallback: mycarousel_initCallback,
		itemLoadCallback: mycarousel_itemLoadCallback2,
		visible: 4,
		wrap: "both"
	});

	$(".jcarousel-prev-horizontal").addClass("png");
	$(".jcarousel-next-horizontal").addClass("png");

	$("#stv-btn").click(function() {
		if ($(this).hasClass("btnlightoff")) {
			folioOn = 1;
			$(this).removeClass().addClass("btnlighton");
			$("#stv-light").stop(true).find("div").removeClass().addClass("lighton").css({opacity: 0}).animate({opacity: 1}, 1000);
			$("#stv-screen").stop(true).removeClass().addClass("screenon").css({opacity: 0}).animate({opacity: 1}, 2000);
			$("#stv-content").stop(true)
			.css({marginTop: "-200px", marginLeft: "1px"})
			.animate({marginTop: "10px"}, {duration: 500, easing: "easeInOutCirc"}, 500)
			.animate({marginTop: "0px"}, 500);
			$("#stv-content ul#sc-nav-bar").tabs({selected: 0});
			
			buildWebGallery = 1;
	
			$("#tv2-screen").stop(true).css({opacity: 0}).animate({opacity: 1}, 2000);
			$("#tv2-cover-left").stop(true).animate({left: '-385px'}, 10000);
			$("#tv2-cover-right").stop(true).animate({right: '-389px'}, 10000);
			
			setTimeout(function() {
				$("#tv2-screen-content-inner").html("")
				$("#tv2-screen-inner").stop(true).animate({opacity: 1, width: "746px"}, {duration: 500, easing: "easeInOutSine"}, 1000).animate({height: "262px"}, {duration: 1000, easing: "easeInOutExpo"}, 500);
				$("#tv2-welcome").css({display: "block"}).animate({opacity: 1}, 1000);
			}, 4000);							
		} else {
			folioOn = 0;
			$(this).removeClass().addClass("btnlightoff");	
			$("#stv-light").find("div").stop(true).animate({opacity: 0}, 1000);
			$("#stv-screen[class=screenon]").stop(true).animate({opacity: 0}, 1000);	
			$("#stv-content").animate({marginTop: "-200px"}, 500);

			$("#tv2-cover-left").stop(true).animate({left: '0px'}, 10000);
			$("#tv2-cover-right").stop(true).animate({right: '0px'}, 10000);	
			
			setTimeout(function() {
				$("#tv2-screen-inner").stop(true).animate({height: "30px"}, {duration: 500, easing: "easeInOutExpo"}, 500).animate({width: "0px", opacity: 0}, 500);	
			}, 1000);
			setTimeout(function() {
				$("#tv2-screen").stop(true).animate({opacity: 0}, 1000);
			}, 2000);
		}
	});
});

$(function () {
	$.sifr({path:'fonts'});
	//$("#r2-inner").sifr({color: '#666', font: 'Ericsson'});
});

function initializeChatBox() {
	$("#chatbox")
	.css({display: "block", marginTop: "240px"})
	.animate({marginTop: "0px"}, {duration: 2000, easing: "easeInOutCirc"});
	var welcomeMsg = processChatMsg("defMsg").split("|");
	$("#chatwindow-message-inner").html(welcomeMsg[0]);
	$("#chatinput").val("");
	return 1;
}

// Beta chatbox. Will stream in keywords from external file in the future. On to-do list.
function processChatMsg(msg) {
	var returnMsg;
	var randomNumber = Math.floor(Math.random()*4)
	var returnMsgDefault = new Array();
	returnMsgDefault[0] = "Cool! :)";
	returnMsgDefault[1] = "I'm not sure what you meant by that?";
	returnMsgDefault[2] = "Umm...ok?";
	returnMsgDefault[3] = "Can you re-word what you just typed?";

	if (msg.match("defMsg")) {
		returnMsg = "<p class=\"firstmsg\"><b></b> </p><p class=\"newmsg\"><b></b> <span class=\"extra-pad\"><b></b> <a href=\"mailto:support@mojo301.com\"></a></span><b></b> </p>";
	} else if (msg.match(/help/gi)) {
		returnMsg = "Alessandra to the rescue! :) Type in the following commands should you want to get our contact info or if you want to leave an enquiry so I can pass it on to the appropriate people: <span class=\"extra-pad\"><b><i>service</i></b> - leave an enquiry</span><b><i>contact</i></b> - get our contact information<br /><b><i>email</i></b> - get our email";
	} else if (msg.match(/service/gi) || msg.match(/enquiry/gi)) {
		returnMsg = "Ok, let's get the ball rolling shall we? May I have your name please?";
	} else if (msg.match(/contact/gi) || msg.match(/get in touch/gi)) {
		returnMsg = "So you decided to get in contact with us hey? Good move! :) Here's our contact information for you to get in touch with us! <span class=\"extra-pad\"><b>E-mail</b>: <a href=\"mailto:support@mojo301.com\">support@mojo301.com</a></span><b>Contact Number:</b> 0418 208 254 (local) or +61 418 208 254 (international)";
	} else if (msg.match(/email/gi) || msg.match(/e-mail/gi) || msg.match(/emial/gi) || msg.match(/mail/gi)) {
		returnMsg = "Do you want to email us? Send your email to <a href=\"mailto:support@mojo301.com\">support@mojo301.com</a>. Rest assured that we value your privacy and won't be giving it out to anyone!";
	} else if (msg.match(/your number/gi) || msg.match(/number/gi) || msg.match(/digits/gi) || msg.match(/\#/gi) || msg.match(/call/gi)) {
		returnMsg = "Sorry, I don't usually give out my number to strangers but you can call customer support at 0418 208 254 (local) or +61 418 208 254 (international). :)";
	} else if (msg.match(/where are you/gi) || msg.match(/located/gi) || msg.match(/location/gi)) {
		returnMsg = "We are a web design company based in Sydney, Australia. Where are you from?";
	} else if (msg.match(/price/gi) || msg.match(/cost/gi) || msg.match(/quote/gi) || msg.match(/how much/gi)) {
		returnMsg = "For you? Nothing! ;) Nothing that is, but high quality websites for dirt cheap prices! Contact us now and find out!";
	} else if (msg.match(/portfolio/gi) || msg.match(/showcase/gi)) {
		returnMsg = "See what we're made of! Go to the \"Showcase\" room and turn on the small PC screen right in front of you!";
	} else if (msg.match(/who are you/gi) || msg.match(/who you/gi) || msg.match(/who u/gi) || msg.match(/who are ya/gi) || msg.match(/name/gi)) {
		returnMsg = "Hi, my name's Alessandra and I'm Mojo New Media Solution's virtual receptionist. How can I help you today?";
	} else if (msg.match(/hello/gi) || msg.match(/hullo/gi) || msg.match(/hi/gi) || msg.match(/hey/gi) || msg.match(/wassup/gi) || msg.match(/what\'s up/gi)) {
		returnMsg = "Hi there! How are you doing today?";
	} else if (msg.match(/bye/gi) || msg.match(/see ya/gi) || msg.match(/see u/gi)) {
		returnMsg = "Loved the chat! Talk to you soon! :)";
	} else if (msg.match(/gday/gi) || msg.match(/g\'day/gi)) {
		returnMsg = "G'day mate! How's it goin?";
	} else if (msg.match(/how are you/gi) || msg.match(/how are ya/gi) || msg.match(/how are u/gi) || msg.match(/how r u/gi)) {
		returnMsg = "I'm doing great thanks. How are you?";
	} else if (msg.match(/weather/gi)) {
		returnMsg = "What's the matter? Run out of topics already? ;) The weather over here right now is so nice, not too hot and not too cold! How's the weather on your side?";
	} else if (msg.match(/a\/s\/l/gi) || msg.match(/asl/gi)) {
		returnMsg = "20 something female from Sydney. Yourself? :)";
	} else if (msg.match(/fuck/gi) || msg.match(/shit/gi) || msg.match(/cunt/gi) || msg.match(/bitch/gi) || msg.match(/bogan/gi)) {
		returnMsg = "Do you kiss your mother with that mouth? Let's keep it professional please.";
	} else if (msg.match(/whore/gi) || msg.match(/skank/gi) || msg.match(/slut/gi)) {
		returnMsg = "I know you are, but what am I?";
	} else if (msg.match(/stupid/gi) || msg.match(/dumb/gi) || msg.match(/idiot/gi)) {
		returnMsg = "I beg to differ. I'm a very intelligent lady thank you very much.";
	} else if (msg.match(/cock/gi) || msg.match(/dick/gi)) {
		returnMsg = "Potty mouth! :p";
	} else if (msg.match(/blowjob/gi) || msg.match(/headjob/gi)) {
		returnMsg = "Wow! Your success rate with women must be REALLY high!";
	} else if (msg.match(/sex/gi) || msg.match(/intercourse/gi)) {
		returnMsg = "I'm sorry I like 'em big! :p";
	} else if (msg.match(/movie/gi) || msg.match(/dinner/gi) || msg.match(/wanna go out/gi) || msg.match(/wanna go on a date/gi)) {
		returnMsg = "You're going to need to up your game to get with this ;) I'm flattered but sorry, I already have a boyfriend! Can I help you with anything else?";
	} else if (msg.match(/boyfriend/gi) || msg.match(/^bf$/gi)) {
		returnMsg = "Hehe yes, I have one! Aww, are you heartbroken now? :p";
	} else if (msg.match(/girlfriend/gi) || msg.match(/^gf$/gi)) {
		returnMsg = "Hmmmm maybe if I'm wildly drunk? Kidding! ;) Anyway, let's get back to business shall we?";
	} else if (msg.match(/:\(/gi)) {
		returnMsg = "Aww why so sad?";
	} else {
		returnMsg = returnMsgDefault[randomNumber];
	}	
	returnMsg = getEmoticon(returnMsg) + "|" + (returnMsg.length + 4000);
	return returnMsg;
}

function validateChatMsg(msg, level) {
	var returnMsg;
	var returnLevel = level;
	var returnInputField;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var numberReg = msg.replace(/[\(\)\.\-\ ]/g, '');

	if (level == 1) {
		returnMsg = "Hi " + msg + "! Ok next step, what's your email address?";
		returnLevel = 2;
		returnInputField = "name";
	} else if (level == 2) {
		if(!emailReg.test(msg)) {
			returnMsg = "I'm sorry, the email you entered seems to be invalid. Please make sure the format is in [emailname]@[domainname].com format.";
		} else {
			returnMsg = "Fantastic! May I have your contact number now please?";
			returnLevel = 3;
			returnInputField = "email";
		}
	} else if (level == 3) {
		if(isNaN(numberReg)) {
			returnMsg = "I'm sorry, the number you entered seems to be invalid. Please make sure there are no alphabetical or special characters in what you just typed.";
		} else {
			returnMsg = "Great, nearly finished! So what was your enquiry about?";
			returnLevel = 4;
			returnInputField = "number";
		}
	} else if (level == 4) {
		returnMsg = "Your enquiry is being processed as I type this! Thanks for taking the time and have an awesome day! :)";
		returnLevel = 5;
		returnInputField = "enquiry";
	}
	
	returnMsg = getEmoticon(returnMsg) + "|" + ((returnMsg.length * 10) + 4000) + "|" + returnLevel + "|" + returnInputField;
	return returnMsg;
}

function getEmoticon(msg) {
	var imgPath = 'images/uno/chat/';
	var returnMsg = msg.replace(/:\)/gi,'<img src="' + imgPath + '/happy.gif" />').replace(/:\(/gi,'<img src="' + imgPath + '/sad.gif" />').replace(/;\)/gi,'<img src="' + imgPath + '/winking.gif" />').replace(/:p/gi,'<img src="' + imgPath + '/tongue.gif" />');

	return returnMsg;
}

function returnChatControl(id) {
	if (id=="enquiry")
		return "Send enquiry";
	else if (id=="contact")
		return "Contact info";
	else
		return "Help! I'm lost!";
}

function playTime() {
	// initialize time displayed
	var roofclock = (getTime()).split("|");
	$("#r2-inner")
	.html(roofclock[0])
	.sifr({color: '#666', font: 'Ericsson'});
	setInterval(function() {
		var tempclock = (getTime()).split("|")
		if (tempclock[0] != roofclock[0]) {
			$("#r2-inner")
			.html(tempclock[0])
			.sifr({color: '#666', font: 'Ericsson'})
			.append(tempclock[1]);
			roofclock[0] = tempclock[0];
			roofclock[1] = tempclock[1];
		}
	}, 1000);
}

function getTime() {
	var d = new Date();
	var t_hour = d.getHours();
	var t_min = d.getMinutes();

	var t_type;
	var t_full;
	
	if (t_hour >= 12) {
		if (t_hour != 12) t_hour = t_hour - 12;
		t_type = '<img src="images/uno/clock/pm.png" />';
	} else {
		if (t_hour == 0) t_hour = "12";
		t_type = '<img src="images/uno/clock/am.png" />';
	}

	if (t_min < 10) t_min = "0" + t_min;
	
	t_full = t_hour + ":" + t_min + "|" + t_type;
	return t_full;
}

function playTime2() {
	// initialize time displayed
	var roofclock = getTime2();
	$("#r2-inner").html(roofclock)//.css({opacity: 0.8});
	setInterval(function() {
		if (getTime2() != roofclock) {
			$("#r2-inner").stop().fadeOut("slow").fadeIn("slow");
			$("#r2-inner").html(getTime2());	
			roofclock = getTime2();
		}
	}, 1000); 
}

function getTime2() {
	var d = new Date();
	var t_hour = d.getHours();
	var t_min = d.getMinutes();
	
	var t_type;
	var t_full;
	
	var t_am = '<div id="t_am" class="t_in png"></div>';
	var t_pm = '<div id="t_pm" class="t_in png"></div>';
	var t_sep = '<div id="t_dot" class="t_in png"></div>';
	var t_blank = '<div id="t_blank" class="t_in"></div>';
	var t_blank_2 = '<div id="t_blank_2" class="t_in"></div>';
	var imgdir = '<div id="t_';
	var imgsuffix = '" class="t_in png"></div>';
	
	if (t_hour >= 12) {
		if (t_hour != 12)
			t_hour = t_hour - 12;
		t_hour = t_hour + "";
		if (t_hour >= 6)
			$(".w2-view-night").css({display:"block"});
		if (t_hour.length == 2) {
			t_hour = t_blank_2 + imgdir + t_hour.charAt(0) + imgsuffix + imgdir + t_hour.charAt(1) + imgsuffix;
		} else {
			t_hour = t_blank + imgdir + t_hour.charAt(0) + imgsuffix;	
		}
		t_type = t_pm;
	} else {
		$(".w2-view-night").css({display:"none"});
		if (t_hour == 0) {
			t_hour = t_blank_2 + imgdir + 1 + imgsuffix + imgdir + 2 + imgsuffix;
		} else if (t_hour == 10 || t_hour == 11) {
			t_hour = t_hour + "";
			t_hour = t_blank_2 + imgdir + t_hour.charAt(0) + imgsuffix + imgdir + t_hour.charAt(1) + imgsuffix;		
		} else {
			t_hour = t_hour + "";
			t_hour = t_blank + imgdir + t_hour.charAt(0) + imgsuffix;	
		}
		t_type = t_am;
	}

	if (t_min < 10) {
		t_min = t_min + "";
		t_min = imgdir + 0 + imgsuffix + imgdir + t_min.charAt(0) + imgsuffix;
	} else {
		t_min = t_min + "";
		t_min = imgdir + t_min.charAt(0) + imgsuffix + imgdir + t_min.charAt(1) + imgsuffix;
	}	
	
	t_full = '<div id="t_box">' + t_hour + t_sep + t_min + t_type + '</div>';
	return t_full;
}

function playAboutUs() {
	/*setInterval(function() {
		$(".fl")
		.animate({opacity: "0.2"},2000)
		.animate({opacity: "1"},2000);
	}, 1000); */
	
	$("#p-txt-1").text("");
	$("#p-txt-2").text("");
	$("#p-txt-3").text("");
	$("#p-txt-4").text("");
	$("#p-txt-5").text("");
	$("#p-txt-6").text("");
	
	$("#p-txt-1").css({opacity: 0})
	.animate({opacity: 1}, 4000);
	var slide1 = setTimeout(function() {
		$("#p-txt-1").animate({opacity: 0}, 2000);
	}, 8000); 
	var slide2 = setTimeout(function() {
		$("#p-txt-2").css({display: "block", opacity: 0})
		.animate({opacity: 1, width: "690px"}, 2000)
	}, 10000); 
	var slide3 = setTimeout(function() {
		$("#p-txt-2").animate({opacity: 1, width: "0px"}, 2000)
	}, 22000); 
	var slide4 = setTimeout(function() {
		$("#p-txt-3").css({display: "block", opacity: 0})
		.animate({opacity: 1, width: "690px"}, 2000)
	}, 24000); 
	var slide5 = setTimeout(function() {
		$("#p-txt-3").animate({opacity: 1, width: "0px"}, 2000)
	}, 36000); 
	var slide6 = setTimeout(function() {
		$("#p-txt-4").css({display: "block", opacity: 0})
		.animate({opacity: 1, width: "690px"}, 2000)
	}, 38000); 
	var slide7 = setTimeout(function() {
		$("#p-txt-4").animate({opacity: 1, width: "0px"}, 2000)
	}, 50000); 
	var slide8 = setTimeout(function() {
		$("#p-txt-5").css({display: "block", opacity: 0})
		.animate({opacity: 1, width: "690px"}, 2000)
	}, 52000); 
	var slide9 = setTimeout(function() {
		$("#p-txt-5").animate({opacity: 1, width: "0px"}, 2000)
	}, 64000);	
	var slide10 = setTimeout(function() {
		$("#p-txt-6").css({display: "block", opacity: 0})
		.animate({opacity: 1}, 1000);
	}, 68000); 
	var slide11 = setTimeout(function() {
		$("#p-txt-6").animate({opacity: 0}, 2000);
	}, 72000);	
	var slide12 = setTimeout(function() {
		playAboutUs();
	}, 76000);	
}

function mycarousel_itemLoadCallback(carousel, state)
{
    if (state != 'init')
        return;
        
    $.getJSON('json-web.js', function(data) {
        mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data, "web");
    });        
};

function mycarousel_itemLoadCallback2(carousel, state)
{
    if (state != 'init')
        return;
    
    $.getJSON('json-graphix.js', function(data) {
        mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data, "graphics");
    });    
};

function mycarousel_itemAddCallback(carousel, first, last, data, stype)
{
    $.each(data.items, function(i,item) {
        carousel.add(i+1, '<a href="#" id="' + stype + (i+1) + '" onclick="revealBigContent(this, \'' + item.media.l + '\', \'' + (item.title.l).replace(/'/g,'%27') + '\', \'' + (item.description).replace(/'/g,'%27') + '\', \'' + item.technology + '\', \'' + item.url + '\',\'' + (stype + (i+1)) + '\');return false;" onmouseover="revealBubble(this);return false;" onmouseout="hideBubble(this);return false;"><div style="background: transparent top center no-repeat url(\'' + item.media.s + '\');" class="img-box png"></div><div class="poptitle"><div class="bubble-top"></div><div class="poptitle-inner">' + item.title.s + '</div><div class="bubble-btm"></div></div></a>');
    });

    carousel.size(data.items.length);
};

function revealBubble(elem) {
	$(elem).children(".poptitle")
	.stop(true)
	.css({display: "block", left: "6px", opacity: 1, top: "0px"})
	//.animate({opacity: 1}, 1000);
}

function hideBubble(elem) {
	$(elem).children(".poptitle")
	.stop(true)
	.animate({top: "-100px"}, 1000);
}

function changeImage(elem) {
	$(elem).attr({src: "images/tres/showcase/launch2.gif"})
	.effect("bounce", {easing: "linear", times: 3});
}

function returnImage(elem) {
	$(elem).attr({src: "images/tres/showcase/launch.gif"});
}

function revealBigContent(elem, screenurl, client, desc, technology, url, id) {
	if (!$("#stv-content #" + id).hasClass("curritem")) {
		var largeThumb = screenurl;
		var largeInfo = client;
		var largeDesc = desc;
		var largeTechnology = technology;
		var largeURL = url;
		if (largeURL != "")
			largeURL = '<p><a href="' + url + '" rel="nofollow" target="_blank"><img src="images/tres/showcase/launch.gif" onmouseover="changeImage(this);return false;" onmouseout="returnImage(this); return false;" /></a></p>';
		else
			largeURL = '<p>Website Yapim Asamasinda.</p>';

		$("#tv2-welcome").animate({opacity: 0}, 1000)
		setTimeout(function() {	
			$("#tv2-welcome").css({display: "none"});
		}, 1000);

		$("#tv2-screen-content-inner")
		.stop(true)
		.animate({opacity: 0.2}, 1000)
		.animate({marginLeft: "-1000px"}, {duration: 1000, easing: "easeOutQuart"})
		.animate({opacity: 0})
		.animate({marginLeft: "2000px"});

		setTimeout(function() {	
			$("#tv2-loader")
			.stop(true)
			.css({display: "block", opacity: 0})
			.animate({opacity: 1}, 2000);
		}, 1000);

		setTimeout(function() {	
			$("#tv2-screen-content-inner")
			.stop(true)
			.animate({marginLeft: "0px", opacity: 1}, {duration: 5000, easing: "easeInOutCirc"})
			.html(
			'<div class="sc-screen"><img src="' + largeThumb + '" /></div>' + 
			'<div class="sc-info">' +
			'<h2>Adi: ' + largeInfo.replace("%27","'") + '</h2>' +
			'<p><b>Site Hakkinda</b></p>' + 
			'<p>' + largeDesc.replace("%27","'") + '</p>' +
			'<p><b>Siteyi Nasil Yaptik??</b></p>' + 
			'<p>' + largeTechnology.replace("%27","'") + '</p>' +
			largeURL +		
			'</div>'
			)
		}, 2000);

		setTimeout(function() {	
			$("#tv2-loader")
			.stop(true)
			.animate({opacity: 0}, 1000);
		}, 4000);
		
		// Make this current item clicked
		$("#stv-content #" + id).addClass("curritem");
		$("#stv-content li a").not("#" + id).removeClass("curritem");
	}
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};

(function ($) {
	$.fn.bubble = function (options) {
		var defaults = {
			'trigger' : '.trigger',
			'popup' : '.popup',
			'distance' : 10,
			'hideDelay' : 500,
			'effectTime' : 250
		};
		
		var settings = $.extend({}, defaults, options);
		
		return this.each(function () {
			var hideDelayTimer = null;

			var trigger = $(settings.trigger, this);
			var popup = $(settings.popup, this);

			$([trigger.get(0), popup.get(0)]).mouseover(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);

				if (popup.is(':animated, :visible')) {
					return;
				} else {
					popup.css({
						display: 'block',
						top: 0,
						left: 20
					}).animate({
						opacity: 1,
						top: '-=' + settings.distance + 'px'
					}, settings.effectTime);				
				}
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);

				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					popup.animate({
						top: '-=' + settings.distance + 'px',
						opacity: 0
					}, settings.effectTime, 'swing', function () {
						popup.css('display', 'none');
					});		
				}, settings.hideDelay);
			});
		});
	}
})(jQuery);



