	
	var is_ie6 = false;
	var is_ie7 = false;
	var is_ie8 = false;
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0"){is_ie6 = true;}
		if(i=="msie" && jQuery.browser.version.substr(0,3)=="7.0"){is_ie7 = true;}
		if(i=="msie" && jQuery.browser.version.substr(0,3)=="8.0"){is_ie8 = true;}
	});
	
	var body_size = 0;
	var scrolling = false;
	var stop_scrolling = true;
	var speed = 5;
	var panel_visible = true;
	var panel_hovered = false;
	
	
	$(document).ready(function(){
		if ($.browser.msie) {
			$('div.menu a').hover(function(){
				$(this).css({'border-bottom':'1px solid #dadada'});
			}, function(){
				$(this).css({'border-bottom':'none'});
			});
		}
		$('div.footer2 div.form div.submit').hover(function(){
			$(this).find('input').css({'margin-top':'-40px'});
		}, function(){
			$(this).find('input').css({'margin-top':'0px'});
		});
	});
	
	
	// Add External Links
	$(document).ready(function(){
		$('a[rel="external"]').each(function(){
			$(this).attr('target', '_blank');
		});
	});
	
	
	// Body min-height
	function bodyHeight(){
		if (body_size == 0) {
			body_size = $('div.body').height();
		}
		window_height = $(window).height();
		document_height = $(document).height();
		if ($.browser.msie) { document_height = document_height - 4; }
		$('div.body').css({'display':'none'});
		header_height = $('div.header').height();
		footer_height = $('div.footer').height();
		body_height = document_height - (header_height + footer_height);
		if (body_height <= body_size) {
			$('div.body').css({'height':body_size});
		} else {
			if (window_height >= document_height) {
				$('div.body').css({'height':body_height});
			} else {
				$('div.body').css({'height':'auto'});
			}
		}
		$('div.body').css({'display':'block'});
	}
	$(document).ready(function(){
		if (is_ie6) { $('div.body').css({'display':'none'}); }
		bodyHeight();
	});
	
	
	// Window Resize
	$(window).resize(function(){
		$('div.body').css({'display':'none'});
		bodyHeight();
		worksSize();
		worksFixed();
	});
	
	
	// Cufon
	$(document).ready(function(){
		Cufon.replace('div.menu a', { fontFamily: 'MyRiad-Regular' });
		Cufon.replace('div.quote a', { fontFamily: 'MyRiad-Regular' });
		Cufon.replace('div.footer div.client-login span', { fontFamily: 'MyRiad-Bold' });
		Cufon.replace('div.footer2 div.form h1', { fontFamily: 'MyRiad-Regular' });
		Cufon.replace('div.directions ul li', { fontFamily: 'MyRiad-Bold' });
		Cufon.replace('div.services ul li h1', { fontFamily: 'MyRiad-Bold' });
		Cufon.replace('div.services-descr div.icons ul li h1', { fontFamily: 'MyRiad-Bold' });
		Cufon.replace('table.submenu h2', { fontFamily: 'MyRiad-Regular' });
	});
	
	
	// Auto hide/show label on text field
	$(document).ready(function() {
		$('.autolabel').focus(function () {
			if ($(this).attr('defaultValue') && $(this).attr('defaultValue') == $(this).val()) {
				$(this).val('')
			}
		});
		$('.autolabel').blur(function () {
			if ($(this).attr('defaultValue') && $(this).val() == '') {
				$(this).val($(this).attr('defaultValue'));
			}
		});
	});
	
	
	// Submenu Hover
	$(document).ready(function(){
		$('table.submenu h2 a').hover(function(){
			$(this).parent().parent().parent().addClass('hovered');
		}, function(){
			$(this).parent().parent().parent().removeClass('hovered');
		});
		$('table.submenu tr td.first a').hover(function(){
			$(this).parent().parent().addClass('hovered');
		}, function(){
			$(this).parent().parent().removeClass('hovered');
		});
	});
	
	
	// Works
	function worksSize(){
		$('div.works').css({'display':'block'});
		$('div.size').css({'width':'100%'});
		ul_width = $('ul.works').width();
		screen_width = $('div.size').width();
		if (ul_width < screen_width) {
			$('div.size').css({'width':ul_width});
			$('ul.works').css({'left':'0px'});
		} else {
			$('div.size').css({'width':'100%'});
			max_margin = (($('ul.works').width() - $('div.size').width()) - 18) / -1;
			ul_margin = parseFloat($('ul.works').css('left'));
			if (ul_margin <= max_margin) {
				$('ul.works').css({'left':max_margin});
			}
		}
	}
	function worksFixed(){
		window_height = $(window).height();
		bottom_line = window_height - 100;
		if (window_height < 900) {
			$('div.works').css({'position':'fixed'});
			$('div.works').animate({marginBottom: 0}, 2000, function(){
				if (!panel_hovered) {
					$('div.works').animate({height: 0}, 1000);
					panel_visible = false;
				}
			});
			$(document).mousemove(function(e){
				if (!panel_visible) {
					posY = e.pageY - $(window).scrollTop();
					if (posY >= bottom_line) {
						scrolling = true;
						$('div.works').stop().animate({height: 213}, 300, function(){
							scrolling = false;
						});
						panel_visible = true;
					}
				} else {
					if (!panel_visible) {
						$('div.works').stop().animate({height: 0}, 300);
						panel_visible = false;
						panel_hovered = false;
					}
				}
			});
			$('div.works').mouseleave(function(){
				if ($('div.works').css('position') == 'fixed') {
					$('div.works').stop().animate({height: 0}, 300);
					panel_visible = false;
					panel_hovered = false;
				}
			});
			$('div.works').mouseenter(function(){
				panel_hovered = true;
			});
		} else {
			panel_visible = true;
			scrolling = false;
			$('div.works').css({'position':'absolute', 'height':'213px'});
		}
	}
	$(document).ready(function(){
		worksSize();
		worksFixed();
	});
	
	
	// Arrows
	$(document).ready(function(){
		$('div.portfolio span.prev').hover(function(){
			$(this).css({'background-position':'0 100%'});
		}, function(){
			$(this).css({'background-position':'0 0'});
		});
		$('div.portfolio span.next').hover(function(){
			$(this).css({'background-position':'0 100%'});
		}, function(){
			$(this).css({'background-position':'0 0'});
		});
	});
	
	
	// Contacts Form Labels
	$(document).ready(function(){
		if ($.browser.webkit || $.browser.mozilla) {
			$('div.form div.field label').css({'left':'10px'});
		}
		$('div.form div.field input').each(function(){
			if ($(this).attr('value') != '') {
				$(this).parent().find('label').css({'display':'none'});
			}
		});
		$('div.form div.field textarea').each(function(){
			if ($(this).attr('value') != '') {
				$(this).parent().find('label').css({'display':'none'});
			}
		});
		$('div.form div.field label').click(function(){
			$(this).css({'display':'none'});
			$(this).parent().find('textarea').focus();
			$(this).parent().find('input').focus();
		});
		$('div.form div.field input').focus(function(){
			$(this).parent().find('label').css({'display':'none'});
			$(this).css({'color':'#fff'});
		});
		$('div.form div.field textarea').focus(function(){
			$(this).parent().find('label').css({'display':'none'});
			$(this).css({'color':'#fff'});
		});
		$('div.form div.field input').blur(function(){
			if ($(this).attr('value') == '') {
				$(this).parent().find('label').css({'display':'inline'});
				if ($(this).parent().hasClass('mail')) {
					if (($(this).parent().find('label').html() != 'Your Email - <em>please complete this mandatory field</em>') && ($(this).parent().find('label').html() != 'Your Email - <EM>please complete this mandatory field</EM>')) {
						$(this).parent().find('label').html('Your Email <em>*</em>');
					}
				}
			} else {
				$(this).parent().find('label').css({'display':'none'});
			}
		});
		$('div.form div.field textarea').blur(function(){
			if ($(this).attr('value') == '') {
				$(this).parent().find('label').css({'display':'inline'});
			} else {
				$(this).parent().find('label').css({'display':'none'});
			}
		});
	});
	
	
	// Contacts Form Validation
	$(document).ready(function(){
		$('div.footer2').find('form').submit(function(){
			valid = true;
			error_msg = '- <em>please complete this mandatory field</em>';
			error_mail = '- <em>invalid email address</em>';
			$('div.form div.field input').each(function(){
				if ($(this).attr('value') == '') {
					label = $(this).parent().find('label').html();
					if ($.browser.msie) {
						label2 = label.replace('<EM>*</EM>',error_msg);
					} else {
						label2 = label.replace('<em>*</em>',error_msg);
					}
					$(this).parent().find('label').html(label2);
					valid = false;
				}
			});
			$('div.form div.field textarea').each(function(){
				if ($(this).attr('value') == '') {
					label = $(this).parent().find('label').html();
					if ($.browser.msie) {
						label2 = label.replace('<EM>*</EM>',error_msg);
					} else {
						label2 = label.replace('<em>*</em>',error_msg);
					}
					$(this).parent().find('label').html(label2);
					valid = false;
				}
			});
			$('div.form div.field input').blur();
			$('div.form div.field textarea').blur();
			if ($('div.form div.mail input').attr('value') != '') {
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				var mail = $('div.form div.mail input').attr('value');
				if (reg.test(mail) == false) {
					label = $('div.form div.mail input').attr('value') + ' ' + error_mail;
					$('div.form div.mail label').html(label);
					$('div.form div.mail label').css({'display':'inline'});
					$('div.form div.mail input').css({'color':'#141414'});
					valid = false;
				}
			} else {
				label = $('div.form div.mail label').html();
				if ($.browser.msie) {
					label2 = label.replace('<EM>*</EM>',error_msg);
				} else {
					label2 = label.replace('<em>*</em>',error_msg);
				}
				$('div.form div.mail label').html(label2);
			}
			if (valid) {
				scroll_top = $(window).scrollTop();
				$.cookie('loco_scroll_top', scroll_top);
			}
			return valid;
		});
	});
	
	
	// Contacts Form Success Message
	$(document).ready(function(){
		var success_msg = "Thanks, we’ll reply shortly";
		if ($('div.footer2').length > 0) {
			scroll_top = $.cookie('loco_scroll_top');
			if (scroll_top) {
				$(window).scrollTop(scroll_top);
				$('div.footer2 div.form h1').html(success_msg);
				$('div.footer2 div.form h1').addClass('success');
			}
			$.cookie('loco_scroll_top', null);
		} else {
			$.cookie('loco_scroll_top', null);
		}
	});
	
	
	// Works Scroller
	function addWorksScroller(){
		var works_size = $('div.works div.size div.scroller div');
		var works_ul = $('div.works div.size ul.works');
		works_size_width = works_size.width();
		works_ul_width = works_ul.width();
		
		function MouseMove2(e) {
			if (!scrolling) {
				var mouseCoordsX = (e.pageX - works_size.offset().left);
				var mousePercentX = mouseCoordsX / works_size_width;
				var destX = -(((works_ul_width - (works_size_width)) - works_size_width) * (mousePercentX));
				var thePosC = parseFloat(mouseCoordsX - destX);
				var thePosD = parseFloat(destX - mouseCoordsX);
				var animSpeed = 500; //ease amount
				var easeType = "easeOutCirc";
				if (mouseCoordsX > destX) {
					$('div.works div.size ul.works').stop().animate({left: -thePosC}, animSpeed, easeType); //with easing
				} else if (mouseCoordsX < destX) {
					$('div.works div.size ul.works').stop().animate({left: thePosD}, animSpeed, easeType); //with easing
				}
			}
		}

		$('div.works div.size').bind('mousemove', function (e){
			MouseMove2(e);
		});
	}
	$(window).load(function(){
		addWorksScroller();
	});
	
	
	// Monitor Scroller
	function addMonitorScroller(){
		var monitor = $('div.monitor div.overflow');
		var monitor_img = $('div.monitor div.overflow div.img-holder');
		monitorHeight = monitor.height();
		imgHeight = monitor_img.height();
		
		function MouseMove(e) {
			var mouseCoordsY = (e.pageY - monitor.offset().top);
			var mousePercentY = mouseCoordsY / monitorHeight;
			var destY = -(((imgHeight - (monitorHeight)) - monitorHeight) * (mousePercentY));
			var thePosC = parseFloat(mouseCoordsY - destY);
			var thePosD = parseFloat(destY - mouseCoordsY);
			var animSpeed = 500; //ease amount
			var easeType = "easeOutCirc";
			if (mouseCoordsY > destY) {
				$('div.monitor div.overflow div.img-holder').stop().animate({top: -thePosC}, animSpeed, easeType); //with easing
			} else if (mouseCoordsY < destY) {
				$('div.monitor div.overflow div.img-holder').stop().animate({top: thePosD}, animSpeed, easeType); //with easing
			}
		}

		$('div.monitor div.scroller').bind('mousemove', function (e){
			MouseMove(e);
		});
	}
	$(window).load(function(){
		addMonitorScroller();
	});
	
	
	
	// Portfolio AJAX
	$(document).ready(function(){
		var switching = false;
	
		// Thumbnails Click
		$("li.thumb_work").click( function(){
			if (!switching) {
				switching = true;
				$('div.monitor div.scroller').unbind('mousemove');
				$('div.portfolio').prepend('<span class="loading"><span></span></span>');
				
				var act = $(this).attr('lang');
				$.ajax({
					type: 'POST',
					dataType: 'html',
					url: '/ajax.php',
					data: {
						func: 'switchWork',
						act: act
					},
					success: function(data){
						if (data!=0) {
							var res = data.split('|');
							curr_work = '';
							next_work = '';
							if (res[2] == 0) {
								next_work = 'img';
							} else if (res[2] == 1) {
								next_work = 'monitor';
							}
							if ($('div.portfolio').find('div.images').length > 0) {
								curr_work = 'img';
							}
							if ($('div.portfolio').find('div.monitor').length > 0) {
								curr_work = 'monitor';
							}
							if (res[2] == 0) {
								// img
								$("#container_of_the_main_block").animate({marginLeft: -200, opacity: 0}, 500, function(){
									$("#container_of_the_main_block").html('<div class="images"><table cellspacing="0" class="images"><tr><td><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></td></tr></table></div>');
									$("span.next").attr('lang',res[1]);
									$("span.prev").attr('lang',res[1]);
									$("#container_of_the_main_block").css({'margin-left':'200px'});
									$("#container_of_the_main_block").animate({marginLeft: 0, opacity: 1}, 500);
									$('div.portfolio span.loading').fadeOut(250, function(){
										$(this).remove();
										switching = false;
									});
								});
							} else
							if (res[2] == 1) {
								// monitor
								$("#container_of_the_main_block").animate({marginLeft: -200, opacity: 0}, 500, function(){
									$("#container_of_the_main_block").html('<div class="monitor"><div class="glow"></div><div class="scroller"></div><div class="overflow"><div class="img-holder"><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></div></div></div>');
									$("span.next").attr('lang',res[1]);
									$("span.prev").attr('lang',res[1]);
									$('div.monitor div.overflow div.img-holder').css({'top':'0px'});
									$('div.portfolio span.loading').fadeOut(250, function(){
										$(this).remove();
										$("#container_of_the_main_block").css({'margin-left':'200px'});
										$("#container_of_the_main_block").animate({marginLeft: 0, opacity: 1}, 500, function(){
											addMonitorScroller();
											switching = false;
										});
									});
								});
							}
						}
					}
				});
			}
		});
		
		// Next Click
		$("span.next").click( function(){
			if (!switching) {
				switching = true;
				$('div.monitor div.scroller').unbind('mousemove');
				$('div.portfolio').prepend('<span class="loading"><span></span></span>');

				var act = $(this).attr('lang');
				$.ajax({
					type: 'POST',
					dataType: 'html',
					url: '/ajax.php',
					data: {
						func: 'updateScreenShot',
						act: act,
						direction: 'next'
					},
					success: function(data){
						if (data!=0) {
							var res = data.split('|');
							var curr_project = $("span.next").attr('lang').split('_');
							var new_project = res[1].split('_');
							curr_work = '';
							next_work = '';
							if (res[2] == 0) {
								next_work = 'img';
							} else if (res[2] == 1) {
								next_work = 'monitor';
							}
							if ($('div.portfolio').find('div.images').length > 0) {
								curr_work = 'img';
							}
							if ($('div.portfolio').find('div.monitor').length > 0) {
								curr_work = 'monitor';
							}
							if (res[2] == 0) {
								// img
								if ((curr_work == next_work) && (curr_project[1] == new_project[1])) {
									$("#container_of_the_main_block").fadeTo(500, 0, function(){
										$("#container_of_the_main_block").html('<div class="images"><table cellspacing="0" class="images"><tr><td><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></td></tr></table></div>');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$("#container_of_the_main_block").fadeTo(500, 1);
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											switching = false;
										});
									});
								} else {
									$("#container_of_the_main_block").animate({marginLeft: -200, opacity: 0}, 500, function(){
										$("#container_of_the_main_block").html('<div class="images"><table cellspacing="0" class="images"><tr><td><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></td></tr></table></div>');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$("#container_of_the_main_block").css({'margin-left':'200px'});
										$("#container_of_the_main_block").animate({marginLeft: 0, opacity: 1}, 500);
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											switching = false;
										});
									});
								}
							} else
							if (res[2] == 1) {
								// monitor
								if ((curr_work == next_work) && (curr_project[1] == new_project[1])) {
									$('div.monitor div.img-holder').fadeTo(500, 0, function(){
										$('div.monitor div.overflow div.img-holder').html('<img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" />');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$('div.monitor div.overflow div.img-holder').css({'top':'0px'});
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											$('div.monitor div.overflow div.img-holder').fadeTo(500, 1, function(){
												addMonitorScroller();
												switching = false;
											});
										});
									});
								} else {
									$("#container_of_the_main_block").animate({marginLeft: -200, opacity: 0}, 500, function(){
										$("#container_of_the_main_block").html('<div class="monitor"><div class="glow"></div><div class="scroller"></div><div class="overflow"><div class="img-holder"><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></div></div></div>');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$('div.monitor div.overflow div.img-holder').css({'top':'0px'});
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											$("#container_of_the_main_block").css({'margin-left':'200px'});
											$("#container_of_the_main_block").animate({marginLeft: 0, opacity: 1}, 500, function(){
												addMonitorScroller();
												switching = false;
											});
										});
									});
								}
							}
						}
					}
				});
			}
		});

		// Prev Click
		$("span.prev").click( function(){
			if (!switching) {
				switching = true;
				$('div.monitor div.scroller').unbind('mousemove');
				$('div.portfolio').prepend('<span class="loading"><span></span></span>');

				var act = $(this).attr('lang');
				$.ajax({
					type: 'POST',
					dataType: 'html',
					url: '/ajax.php',
					data: {
						func: 'updateScreenShot',
						act: act,
						direction: 'prev'
					},
					success: function(data){
						if (data!=0) {
							var res = data.split('|');
							var curr_project = $("span.prev").attr('lang').split('_');
							var new_project = res[1].split('_');
							curr_work = '';
							next_work = '';
							if (res[2] == 0) {
								next_work = 'img';
							} else if (res[2] == 1) {
								next_work = 'monitor';
							}
							if ($('div.portfolio').find('div.images').length > 0) {
								curr_work = 'img';
							}
							if ($('div.portfolio').find('div.monitor').length > 0) {
								curr_work = 'monitor';
							}
							if (res[2] == 0) {
								// img
								if ((curr_work == next_work) && (curr_project[1] == new_project[1])) {
									$("#container_of_the_main_block").fadeTo(500, 0, function(){
										$("#container_of_the_main_block").html('<div class="images"><table cellspacing="0" class="images"><tr><td><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></td></tr></table></div>');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$("#container_of_the_main_block").fadeTo(500, 1);
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											switching = false;
										});
									});
								} else {
									$("#container_of_the_main_block").animate({marginLeft: 200, opacity: 0}, 500, function(){
										$("#container_of_the_main_block").html('<div class="images"><table cellspacing="0" class="images"><tr><td><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></td></tr></table></div>');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$("#container_of_the_main_block").css({'margin-left':'-200px'});
										$("#container_of_the_main_block").animate({marginLeft: 0, opacity: 1}, 500);
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											switching = false;
										});
									});
								}
							} else
							if (res[2] == 1) {
								// monitor
								if ((curr_work == next_work) && (curr_project[1] == new_project[1])) {
									$('div.monitor div.img-holder').fadeTo(500, 0, function(){
										$('div.monitor div.overflow div.img-holder').html('<img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" />');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$('div.monitor div.overflow div.img-holder').css({'top':'0px'});
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											$('div.monitor div.overflow div.img-holder').fadeTo(500, 1, function(){
												addMonitorScroller();
												switching = false;
											});
										});
									});
								} else {
									$("#container_of_the_main_block").animate({marginLeft: 200, opacity: 0}, 500, function(){
										$("#container_of_the_main_block").html('<div class="monitor"><div class="glow"></div><div class="scroller"></div><div class="overflow"><div class="img-holder"><img id="img_preview" src="'+res[0]+'" width="'+res[3]+'" height="'+res[4]+'" alt="" /></div></div></div>');
										$("span.next").attr('lang',res[1]);
										$("span.prev").attr('lang',res[1]);
										$('div.monitor div.overflow div.img-holder').css({'top':'0px'});
										$('div.portfolio span.loading').fadeOut(250, function(){
											$(this).remove();
											$("#container_of_the_main_block").css({'margin-left':'-200px'});
											$("#container_of_the_main_block").animate({marginLeft: 0, opacity: 1}, 500, function(){
												addMonitorScroller();
												switching = false;
											});
										});
									});
								}
							}
						}
					}
				});
			}
		});
		
	});
