	//initialize vars
	
	lenseDisabled = false;
	resizeOk = true;
	curPage = 3;
	stopHashUpdate = false;
	cachedImagesArray = new Array();
	
	//====================
	function resize()
	//====================
	{

		var pageWidth = $(document).width();
		var pageHeight = $(document).height();
	
		var viewportWidth = $(window).width();
		var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
		
		mapWidth = $('#map').width();
		mapPosition = ((mapWidth - viewportWidth)/2);
		headerPos = (((viewportWidth - 880)/2)+4);
		centeringPos = (((viewportWidth - 860)/2));
		floatingMenuPos = (((viewportWidth - 860)/2)-50);
	
		//set default positioning
		$('#map-cont').attr('style', 'width:' + viewportWidth + '; height:' + viewportHeight +  ';');	
		$('#map').attr('style', 'top: 70px; left: -' + mapPosition + 'px;');
		$('#mast_head').attr('style', 'position: fixed; margin: 0px; top: 0px; left: ' + headerPos + 'px;');
		
		$('#text').html("<p>Page Width: "+ pageWidth + " Page Height: " + pageHeight + '</p><p>Viewport Width: ' +  viewportWidth + ' Viewport Height :' + viewportHeight + '</p>');


		$('#centering').attr('style', 'background: #000723; width: 860px; height: 520px; display: none; z-index: 2000; position: absolute; top: 80px; left: ' + centeringPos + 'px;');
		$('#floatingmenu').attr('style', 'z-index: 1000; top: 80px; right: ' + floatingMenuPos + 'px;');

	
	}



	//====================
	function portfolioZoomInternal(pl)
	//====================
	{

		$('#our_work ul').css('display', 'none');
		$('#close').css('display', 'none');
		
		$('#centering_loading').fadeIn('fast', function(){


			work = $(pl).attr('rel');
			sect = $(pl).closest('ul').attr('title');
			year = $(pl).closest('li').attr('title');
			url  = $(pl).attr('href');
			serv = $(pl).closest('li').attr('rel');
			titlee = $(pl).attr('title');
			ts = '?' + Math.round(new Date().getTime() / 1000);
			
			$('#screenshot').html('<img src="/images/cards/portfolio/screenshots/' + sect + '/' + work + '/' + work + '.png' + ts + '" alt="" />');
			
			for(i = 1; i < 4; i++)
			{
				$('#box' + i).html('<img src="/images/cards/portfolio/screenshots/' + sect + '/' + work + '/' + work + '_' + i + '.jpg" alt="" />');
			}
	
			$('#section').html('<img src="/images/cards/portfolio/screenshots/' + sect +  '/section.png" alt="" />');
			$('#work_title').html('<img src="/images/cards/portfolio/screenshots/' + sect +  '/' + work + '/title.png" alt="" />');
			$('#section_long').html('<img src="/images/cards/portfolio/screenshots/' + sect +  '/section_long.png" alt="" />');
			$('#work_year').html('<img src="/images/cards/portfolio/screenshots/' + year + '.png" alt="" />');
			if (serv != '');
			{
				bits = serv.split(',');
				bitsStr = '';
				
				  for(i = 0; i < bits.length; i++) {
						num = bits[i];
						bitsStr += '<li>' + services[num] + '</li>';
	
				  }
	  
				$('#what_we_did ul').html(bitsStr);
				
			}
			
			window.location.hash = '/' + url;
			updateMeta(0, titlee);
		

			cachedImg = $('#screenshot img').attr('src');
			if (cachedImg in cachedImagesArray)
			{
				resizePortfolio();
				$('#centering_loading').fadeOut('slow', function(){
																 
					$('#close').css('display', 'block');
					stopHashUpdate = false;
																 
				});
			}
			else
			{
				$('#screenshot img').load(function(){
					
					resizePortfolio();
					$('#centering_loading').fadeOut('slow', function(){
																	 
						$('#close').css('display', 'block');
						stopHashUpdate = false;
						cachedImagesArray[cachedImg] = '';
																	 
					});
				})
			}
			
			
			
			
			
			

/*			$('#screenshot img').load(function(){
				$('#centering_loading').fadeOut('slow', function(){
																 
					$('#close').css('display', 'block');												 
																 
				});
			})*/


			
														 
		});
		
		
	}

	//====================
	function portfolioZoom(el)
	//====================
	{
		zoomDuration = 500;
		coeff = ((($(window).width() - 860)/2));
		topp = '-=80';
		leftt = '-=' + coeff;
		
		if(typeof(el) != 'object') { 
		
			$('#portfolio_intro li a').each(function(){
				if ($(this).attr('href') == el)
				{
					el = $(this);
					zoomDuration = 500;
					topp = '0px';
					leftt = '0px';					
					$('#upper-curtain').css('diplay', 'none');
					$('#lower-curtain').css('diplay', 'none');
					//$('#centering_loading').css('background', 'none');
				}
			});		
		
		}

		if(typeof(el) != 'object') { 

			$('.our_work_subsub a').each(function(){
				if ($(this).attr('href') == el)  //user is coming from a bookmark or direct type in such as http://wm.com.localhost/#/info/portfolio/web/pianetah except for the 3 sites in the porftolio introduction card
				{
					el = $(this);

					$('#centering').animate({
						width: '100%',
						height: '100%',
						opacity: '1',
						top: '0px',
						left: '0px'
						
					  }, zoomDuration, function() {});
		
					portfolioZoomInternal(el);
				}
			});		
			
			return;
		}
		
		if(typeof(el) != 'object') { 
			return;
		}


		work = $(el).attr('rel');
//		sect = $(el).closest('ul').attr('title');
		sect = $(el).closest('li').attr('class');
		year = $(el).closest('li').attr('title');
		url  = $(el).closest('li').attr('rel');
		serv = $(el).closest('li').children('span').attr('rel');
		titlee = $(el).attr('title');
		ts = '?' + Math.round(new Date().getTime() / 1000);
		
		$('#centering_loading').css('display', 'block');
		
		$('#screenshot').html('<img src="/images/cards/portfolio/screenshots/' + sect + '/' + work + '/' + work + '.png' + ts + '" alt="" />');
		
		for(i = 1; i < 4; i++)
		{
			$('#box' + i).html('<img src="/images/cards/portfolio/screenshots/' + sect + '/' + work + '/' + work + '_' + i + '.jpg" alt="" />');
		}

		$('#section').html('<img src="/images/cards/portfolio/screenshots/' + sect +  '/section.png" alt="" />');
		$('#work_title').html('<img src="/images/cards/portfolio/screenshots/' + sect +  '/' + work + '/title.png" alt="" />');
		$('#section_long').html('<img src="/images/cards/portfolio/screenshots/' + sect +  '/section_long.png" alt="" />');
		$('#work_year').html('<img src="/images/cards/portfolio/screenshots/' + year + '.png" alt="" />');
		if (serv != '');
		{
			bits = serv.split(',');
			bitsStr = '';
			
			  for(i = 0; i < bits.length; i++) {
						num = bits[i];
						bitsStr += '<li>' + services[num] + '</li>';

  			  }
  
			$('#what_we_did ul').html(bitsStr);
			
		}
		
		window.location.hash = '/' + url;
		updateMeta(0, titlee);
		stopHashUpdate = true;

		$('#centering').animate({
			width: '100%',
			height: '100%',
			opacity: '1',
			top: topp,
			left: leftt
			
		  }, zoomDuration, function() {



			cachedImg = $('#screenshot img').attr('src');
			if (cachedImg in cachedImagesArray)
			{
				resizePortfolio();
				
				$('#centering_loading').fadeOut('slow', function(){
																 
					$('#close').css('display', 'block');
					stopHashUpdate = false;
																 
				});
			}
			else
			{
				$('#screenshot img').load(function(){
	
					resizePortfolio();
					$('#centering_loading').fadeOut('slow', function(){
																	 
						$('#close').css('display', 'block');
						stopHashUpdate = false;
						cachedImagesArray[cachedImg] = '';
																	 
					});
				})
			}
			
		  });
			
			
}				
				
