﻿	var index;
	
	$j(document).ready(function() {
		index = 
			(	window.location.href=='http://office-planning.server/' || window.location.href=='http://data.office-planning.com.ua/' || 
				window.location.href=='http://office-planning.server/eng/'		|| 
				window.location.href=='http://data.office-planning.com.ua/eng/'	|| 
				window.location.href=='http://www.office-planning.com.ua/eng/'	|| 
				window.location.href=='http://www.office-planning.com.ua/'		||
				window.location.href=='http://office-planning.com.ua/eng/'		|| 
				window.location.href=='http://office-planning.com.ua/'
			) 
			? true : false;			
		activateBackgroundimage();
		activateMenu();
		activateContacts();
	});	
	
	function activateMenu(){
		
		if(!$j.browser.msie){
			$j("#menu_wrapper").animate( { height: "50px",  opacity: 0.7 }, 300, 'easeInOutExpo',  function(){
				$j("#menu_wrapper").animate( { width: "888px", opacity: 0.9 }, 1000, 'easeInOutExpo', function(){
					$j('#nav').droppy();				
					activateImageMenu();
				});	
			});
		} else {
			$j("#menu_wrapper").animate( { height: "50px" }, 300, 'easeInOutExpo',  function(){
				$j("#menu_wrapper").animate( { width: "888px" }, 1000, 'easeInOutExpo', function(){
					$j('#nav').droppy();				
					activateImageMenu();
				});	
			});
		}
	}
	function activateImageMenu(){
		
		var $currItemMenu = $j("a[@href=" + document.location.pathname + "] img");		
		if( $currItemMenu.length ){
			activateItemMenu( $currItemMenu );
			$currItemMenu.addClass('current_menu_item');
		}
		
		$j("#nav img[@class!=current_menu_item]").bind('mouseover', function(){
			activateItemMenu(this);		
		}).bind('mouseout', function(){
			activateItemMenu(this);			
		});
	}	
	function activateItemMenu(currMenuImage){
		
		var $currMenuImage 	= $j(currMenuImage);
		var imageSrc			= $currMenuImage.attr('src');		
		var newImageSrc		= 
					( imageSrc.match( /^([\/]?)images\/menu\/(.*)\_green.png$/ )==null )
					? imageSrc.replace( /^([\/]?)images\/menu\/(.*)\.png/, '$1images/menu/$2_green.png' )
					: $currMenuImage.attr('src').replace( /^([\/]?)images\/menu\/(.*)\_green.png/, '$1images/menu/$2.png' );		
		$currMenuImage.attr('src', newImageSrc );
	}
	
	function activateBackgroundimage(){
		if(index){
			activateBackgroundimageForIndex();
		} else {
			activateBackgroundimageForOtherPage();
		}
	}
	function activateBackgroundimageForOtherPage(){
		var srcImage	= ($j("#backgroundImage").length!=0 && $j("#backgroundImage").val().length!=0) ? $j("#backgroundImage").val() : 'bg_product.jpg';
		var $img			= $j('<img/>').attr('src', '/upload/backgrounds/'+srcImage).css( 'width', $j(window).width()<1024 ? 1024 : '100%' );
		$j("#backgroundimage_wrapper").append( $img );			
		$img.preload({
			'onFinish':function(){
				$j('.current_img').fadeIn(700); 
			}
		});
	}
	
	function activateContacts(){
		$j('#contact_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'right' }, 1300, function(){ 
			$j("#contact_wrapper").animate( { opacity: 0.95 }, 100 );		
			if(index){
				activateNavigationPanel();
			}
		});
	}	
	
	// -- Index --		
	
	function activateBackgroundimageForIndex(){		
			var thumb	= $j('#mycarousel li img:first');			
			// Thumb
			changeThumb( thumb );			
			// Image			
			changeMainImage( createNewMainImageOfThumb( thumb ) );
			// Title
			changeTitleAndLink( thumb );
	}
	function activateNavigationPanel(){	
		$j('#navigation_panel_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'down' }, 567, function(){ 
			$j("#navigation_panel_wrapper").animate( { opacity: 1 }, 100 );
			activateToggleNavigationPanel();		
		});		
		$j('#navigation_panel_wrapper_right').toggle('slide', { easing: 'easeInOutExpo', direction: 'down' }, 500, function(){ 
			$j("#navigation_panel_wrapper_right").animate( { opacity: 1 }, 100, function(){ $j("#toggle_navigation_panel img").click(); } );			
		});
	}
	var navigationPanelIsOpen = false;
	function activateToggleNavigationPanel(){
		$j("#toggle_navigation_panel img").bind('click', function(){
			if( navigationPanelIsOpen==false ){
				$j(this).attr('src', 'images/toggle_open.gif');
				$j('.jcarousel-skin-tango .jcarousel-container-horizontal, .jcarousel-skin-tango .jcarousel-clip-horizontal').width(510);				
				$j("#navigation_panel_wrapper").animate( {'width':'630px', 'left':'248px'}, 500 ); //206 //498px //462px
				navigationPanelIsOpen = true;
			} else {
				$j(this).attr('src', 'images/toggle.gif');
				$j('.jcarousel-skin-tango .jcarousel-container-horizontal, .jcarousel-skin-tango .jcarousel-clip-horizontal').width(83);
				$j("#navigation_panel_wrapper").animate( {'width':'192px', 'left':'681px'}, 500 );
				navigationPanelIsOpen = false;
			}
		});	
		activateSlideshowOnMain();
	}
	// -- slide show --
	function activateSlideshowOnMain(){
		$j('#mycarousel').jcarousel({
			scroll: 1,
        	itemLoadCallback: mycarousel_itemLoadCallback,
			initCallback: mycarousel_initCallback
		});
	}
	function mycarousel_itemLoadCallback(carousel, state){
	}
	function mycarousel_initCallback(){
		$j('#product_mycarousel_wrapper').css('visibility', 'visible');
		$j('.thumb, .current_thumb').bind('click', function(){			
			// Thumb
			changeThumb( this );			
			// Image			
			changeMainImage( createNewMainImageOfThumb( this ) );
			// Title
			changeTitleAndLink( this );			
		});
	}
	function changeThumb(thumb){
		$j('.current_thumb').removeClass('current_thumb').addClass('thumb');
		$j(thumb).removeClass('thumb').addClass('current_thumb');
	}
	function createNewMainImageOfThumb(thumb){
		var srcImage 	= $j(thumb).attr('src').split( '/upload/settings/.thumbs/75x50_' );		
		var $img 		= $j( '<img/>' ).attr('src', '/upload/settings/'+srcImage[1]).css({'width':'100%'}).addClass('current_img');
		$j("#backgroundimage_wrapper").css({'width': $j(window).width()<998 ? 998 : '100%', 'height': $j(window).height()<750 ? 750 : '100%' });
		
		return $img ;
	}
	function changeMainImage($img){
		$current_img	= $j('.current_img');
		$j("#backgroundimage_wrapper").append( $img );			
			$img.preload({
				'onFinish':function(){ 					
					$current_img.fadeOut(500, function(){
						$current_img.remove();
					});					
					$j('.current_img').fadeIn(700); 
				}
		});
	}	
	function changeTitleAndLink(thumb){
		$j('#thumb_title_block h2 a').text( $j(thumb).attr('title') );
		$j('#thumb_title_block h2 a').attr( 'href', $j(thumb).attr('alt') );
	}
	
	// -- Products --
	
	var thisThumbIsSecond = false;
	function activateProducts(){
		activateProduct_mycarousel();
		
		var thumb = $j('#mycarousel li img:first');
		changeThumbForProduct(thumb);
		changeMainImageForProduct( createNewMainImageOfThumbForProduct(thumb) );		
	}
	function activateProduct_mycarousel(){
		$j('#mycarousel').jcarousel({
			scroll: 1,
			vertical: true,
			size: $j('.thumb_vertical, .current_thumb_vertical').length,
			initCallback: product_mycarousel_itemCallback
		});
	}
	function product_mycarousel_itemCallback(carousel, state){
		$j('#product_mycarousel_wrapper').css('visibility', 'visible');
		$j('.thumb_vertical, .current_thumb_vertical').bind('click', function(){
																	
			$j('.current_img_product').css('opacity','0.5');
			
			// Thumb
			changeThumbForProduct( this );			
			// Image			
			changeMainImageForProduct( createNewMainImageOfThumbForProduct( this ) );			
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
		});
		
		activateNavigationArrow(carousel);
	}
	function changeThumbForProduct( thumb ){		
		$j('.current_thumb_vertical').removeClass('current_thumb_vertical').addClass('thumb_vertical');
		$j(thumb).removeClass('thumb_vertical').addClass('current_thumb_vertical');
	}
	function createNewMainImageOfThumbForProduct(thumb){					
		//var $srcImage 	= $j(thumb).attr('src').replace( /(\/upload\/product[\/]+)([0-9]+)\/.thumbs\/75x50_(.*)/, '/upload\/product/$2/$3' );		
		var srcImage 	= $j(thumb).attr('src').replace( /(\/upload\/product[\/]+)([0-9]+)\/.thumbs\/75x50_(.*)/, '/img/6/upload\/product/$2/$3' );
		var textImage	= $j(thumb).attr('alt');
		var $img 		= $j( '<img/>' ).attr('src', srcImage).attr('alt', textImage).addClass('current_img_product');
		return $img;
	}
	function changeMainImageForProduct($img){
		$current_img	= $j('.current_img_product');
		$j("#review_image_wrapper").append( $img );		
		$img.preload({
			'onFinish':function(){				
				$current_img.fadeOut(500, function(){
					$current_img.remove();					
				});
				$j('.current_img_product').fadeIn(700);
				
				$j('#text_wrapper div').fadeOut(100, function(){
					$j('#text_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'up' }, 400, function(){					
						changeText($img);						
						$j('#text_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'up' }, 300, function(){
							$j('#text_wrapper div').fadeIn();
						});
					});					
				});				
			}
		});		
	}
	function changeText($img){
		$j("#text_wrapper div").html( $j('span.'+$img.attr('alt')).html() );
	}
	function activateNavigationArrow(carousel){
		$j('#left_arrow').bind('click', function(){
			
			$j('.current_img_product').css('opacity','0.5');
			
			$prev_thumb = $j('.current_thumb_vertical').parent('li').prev('li').children('img');
			if($prev_thumb.length>0){
				changeThumbForProduct( $prev_thumb );
				changeMainImageForProduct( createNewMainImageOfThumbForProduct( $prev_thumb ) );
			}
			if( thisThumbIsSecond==false ){				
				carousel.prev();
			}
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
		});
		
		$j('#right_arrow').bind('click', function(){	
																
			$j('.current_img_product').css('opacity','0.5');
			
			$next_thumb = $j('.current_thumb_vertical').parent('li').next('li').children('img');
			if($next_thumb.length>0){
				changeThumbForProduct( $next_thumb );
				changeMainImageForProduct( createNewMainImageOfThumbForProduct( $next_thumb ) );
			}
			if( thisThumbIsSecond==true ){
				carousel.next();
			}
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
			
			//carousel.scroll(jQuery.jcarousel.intval(2));
		});
	}
	
	// -- News --
	
	var thisThumbIsSecond = false;
	function activateNews(){
		activateNews_mycarousel();
		
		var thumb = $j('#mycarousel li img:first');
		changeThumbForNews(thumb);
		changeMainImageForNews( createNewMainImageOfThumbForNews(thumb) );		
	}
	function activateNews_mycarousel(){
		$j('#mycarousel').jcarousel({
			scroll: 1,
			vertical: true,
			size: $j('.thumb_vertical').length,
			initCallback: news_mycarousel_itemCallback
		});
	}
	function news_mycarousel_itemCallback(carousel, state){
		$j('#product_mycarousel_wrapper').css('visibility', 'visible');
		$j('.thumb_vertical, .current_thumb_vertical').bind('click', function(){
																	
			$j('.current_img_product').css('opacity','0.5');														
																	
			// Thumb
			changeThumbForNews( this );			
			// Image			
			changeMainImageForNews( createNewMainImageOfThumbForNews( this ) );
			// Title and date
			changeTitleAndDateNews( $j(this) );
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
		});
		
		activateNavigationArrowNews(carousel);
	}
	function changeThumbForNews( thumb ){		
		$j('.current_thumb_vertical').removeClass('current_thumb_vertical').addClass('thumb_vertical');
		$j(thumb).removeClass('thumb_vertical').addClass('current_thumb_vertical');
	}
	function createNewMainImageOfThumbForNews(thumb){					
		//var $srcImage 	= $j(thumb).attr('src').replace( /(\/upload\/news[\/]+)([0-9]+)\/.thumbs\/75x50_(.*)/, '/upload\/news/$2/$3' );		
		var srcImage 	= $j(thumb).attr('src').replace( /(\/upload\/news[\/]+)([0-9]+)\/.thumbs\/75x50_(.*)/, '/img/6/upload\/news/$2/$3' );
		var textImage	= $j(thumb).attr('alt');
		var textDate	= $j(thumb).attr('date');
		var textTitle	= $j(thumb).attr('title');
		var $img 		= $j( document.createElement('img') ).attr('src', srcImage).attr({'alt':textImage, 'date':textDate, 'title':textTitle}).addClass('current_img_product');
		return $img;
	}
	function changeMainImageForNews($img){
		$current_img	= $j('.current_img_product');
		$j("#review_image_wrapper").append( $img );		
		$img.preload({
			'onFinish':function(){				
				$current_img.fadeOut(500, function(){
					$current_img.remove();					
				});
				$j('.current_img_product').fadeIn(700);
				
				$j('#text_wrapper div').fadeOut(100, function(){
					$j('#text_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'up' }, 400, function(){					
						changeTitleAndDateNews($img);
						changeTextNews($img);						
						$j('#text_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'up' }, 300, function(){
							$j('#text_wrapper div').fadeIn();
						});
					});					
				});				
			}
		});		
	}
	function changeTitleAndDateNews($thumb){
		$j("#titles_wrapper #cat_name").text( $thumb.attr('title') );
		$j("#titles_wrapper #subcat_name").text( $thumb.attr('date') );
	}
	function changeTextNews($thumb){
		$j("#text_wrapper div").text( $thumb.attr('alt') );
	}
	function activateNavigationArrowNews(carousel){
		$j('#left_arrow').bind('click', function(){
															  
			$j('.current_img_product').css('opacity','0.5');
			
			$prev_thumb = $j('.current_thumb_vertical').parent('li').prev('li').children('img');
			if($prev_thumb.length>0){
				changeThumbForNews( $prev_thumb );
				changeMainImageForNews( createNewMainImageOfThumbForNews( $prev_thumb ) );
			}
			if( thisThumbIsSecond==false ){				
				carousel.prev();
			}
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
		});
		
		$j('#right_arrow').bind('click', function(){
			
			$j('.current_img_product').css('opacity','0.5');
																
			$next_thumb = $j('.current_thumb_vertical').parent('li').next('li').children('img');
			if($next_thumb.length>0){
				changeThumbForNews( $next_thumb );
				changeMainImageForNews( createNewMainImageOfThumbForNews( $next_thumb ) );
			}
			if( thisThumbIsSecond==true ){
				carousel.next();
			}
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
			
			//carousel.scroll(jQuery.jcarousel.intval(2));
		});
	}
	
	// -- Projects --
	
	var thisThumbIsSecond = false;
	function activateProjects(){
		activateProjects_mycarousel();
		
		var $thumb = $j('#mycarousel li img:first');
		if($thumb.attr('src')){
			changeThumbForProjects($thumb);
			changeMainImageForProjects( createNewMainImageOfThumbForProjects($thumb) );
		}
	}
	function activateProjects_mycarousel(){
		$j('#mycarousel').jcarousel({
			scroll: 1,
			vertical: true,
			size: $j('.thumb_vertical').length,
			initCallback: projects_mycarousel_itemCallback
		});
	}
	function projects_mycarousel_itemCallback(carousel, state){
		$j('#product_mycarousel_wrapper').css('visibility', 'visible');
		$j('.thumb_vertical, .current_thumb_vertical').bind('click', function(){
			
			$j('.current_img_product').css('opacity','0.5');
			
			// Thumb
			changeThumbForProjects( this );			
			// Image			
			changeMainImageForProjects( createNewMainImageOfThumbForProjects( this ) );
			// Title
			changeTitleProjects( $j(this) );
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
		});
		
		activateNavigationArrowProjects(carousel);
	}
	function changeThumbForProjects( thumb ){		
		$j('.current_thumb_vertical').removeClass('current_thumb_vertical').addClass('thumb_vertical');
		$j(thumb).removeClass('thumb_vertical').addClass('current_thumb_vertical');
	}
	function createNewMainImageOfThumbForProjects(thumb){					
		var $srcImage 	= $j(thumb).attr('src').replace( /\/upload\/projects\/.thumbs\/75x50_(.*)/, '/img/6/upload/projects/$1' );
		var textImage	= $j(thumb).attr('alt');
		var textDate	= $j(thumb).attr('date');
		var textTitle	= $j(thumb).attr('title');
		var $img 		= $j( document.createElement('img') ).attr('src', $srcImage).attr({'alt':textImage, 'title':textTitle}).addClass('current_img_product');
		return $img;
	}
	function changeMainImageForProjects($img){
		$current_img	= $j('.current_img_product');
		$j("#review_image_wrapper").append( $img );		
		$img.preload({
			'onFinish':function(){				
				$current_img.fadeOut(500, function(){
					$current_img.remove();					
				});
				$j('.current_img_product').fadeIn(700);
				
				$j('#text_wrapper div').fadeOut(100, function(){
					$j('#text_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'up' }, 400, function(){					
						changeTitleProjects($img);
						changeTextProjects($img);						
						$j('#text_wrapper').toggle('slide', { easing: 'easeInOutExpo', direction: 'up' }, 300, function(){
							$j('#text_wrapper div').fadeIn();
						});
					});					
				});				
			}
		});		
	}
	function changeTitleProjects($thumb){
		$j("#titles_wrapper #cat_name").text( $thumb.attr('title') );
		$j("#titles_wrapper #subcat_name").text( $thumb.attr('date') );
	}
	function changeTextProjects($thumb){
		$j("#text_wrapper div").text( $thumb.attr('alt') );
	}
	function activateNavigationArrowProjects(carousel){
		$j('#left_arrow').bind('click', function(){
			
			$j('.current_img_product').css('opacity','0.5');
			
			$prev_thumb = $j('.current_thumb_vertical').parent('li').prev('li').children('img');
			if($prev_thumb.length>0){
				changeThumbForProjects( $prev_thumb );
				changeMainImageForProjects( createNewMainImageOfThumbForProjects( $prev_thumb ) );
			}
			if( thisThumbIsSecond==false ){				
				carousel.prev();
			}
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
		});
		
		$j('#right_arrow').bind('click', function(){
			
			$j('.current_img_product').css('opacity','0.5');
			
			$next_thumb = $j('.current_thumb_vertical').parent('li').next('li').children('img');
			if($next_thumb.length>0){
				changeThumbForProjects( $next_thumb );
				changeMainImageForProjects( createNewMainImageOfThumbForProjects( $next_thumb ) );
			}
			if( thisThumbIsSecond==true ){
				carousel.next();
			}
			
			thisThumbIsSecond = thisThumbIsSecond ? false : true;
			
			//carousel.scroll(jQuery.jcarousel.intval(2));
		});
	}
	
	// -- Staff --
	
	function activateStaff(){
		$j('#mycarousel').jcarousel();
		activateStaffShow();
	}
	function activateStaffShow(){
		$j(".staff_image_s").bind('mouseover', function(){
			staffShow(this);
		});
	}
	
	function staffShow(currentThumbImage){
		
		deactivateStaff();
		
		var $currentThumbImage	= $j(currentThumbImage);		
		var $parents_li			= $currentThumbImage.parents('li');
		var srcImageBig			= $currentThumbImage.attr('src').replace( /^(\/images\/staff\/[0-9]+)([a-z])\.([a-z]{3})/, '$1b.$3' );
		var $img_big_wrapper 	= $currentThumbImage.prev();
		
		var $imageBig				= $j( document.createElement('img') ).attr('src', srcImageBig);
		$imageBig.preload({									
				'onFinish':function(){
					$img_big_wrapper.css({ 'background':'url("'+srcImageBig+'") right no-repeat', 'width':0 });
					$img_big_wrapper.animate({ width:315 }, 1350, function(){
						$img_big_wrapper.bind('mouseout', function(){
							staffHide(this);
							$img_big_wrapper.unbind('mouseout').addClass('img_big_wrapper');
						});
					});
					$parents_li.animate({ width:315 }, 1500);			
				}				
		});
	}
	function staffHide(img_big_wrapper){
		var $img_big_wrapper	= $j(img_big_wrapper);		
		var $parents_li		= $img_big_wrapper.parents('li');
		
		$img_big_wrapper.animate({ width:0 }, 1500, function(){
			activateStaffShow();
		});
		$parents_li.animate({ width:98 }, 1150);
	}
	function deactivateStaff(){
		staffHide( $j(".img_big_wrapper") );
		$j(".staff_image_s").unbind('mouseover');
	}
	
	// -- Addithional -- 

	function var_dump(obj) {
		  var result = null;
		  for (var i in obj)
		  result += 'object' + '.' + i + ' = ' + obj[i] + '\n';
		  return result;
	}
	 
	function activateblock(){
		$j.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: '.5', 
            color: '#fff'				
        }, overlayCSS:{'z-index': 1007} }); 
	}
	
	function deactivateblock(){
		$j.unblockUI();
	}
	
	function you_are_sure(str){
		return confirm(str);
	}