function resizePortfolio() {

/*	//var xw = $(window).width();
	//var xh = $(window).height();
	
	var xw = screen.width;
	var xh = screen.height;

	if(xh < 960)
	{
		var w = $('#screenshot img').width();
		var h = $('#screenshot img').height();
	
		var s = Math.min(xw/w, xh/h);
		var nw = Math.floor(s*w);
		var nh = Math.floor(s*h);
		$('#screenshot img').css('height',nh).css('width',nw);
	}*/

	var xw = screen.width;
	var xh = screen.height;

	if(xh < 960)
	{	
		$('body').addClass('resized');
		mult1 = 0.75;
		mult2 = 0.80;
		
		var w = $('#screenshot img').width();
		var h = $('#screenshot img').height();
	
		var nw = Math.floor(mult1 * w);
		var nh = Math.floor(mult1 * h);
		$('#screenshot img').css('height',nh).css('width',nw);

		//section img
		w = $('#section img').width();
		h = $('#section img').height();
	
		nw = Math.floor(mult2 * w);
		nh = Math.floor(mult2 * h);
		$('#section img').css('height',nh).css('width',nw);
		
		//work_title img
		w = $('#work_title img').width();
		h = $('#work_title img').height();
	
		nw = Math.floor(mult2 * w);
		nh = Math.floor(mult2 * h);
		$('#work_title img').css('height',nh).css('width',nw);
		
		//section_long img
		w = $('#section_long img').width();
		h = $('#section_long img').height();
	
		nw = Math.floor(mult2 * w);
		nh = Math.floor(mult2 * h);
		$('#section_long img').css('height',nh).css('width',nw);
		
		//work_year img
		w = $('#work_year img').width();
		h = $('#work_year img').height();
	
		nw = Math.floor(mult2 * w);
		nh = Math.floor(mult2 * h);
		$('#work_year img').css('height',nh).css('width',nw);
		
	}
	
}			
				
				
	//====================
	function startDragging()
	//====================
	{
		fadeCharsIn();

		$('.zone').addClass('dragging');
		$('.secondary').removeClass('secondary');
		var Startpos = $('#map').position();
        $('#text').text("START: \nLeft: "+ Startpos.left + "\nTop: " + Startpos.top);	
	}
	
	//====================
	function whileDragging()
	//====================
	{

		curPos = $('#map').position();
        $('#text').text("Current Position: \nLeft: "+ curPos.left + "\nTop: " + curPos.top);	
	
	}

	//====================
	function moveFocusToPage(page)
	//====================
	{
		if (ret = in_array(page, matrix, '', true))
		{
			
			vals = ret.split('-');
			row = vals[0];
			col = parseInt(vals[1]);
			
			topDrop = rowLevels[row];
			leftPosition = (($('#map').width() - $(window).width())/2);
			curPage = page;
			
			//***** FIND COLUMN ******//
	
			switch(col)
			{
				case 1: //col 1

					leftDrop = ((($(window).width() - 900)/2) + 10);
				
				break;
				
				case 2: //center page

					leftDrop = (-leftPosition + 880);
				
				break;
				
				case 3: // col 3

					leftDrop = -leftPosition; 
				
				break;

				case 4: // col 4

					leftDrop = (-leftPosition - 880);
				
				break;

				case 5: // col 5

					leftDrop = (-leftPosition - (880*2));
				
				break;
				
				default:
					
					
				break;
				
			}

	
		
			$('.zone').addClass('dragging');
			$('.zone').removeClass('secondary');
		
			$('#map').animate({
     			left: leftDrop,
				top: topDrop
			  }, 500, function() {

				$('.dragging').removeClass('dragging');
				$('.zone').addClass('secondary');
				$('#page_' + curPage).removeClass('secondary');
				window.location.hash = '/' + urls[curPage];
				updateMeta(curPage);
				
				updateMenu(curPage);
				
			  });
			
		}


	}
	//====================
	function stopDragging(resize)
	//====================
	{


		curPos = $('#map').position();
		
		
		topDrop = rowLevels[1];  //1st row level
		leftPosition = (($('#map').width() - $(window).width())/2);
		leftDrop = -leftPosition; //center page
	
		curPage = 3;
		curRow = 1;
		
		col1Offset = (-leftPosition + (860 * 2)) - 430;  // 430 is half 860 ie: width of a .zone
		col2Offset = (-leftPosition + 860) - 430;
		col3Offset = (leftDrop) - 430;
		col4Offset = (-leftPosition - 860) - 430;
		col5Offset = (-leftPosition - (860 * 2)) - 2000; //2000 is just a high number so that if the user tries to drag the last column out of the screen (far right) the map gets dropped back to where it belongs
		
		
		//***** FIND ROW ****//
		
		if (curPos.top < -200 && curPos.top > -700) //2nd row level
		{
			topDrop = rowLevels[2];	
			curRow = 2;

		}

		if (curPos.top < -700 && curPos.top > -1200)	//3rd row level
		{
			topDrop = rowLevels[3];
			curRow = 3;

							
		}

		if (curPos.top < -1200 && curPos.top > -1700)	//3rd row level
		{
			topDrop = rowLevels[4];
			curRow = 4;

							
		}

		if (curPos.top < -1700 && curPos.top > -2300)	//3rd row level
		{
			topDrop = rowLevels[5];
			curRow = 5;

							
		}

		if (curPos.top < -2300 && curPos.top > -2800)	//3rd row level
		{
			topDrop = rowLevels[6];
			curRow = 6;

							
		}

		//***** FIND COLUMN ******//


		if (curPos.left > col1Offset)//col 1
		{

			leftDrop = ((($(window).width() - 900)/2) + 10);
			curPage = matrix[curRow + '-1'];

		}
		else if (curPos.left > col2Offset) //col 2
		{
			leftDrop = (-leftPosition + 880);
			curPage = matrix[curRow + '-2'];

		}
		else  if (curPos.left > col3Offset) //col 3
		{
			curPage = matrix[curRow + '-3'];
		}		
		else if (curPos.left > col4Offset) //col 4
		{
			leftDrop = (-leftPosition - 880);
			curPage = matrix[curRow + '-4'];

		}
		else if (curPos.left > col5Offset) //col 5
		{
			leftDrop = (-leftPosition - (880*2));
			curPage = matrix[curRow + '-5'];

		}		

		if (!lenseDisabled)
		{
				$('#map').animate({
					left: leftDrop,
					top: topDrop
				  }, 500, function() {


					$('.dragging').addClass('secondary');
		
					$('#page_' + curPage).removeClass('secondary');  
				
					
					$('.dragging').removeClass('dragging');
				
					if (!stopHashUpdate) window.location.hash = '/' + urls[curPage];
					updateMeta(curPage);
					
			
				  });
		}
		
			if (resize)
			{
				headerPos = ((($(window).width() - 880)/2)+4);
				
				//$('#mast_head').attr('style', 'position: fixed; margin: 0px; top: 0px; left: ' + headerPos + 'px;');

				$('#mast_head').animate({
					left: headerPos,
					top: 0,
					margin: 0
				  }, 500, function() {
					// Animation complete.
				  });
				
				floatingMenuPos = ((($(window).width() - 860)/2)-50);
				$('#floatingmenu').attr('style', 'z-index: 1000; top: 80px; right: ' + floatingMenuPos + 'px;');



				if ($('#centering').css('display') != 'block')
				{
					centeringPos = ((($(window).width() - 860)/2));
					$('#centering').attr('style', 'background: #000723; width: 860px; height: 520px; display: none; z-index: 2000; position: absolute; top: 80px; left: ' + centeringPos + 'px;');
				
				}
			}
			else
			{
				updateMenu(curPage);	
			}

				

	
	}
							
	//=============================================
	function in_array (needle, haystack, argStrict, returnKey) 
	//=============================================	
	{
		// Checks if the given value exists in the array  
		// 
		// version: 1008.1718
		// discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: vlado houba
		// +   input by: Billy
		// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
		// *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
		// *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
		// *     returns 2: false
		// *     example 3: in_array(1, ['1', '2', '3']);
		// *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
		// *     returns 3: true
		// *     example 4: in_array(1, ['1', '2', '3'], true);
		// *     returns 4: false
		var key = '', strict = !!argStrict; 
		if (strict) 
		{
			for (key in haystack) 
			{
				if (haystack[key] === needle) 
				{
					if (returnKey)
					{
						return key;
					}
					else
					{
						return true;
					}            
				}
			
			}
		} 
		else 
		{
			for (key in haystack) {
				if (haystack[key] == needle) 
				{   
					if (returnKey)
					{
						return key;
					}
					else
					{
						return true;
					}
				}	
			}
		}
		 return false;
	}



	//=============================================
	function bindDraggables() 
	//=============================================	
	{

		$( "#map" ).draggable({ cursor: 'move',
		
			start: function() {
			
				startDragging();

			},
			drag: function() {

				whileDragging();			
			
			},
			stop: function() {
			
				stopDragging(false);			
			}
		
		
		
		});
	
			$( "#floatingmenu" ).draggable({
										   
		    containment: 'parent',
			cursor: 'crosshair',
		
			start: function() {
			
				

			},
			drag: function() {

						
			
			},
			stop: function() {
			
							
			}
		
		
		
		});
	}
	
	//=============================================
	function updateMeta(page, titt, keyy, descrr) 
	//=============================================	
	{
		//title
		if (titleT[page]  != undefined) {
			title = $('title').html();
			//$('#tit').text(titleT[page] + ' - ' + title);
			document.title = titleT[page] + ' - ' + meta['title'];
		
		}
		else if(titt != undefined)
		{
			document.title = titt + ' - ' + meta['title'];
		}
		else
		{
			//$('#tit').text(meta['title']);
			document.title = meta['title'];
		}

		//meta keywords
		if (keyT[page]  != undefined) {
			$('#mk').attr('content', keyT[page]);
		
		}
		else if(keyy != undefined)
		{
			$('#mk').attr('content', keyy);	
		}
		else
		{
			$('#mk').attr('content', meta['keywords']);	
		}
		
		//meta description
		if (descrT[page]  != undefined) {
			$('#md').attr('content', descrT[page]);
		
		}
		else if(descrr != undefined)
		{
			$('#md').attr('content', descrr);	
		}		
		else
		{
			$('#md').attr('content', meta['descr']);	
		}
		
	}
	
	//=============================================
	function updateMenu(page) 
	//=============================================	
	{

		$('.mainlevel a').each(function() {
			
			if ( ( menuPage = $(this).attr('rel')) != '')
			{
				if (page == menuPage)
				{
					mainlevelPosition = $('.mainlevel').css('left');
					curMenuClass = $(this).parents('ul').attr('class');
					
					switch(curMenuClass)
					{
						case 'mainlevel':

							$('.mainlevel').css('left', '0px');
							$('.mainlevel').css('margin-bottom', '20px');
							$('#uponelevel').css('display', 'none');
							
						break;
						
						case 'sub':
						
							$('.sub').css('display', 'none');
							$(this).parents('ul.sub').css('display', 'block');
							$('.mainlevel').css('left', '-150px');
							$('#uponelevel').css('display', 'block');
							subMenuHeight = $(this).parents('ul.sub').height();
							$('.mainlevel').css('margin-bottom', subMenuHeight - 80 + 'px');

							
						
						break;
						
						case 'subsub':

							$('.subsub').css('display', 'none');
						    $('.sub').css('display', 'none');
							$(this).parents('ul.subsub').css('display', 'block');
							$(this).parents('ul.sub').css('display', 'block');
							$('.mainlevel').css('left', '-300px');
							$('#uponelevel').css('display', 'block');
							subsubMenuHeight = $(this).parents('ul.subsub').height();
							//subsubMenuHeight = (subsubMenuHeight > 0)	?	subsubMenuHeight	: 	120;
							$('.mainlevel').css('margin-bottom', subsubMenuHeight - 80 + 'px');							
							
						break;
						
					}
					
					$('#floatingmenu .active').removeClass('active');
					$(this).addClass('active');
				}
			}
										
		});



	}
	//=============================================
	function bindAllOtherLinks() 
	//=============================================	
	{

		$('.fld_bits_wrapper a').click(function() {
			
			page = $(this).attr('rel');
		
			moveFocusToPage(page);
			
			return false;
											  
		});

		$('.strategy_tabs a').click(function() {
			
			page = $(this).attr('rel');
		
			moveFocusToPage(page);
			
			return false;
											  
		});

		$('.forward a').click(function() {
			
			page = $(this).attr('rel');
		
			moveFocusToPage(page);
			
			return false;
											  
		});
	
	}
	//=============================================
	function bindFloatingMenu() 
	//=============================================	
	{


		$('#floatingmenu a').click(function() {
			
			page = $(this).attr('rel');
			target = $(this).attr('target');
			
			if (target == '_blank') { 
			
				window.location = $(this).attr('href');
			
			}
			else
			{
			
				moveFocusToPage(page);
			
			}
			
			return false;
											  
		});

		/*
		$('#close a').click(function() {
			
			page = $(this).attr('rel');
			target = $(this).attr('target');
			
			
			if (target == '_blank') { 
			
				window.location = $(this).attr('href');
			
			}
			else
			{
			
				moveFocusToPage(page);
			
			}
			
			return false;
											  
		});
		*/



		$('.sub-a').click(function() {
			
			subMenuHeight = $(this).parents('li').children('.sub').height();
			$('.sub').css('display', 'none');
			$(this).parents('li').children('.sub').css('display', 'block');
			$('#uponelevel').css('display', 'block');
			
					$('#floatingmenu ul.mainlevel').animate({
						left: "-=150",
						marginBottom: subMenuHeight - 80
						
					  }, 500, function() {
	
					  });
			
			return false;
											  
		});
	
	
		$('.subsub-a').click(function() {
			
			subsubMenuHeight = $(this).parents('li').children('.subsub').height();
			$('.subsub').css('display', 'none');
			$(this).parents('li').children('.subsub').css('display', 'block');
			$('#uponelevel').css('display', 'block');
	
			
					$('#floatingmenu ul.mainlevel').animate({
						left: "-=150",
						marginBottom: subsubMenuHeight - 80
						
					  }, 500, function() {
	
					  });
			
			return false;
											  
		});
	
	}
	
	//=============================================
	function zoomOff(userPage) 
	//=============================================	
	{
		
		if (lenseDisabled)
		{
		//start test
			$('#lense_right').addClass('lense_off').removeClass('lense_grey');
			$('#lense_left').addClass('lense_grey').removeClass('lense_on');
			lenseDisabled = true;
			
			$('.freeze').unbind('click');
			$('.zone').removeClass('freeze');
			$('#floatingmenu ul li a').removeClass('freeze');
			bindFloatingMenu();
			bindDraggables();
								
			lenseDisabled = false;
			resizeOk = true;
		
		
						$('.zone').animate({
							width: resetZoneWidth,
							height: resetZoneHeight					
						  }, {queue:false, duration:800, complete: function( ) {
						
						  }});			
		
		
						$('.placeholder').animate({
							width: '+=8%',
							height: '+=8%'					
						  }, {queue:false, duration:800, complete: function() {
		
								$('.placeholder').css('height', '0px');
								$('.content').children().css('display', 'block');
								$('.zone .content').css('padding', '40px 30px');
								$('.zone').not('#page_' + curPage).addClass('secondary');

		
			
						  }});
		
		
		
		
							if (userPage !== undefined)
							{
															
								leftPosition = ((resetMapWidth - $(window).width())/2);
								leftDrop = -leftPosition; //center page
		
								$('#map').animate({
									width: resetMapWidth,
									height: resetMapHeight,
									top: -472,
									left: leftDrop
								  }, {queue:false, duration:700, complete: function() {
			
										moveFocusToPage(userPage);
										
								  }});
								
							}
							else
							{
							
								$('#map').animate({
									top: resetMapTop,
									left: resetMapLeft,
									width: resetMapWidth,
									height: resetMapHeight
								  }, {queue:false, duration:1000, complete: function() {
											window.location = resetHash;
								  }});
							}
		
			
		
		
		
		
							$('.row2').animate({
								top: resetRow2Top
		
								
							  }, {queue:false, duration:600, complete: function() {
			
		
							  }});
		
							$('.row3').animate({
								top: resetRow3Top
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});

		
							$('.row4').animate({
								top: resetRow4Top
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});

		
							$('.row5').animate({
								top: resetRow5Top
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});

		
							$('.row6').animate({
								top: resetRow6Top
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});
							
							$('.col2').animate({
								left: resetCol2Left
								
							  },{queue:false, duration:600, complete: function() {
			
							
			
							  }});	
		
							$('.col3').animate({
								left: resetCol3Left
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});

							$('.col4').animate({
								left: resetCol4Left
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});

							$('.col5').animate({
								left: resetCol5Left
								
							  }, {queue:false, duration:600, complete: function() {
			
							
			
							  }});
		
			
		return;
		//end test
		}


	
	}
	
	//=============================================
	function fadeCharsIn()
	{
	//=============================================
		
			$('.services_char').each(function() {
		
				if ($(this).css('display') == 'none')
				{
					$('.tab_descr').fadeOut();
					$(this).fadeIn();
					$(this).parents('.content').children('.page-title').removeClass().addClass('page-title');
				
				}
		
												  
			});
			
			$('.set').css('display', 'none');
			$('.set1').fadeIn();
			
	}

	//=============================================
	function blindUp()
	{
	//=============================================
		
		clearInterval(progressId);
		progressId = setInterval(function(){
										  
			curProgress = $('#progress').text();
			if (curProgress < 100)
			{
				++curProgress;
				$('#progress').text(curProgress);
			}
			else
			{
				clearInterval(progressId);

				$('#loading').fadeOut(function() {
		
					$('#upper-curtain').animate({ height: "toggle" }, 1500, function() { });
					$('#lower-curtain').animate({ height: "toggle" }, 1500, function() { });
					
					setTimeout('showLenses()', 15000);
			
				});	
		
			}
		
		}, 20);
		
	
			
	}
	//=============================================
	function updateProgress()
	{
	//=============================================
		
		
		curProgress = $('#progress').text();
		if (curProgress < 100)
		{
			++curProgress;
			$('#progress').text(curProgress);
			//window.status = curProgress + '% Complete';
		}		
	
	}

	//=============================================
	function showLenses()
	{
	//=============================================
		
		
		$('#lense_right, #lense_left').css('display', 'block');	
	
	}
	
	//=============================================
	function zoomIn() 
	//=============================================	
	{

		if (!lenseDisabled)
		{
			
			fadeCharsIn();
	
			$('#lense_right').addClass('lense_grey').removeClass('lense_off');
			$('#lense_left').addClass('lense_on').removeClass('lense_grey');
			lenseDisabled = true;
			resizeOk = false;
			
			
			resetMapLeft = $('#map').css('left');
			resetMapTop = $('#map').css('top');
			resetMapLeft = $('#map').css('left');	
			resetRow2Top = $('.row2').css('top');
			resetRow3Top = $('.row3').css('top');
			resetRow4Top = $('.row4').css('top');
			resetRow5Top = $('.row5').css('top');
			resetRow6Top = $('.row6').css('top');			
			resetCol2Left = $('.col2').css('left');
			resetCol3Left = $('.col3').css('left');
			resetCol4Left = $('.col4').css('left');
			resetCol5Left = $('.col5').css('left');			
			resetZoneWidth = $('.zone').width();
			resetZoneHeight = $('.zone').height();
			resetMapWidth = $('#map').width();
			resetMapHeight = $('#map').height();
			resetHash = window.location.hash;

			newZoneWidth = 0.25 * resetZoneWidth;
			newZoneHeight = 0.25 * resetZoneHeight;
			newMapWidth = 0.25 * resetMapWidth;
			newMapHeight = 0.25 * resetMapHeight;
			rowOffset = 1.1 * newZoneHeight;
			colOffset = 1.06 * newZoneWidth;
			
			center = ((($(window).width() - newMapWidth)/2));
			
			$('.content').children().css('display', 'none');
			$('.zone .content').css('padding', '0px');
			
			$('.placeholder').css('height', '530px');
			
			/*
			$("#map").draggable("destroy");

			$( "#map" ).draggable({
			
			containment: 'parent'
			
			
			
			});
			*/
		
						$('.zone').animate({
							width: newZoneWidth,
							height: newZoneHeight								
						  }, {queue:false, duration:1000, complete: function( ) {
							  
		
						  }});
		
						$('.placeholder').animate({
							width: '-=8%',
							height: '-=8%'							
						  }, {queue:false, duration:1000, complete: function( ) {
							  
		
						  }});
							
							
							$('#map').animate({
								top: '120',
								left: center,
								width: newMapWidth,
								height: newMapHeight								
							  }, {queue:false, duration:1000, complete: function() {
								
									$('.zone').removeClass('secondary').addClass('freeze');
									$('#floatingmenu ul li a').addClass('freeze');
									
									$('.freeze').bind('dblclick', function() {
									  newPage = $(this).attr('id');
									  newPage = newPage.replace('page_','');
									  if (newPage == '')
									  {
										newPage = $(this).attr('rel');  
									  }
									  if (newPage != '')
									  {
										  zoomOff(newPage);
									  }
									});

					
							  }});
		
		
							$('.row2').animate({
								top: rowOffset
							  }, {queue:false, duration:1000, complete: function() {
			
		
							  }});
		
							$('.row3').animate({
								top: rowOffset * 2
							  }, {queue:false, duration:1000, complete: function() {
			
							  }});

							$('.row4').animate({
								top: rowOffset * 3
							  }, {queue:false, duration:1000, complete: function() {
			
							  }});

							$('.row5').animate({
								top: rowOffset * 4
							  }, {queue:false, duration:1000, complete: function() {
			
							  }});
		

							$('.row6').animate({
								top: rowOffset * 5
							  }, {queue:false, duration:1000, complete: function() {
			
							  }});
							
							$('.col2').animate({
								left: colOffset
							  },{queue:false, duration:1000, complete: function() {
					
							  }});	
		
							$('.col3').animate({
								left: colOffset * 2
							  }, {queue:false, duration:1000, complete: function() {

							  }});

							$('.col4').animate({
								left: colOffset * 3
							  }, {queue:false, duration:1000, complete: function() {

							  }});
							
							$('.col5').animate({
								left: colOffset * 4
							  }, {queue:false, duration:1000, complete: function() {

							  }});							
		
		return false;

		}


	
	}
	

	$(function() {

	curHash = window.location.hash;
	curHash = curHash.replace('#/', '');
	pathname = window.location.pathname;
	
	if (curHash != '')
	{
		if ( (pagina = in_array(curHash, urls, '', true)) != '' )
		{
			moveFocusToPage(pagina);
		}
		else if (curHash.indexOf('portfolio') > 0)
		{
			//moveFocusToPage(19);
			portfolioZoom(curHash);
		}
	}
	else if (pathname != '/')
	{
		pathname = pathname.substr(1);
		if ( (pagina = in_array(curHash, urls, '', true)) != '' )
		{
			window.location = '/#/' + pathname;
			return;
		}
		else if (pathname.indexOf('portfolio') > 0)
		{
			//moveFocusToPage(19);
			portfolioZoom(pathname);
		}		

	}
	
	resize();
	
	$(window).resize(function() {
				
	 if (resizeOk)
	 {
	 	stopDragging(true);
	  
	 }
	 
	});


	$('#lense_left a').click(function() {

		zoomOff();
			  					  
	});
	




	$('#lense_right a').click(function() {

	
		zoomIn();

					  					  
	});


	/* SCHEDA HOME */
	
	$('#home_fld_dev_front a').mouseover(function() {

	
		$('#home_fld_dev_sheet').animate({
			top: '-63px',
			left: '-8px',
			width: '200px'
		  }, {queue:false, duration:200, complete: function() {

		  }});

					  					  
	});

	$('#home_fld_dev_front a').mouseout(function() {

	
		$('#home_fld_dev_sheet').animate({
			top: '10px',
			left: '1px',
			width: '170px'
		  }, {queue:false, duration:200, complete: function() {

		  }});

					  					  
	});

	$('.home_fld_front_small a').mouseover(function() {

	
		$(this).parents('div').children('.sheet').animate({
			top: '-51px',
			left: '-5px',
			width: '133px'
		  }, {queue:false, duration:200, complete: function() {

		  }});

					  					  
	});

	$('.home_fld_front_small a').mouseout(function() {

	
		$(this).parents('div').children('.sheet').animate({
			top: '10px',
			left: '-2px',			
			width: '123px'
		  }, {queue:false, duration:200, complete: function() {

		  }});

					  					  
	});
	
	/* SCHEDA DESIGN/DEVELOPMENT/MARKETING/OTHER */
	

	$('.services_tabs a').mouseover(function() {

		cl = $(this).attr('class');

		if ($('.' + cl + '_descr').css('display') != 'block')
		{

			$(this).parents('.content').children('.services_right').children('.services_char').fadeOut();
			$(this).parents('.content').children('.services_right').children('.tab_descr').fadeOut();
			$(this).parents('.content').children('.page-title').removeClass().addClass('page-title ' + cl + '_title');
			$(this).parents('.content').children('.services_right').children('.' + cl + '_descr').fadeIn();
		}

					  					  
	});


	$('.services_right').mouseover(function() {

		if ($(this).children('.services_char').css('display') == 'none')
		{
			$(this).children('.tab_descr').fadeOut();	
			$(this).parents('.content').children('.page-title').removeClass().addClass('page-title');
			$(this).children('.services_char').fadeIn();
		
		}

					  					  
	});

	/* SCHEDA FAQ & PRICING */
	
	$('.more a').click(function() {
		
		obj = $(this).parents('.sets_cont');
		count = parseInt($(this).parents('.sets_cont').children('.set').size());
		$(this).parents('.sets_cont').children('.set').each(function(){
			if ($(this).css('display') == 'block')
			{
				setId = parseInt($(this).attr('rel'));
				$(this).fadeOut();
				
				newSet = ((setId + 1) > count)		?	1	:		setId + 1;
				$(obj).children('.set' + newSet).fadeIn();
				return false;
			}
		});
		
		return false;
					  					  
	});	

	/* SCHEDA PORTFOLIO */

/*	$('#portfolio_section li a').click(function() {
	
		level = $(this).attr('rel');
		$('#portfolio_section li a').attr('class', '');
		$(this).addClass('highlite');
		
					$('#portfolio_holder ul').removeClass('db');
					
					$('#portfolio_holder ul').each(function(){
						if ($(this).css('display') == 'block')
						{

							$(this).fadeOut('slow', function(){
																			   
								$('#portfolio_' + level).fadeIn();											   
																			   
																			   
							});
					
							
						}
					});
					
				
	
		return false;
	
	});*/
	



	$('#portfolio_intro li a').click(function() {

	
		portfolioZoom($(this));			
		
		return false;
					  					  
	});

	$('.pfolio').mouseover(function() {
		
		$('#quick_menu li ul').css('display', 'none');
		$(this).parents('li').children('ul').fadeIn();
					  					  
	});
	
	$('.go').mouseout(function() {
		
		$(this).parents('li').children('ul').fadeOut();
					  					  
	});
	
	$('.our_work_sub .maina').mouseover(function() {
		
		$('.our_work_sub ul').each(function(){
			
			if ($(this).css('display') == 'block')
			{
				$(this).css('display', 'none');
				
			}
		});
		
		$(this).parents('li').children('ul').fadeIn();
					  					  
	});

	$('.detector').mouseover(function() {
		
		$('#our_work ul').css('display', 'none');
					  					  
	});	

	$('.our_work_subsub a').click(function() {
		
		portfolioZoomInternal($(this));
		return false;
	
	});

		
	$('#close a').click(function() {
		
		stopHashUpdate = false;
		page = $(this).attr('rel');
		target = $(this).attr('target');
		$('#close').css('display', 'none');
		coeff = ((($(window).width() - 860)/2));
		
				$('#centering').animate({
					width: 860,
					height: 520,
					opacity: '0',
					top: '+=80',
					left: '+=' + coeff
					
				  }, 500, function() {
					$('#centering').css('display', 'none');
					
					if (target == '_blank') { 
					
						window.location = $(this).attr('href');
					
					}
					else
					{
					
						moveFocusToPage(page);
					
					}
			
					
					//$('#centering').empty(':not(:#close)');
					//$('#centering').children(':not(:#close)').remove();
				  });			
		
		return false;
					  					  
	});




	$('#uponelevel a').click(function() {
		
		$('#uponelevel').css('display', 'block');
		level = parseInt($('#floatingmenu ul.mainlevel').css('left'));
		
		if (level < 0)
		{
			
			level += 150;


			
			switch(level)
			{
				case 0:
		
					//$('.sub').css('display', 'none');
					$('#uponelevel').css('display', 'none');

					$('#floatingmenu ul.mainlevel').animate({
						marginBottom: 20
						
					  }, 500, function() {
		
						
		
					  });
			
				
				break;
				
				case -150:

					//$('.subsub').css('display', 'none');
					
					$('.sub').each(function() {
										   
						if ($(this).css('display') == 'block')			   
						{
							subHeight = $(this).height();
							
							$('#floatingmenu ul.mainlevel').animate({
								marginBottom: subHeight - 100
								
							  }, 500, function() {
				

				
							  });
					
							
						}
						
					});
					
					
				break;
				
			}
			
			
			$('#floatingmenu ul.mainlevel').animate({
				left: "+=150"
				
			  }, 500, function() {

			  });
			
			
			
			
		}


		return false;
					  					  
	});
	

		bindFloatingMenu();
		
		bindAllOtherLinks();
		

		bindDraggables();
		
		
	});

