var Query = window.location.hash.replace('#', '').split('/');
var origQuery = window.location.hash.replace('#', '').replace(/\/+/g, '_');
var autoOpen = false;

/* Check for open page by link */
var locationHref = window.location.href.split('#');
if (locationHref.length <= 1 && locationHref[0] != _BASE_URL && location.href.indexOf(_BASE_URL) >= 0)
	window.location = locationHref[0].replace(_BASE_URL, _BASE_URL+'#');


function SetQuery(link) {
	
	if (!autoOpen)
		if (link.length)
			Query = link.split('/');
	autoOpen = false;

	var queryVar = '#';
	for (i=0; i < Query.length; i++) {
		queryVar += Query[i];
        //alert(Query[i]);
		if (i < Query.length - 1)
			queryVar += '/';
	}

	window.location = queryVar;

}

$jquery(document).ready(function() { // On page load
	
	var ajaxSendCounter = 0;
	/* Ajax loader show or hide */
	$jquery("#loading").bind("ajaxSend", function(){
	   ajaxSendCounter ++;
	   Loader(true, this);
	}).bind("ajaxComplete", function(){
	   ajaxSendCounter --;
	   if (ajaxSendCounter == 0)
		Loader(false, this);
	});

	/* Ajax error show messgae */
	$jquery('#ajaxError').ajaxError(function (event, request, settings) {
		$jquery(this).show().fadeOut(5000);
	});
	
	IntroPrepare();

	HomeMenuLinkConfiguration();// Main menu configurate

	$jquery('a:[class!="logo"]').live('click', function() {
        if((jQuery(this).attr('target') != '_blank') && (jQuery(this).attr('class') != 'url')){
            return false;
        }
    });


});

function Loader(action, item) {
	
	/*var centerLoader = window;
	if ($jquery('.contentBlock:visible'))
		centerLoader = $jquery('.contentBlock:visible').parents('td.level0');
	$jquery('#loading').centerInClient({container : centerLoader});*/
	
	if (action){
		$jquery('#loading').show();
		//$jquery('#loading_overlay').show();
	}else{
		$jquery('#loading').hide();
		//$jquery('#loading_overlay').hide();
    }

}

function HomeMenuLinkConfiguration() {
	
	var HomeMenuLinkOptionsVar = new  HomeMenuLinkOptions();
	HomeMenuLinkOptionsVar.AutoOpen();

	$jquery('#homeNavigationMenu a.navItem').each(function() { // set navigation text in center
		$jquery('span', this).centerInClient({container : $jquery(this), setTopPadding : '-50'});
	});

	$jquery('#homeNavigationMenu tr > td').each(function(i) {
		$jquery(this).css('z-index', 10 + i);
		var box = $jquery(this);
		var link = $jquery(this).find('a.navItem');
		var content = $jquery(this).find('div.contentBlock');

		$jquery(link).click(function(e) { // Main menu click function
			HomeMenuLinkOptionsVar.prepare(box, $jquery(this).attr('href'));
			return false;
		});
	});

}


function HomeMenuLinkOptions(box, link) { // Main menu open/close action
	
	this.prepare = function(box, link) {
		this.Close(box, link);
	}

	this.Open = function(box, link) {
		
		if (link) {
			$jquery(box).show();
			SetQuery(link.replace(_BASE_URL, ''));
			$jquery(box).find('div.contentBlock').html('');
			$jquery.ajax({
				type: "post",
				url: link,
				success: function(msg){
					var speedOpen;
					if (msg.length < 2500)
						speedOpen = 700;
					else if (msg.length > 2500 && msg.length < 7000)
						speedOpen = 1000;
					else if (msg.length > 7000 && msg.length < 12000)
						speedOpen = 2000;
					else
						speedOpen = 2500;
						  
					$jquery(box).css('overflow', 'hidden').find('div.contentBlock').html(msg).animate({'height' : '755px'}, 10, function() {

						var height = ($jquery(this).children().height() < 700) ? 700 : $jquery(this).children().height();
						$jquery(this).animate({'height' : height + 'px'}, 2000, function() {
							$jquery(this).css('height', 'auto');
						});
						
					}).show();
					$jquery(box).css('overflow', 'hidden');
					
					$jquery(box).find('a.navItem').hide(100);
					OnMenuOpen();
                    var tdSize = 640;
                    if($jquery(box).attr('id') == 'klienti_block') tdSize=740;
					$jquery(box).animate({width: tdSize}, 1000, function() {
						//$jquery(this).children('div.contentBlock').slideDown(500);
						$jquery('.mainNavLayout').hide(1);
						if ($jquery(this).addClass('openBox').next().css('display') == 'none') {
							$jquery(this).addClass('openBox').next().next().addClass('openBoxSecond');
						} else {
							$jquery(this).addClass('openBox').next().addClass('openBoxSecond');
						}
                        $jquery('.contentBlock').css({'width' : '560px'});
                        $jquery('#portfolio_block .contentBlock').css({'width' : '620px'});
                        $jquery('#klienti_block .contentBlock').css({'width' : '740px'});

					});
				},
				error:function (xhr, ajaxOptions, thrownError){
                    $jquery('.mainNavLayout').hide(1);
                } 
			});
		}
	};
	
	this.Close = function(box, link) {
		var interval = false;
		$jquery('#homeNavigationMenu tr > td').each(function() {
			var closeTd = this;
			if ($jquery(closeTd).width() != '28' ) {
				$jquery('.mainNavLayout').show(1);
				
				if ($jquery(closeTd).removeClass('openBox').next().css('display') == 'none') {
					$jquery(closeTd).removeClass('openBox').next().next().removeClass('openBoxSecond');
				} else {
					$jquery(closeTd).removeClass('openBox').next().removeClass('openBoxSecond');
				}

				$jquery(closeTd).delay(1).animate({width: '28px'}, {duration: 1000});
				$jquery(closeTd).find('div.contentBlock').delay(1).slideUp(700, function() {
					$jquery(closeTd).find('a.navItem').show(100);
					$jquery(closeTd).find('div.contentBlock').html('');
				});
				
				interval = true;
			}
		});
		if (interval) {
			setTimeout(function() {
				var HomeMenuLinkOptionsVar = new  HomeMenuLinkOptions();
				HomeMenuLinkOptionsVar.Open(box, link);
			},500);
		} else
			this.Open(box, link);
	}

	this.AutoOpen = function() {
		if (Query.length) {
			for (var i = 0; i < Query.length; i++) {
				if (Query[i] != '') {
					if (i == 0) {
						try {
							autoOpen = true;
							this.Open($jquery('#'+Query[i]+'_block'), $jquery('#'+Query[i]+'_block').find('a.navItem').attr('href'));	
						}
						catch (err) {
							$jquery('#ajaxError').show().fadeOut(5000);
						}						
					}
				}
			}
		}
	}

}

function OnMenuOpen() { //Set all action when main menu was open
	setPageTitle(); // set page title
	//var stdWidth1 = 570*$jquery('.staticBlockPageSlider .widget-static-block').length;
	var stdWidth2 = 570*$jquery('.staticBlockPageSlider2 .widget-static-block').length;

    //$jquery('.staticBlockPageSlider .sliderContainer .std').css({'width' : stdWidth1 + 'px'});
    $jquery('.staticBlockPageSlider2 .sliderContainer .std').css({'width' : stdWidth2 + 'px'});

	if ($jquery('.staticBlockPageSlider').size() > 0){
		StaticBlockPageSlider(0); // Static page (main menu)
    }

    if ($jquery('.staticBlockPageSlider2').size() > 0)
		StaticBlockPageSlider2(0); // Static page (main menu)

	CategoryTopMenu();// Category prepare

	if ($jquery('.simplePageBlock').size() > 0)
		SimplePage(); // Simple page prepare
	
	if ($jquery('.caruselList').size())
		$jquery('.caruselList').caruselList();// Carusel prepare
	
	AccessoriesOpen();// Accessories type page prepare

}

function setPageTitle() { // set page title
	
	var titleSub = $jquery('.contentBlock:visible').prev('a').children('span').html();
	document.title = _BASE_TITLE + ' - ' + titleSub;

}



function StaticBlockPageSlider(level) { // Static block page


// =============================================================================
// =============================================================================
// =============================================================================
// =============================================================================
	/*	
	var theInt = null;
	var stop = 0;
	var counter = 0;
	if(theInt != null){
		theInt = null;
	}
	alert(theInt);
	$jquery('.staticBlockPageSlider .widget-static-block img').mouseover(function() {
		stop = 1;
		counter = 0;
	});	

	$jquery('.staticBlockPageSlider .widget-static-block img').mouseout(function() {
		stop = 0;
		counter = 0;
	});
	
	$jquery('.staticBlockPageSlider .nextBtn').mouseover(function() {
		stop = 1;
		counter = 0;
	});	

	$jquery('.staticBlockPageSlider .nextBtn').mouseout(function() {
		stop = 0;
		counter = 0;
	});
	
	theInterval = function(){
	clearInterval(theInt);
	
	theInt = setInterval(function(){
			$jquery('.staticBlockPageSlider #asd').html('value = ' + counter);
			if(counter == 4){
				if(stop == 0){
					$jquery('.staticBlockPageSlider .navigation .nextBtn').trigger('click');
				}
				counter = 0;
			}
			if(stop == 0) counter++;
		}, 1000);
	};


	jQuery('.sliderContainer .std p').each(function(){
		if(jQuery(this).html() == ''){
			jQuery(this).remove();
		}
	});
	theInterval();
*/
// =============================================================================
// =============================================================================
// =============================================================================
// =============================================================================
	var activeSlide = 0;
	var activeSlideNext = 0;
	var blockSize = 0;
	var blockWidth = 0;
	var pub = {};
	var firstImg = jQuery('.widget-static-block:first-child img').attr('src');
	var move = 0;
	pub.level = level;
	jQuery('#portfolioNext').attr('src', firstImg);
	pub.ShowNext = function() {
		if (activeSlide == blockSize - 1)
			activeSlideNext = 0;
		else
			activeSlideNext++;
		pub.Animation();
	}

	pub.ShowPrev = function() {
		if (activeSlide == 0)
			activeSlideNext = blockSize - 1;
		else
			activeSlideNext--;
		pub.Animation();
	}

	pub.Animation = function(level) {

		$jquery('.contentBlock').css({'width' : 620 + 'px', 'overflow' : 'hidden', 'margin' : '0 auto'}); // fix bug in IE, set Width 845px
		$jquery('.contentBlock .ajaxDataBlock').css({'overflow' : 'hidden'});
		move = (blockWidth * activeSlideNext);
		var activeHeight;
		var oldActiveSlide = activeSlide;
		activeSlide = activeSlideNext;

		if (pub.level) {
			if (Query[1])
				SetQuery(Query[0] + '/' + Query[1] + '/block=' + activeSlide); // for level = 1
		} else
			SetQuery(Query[0]+'/block=' + activeSlide); // for level = 0

		$jquery('.staticBlockPageSlider .navigation .pager .active').removeClass('active');
		$jquery('.staticBlockPageSlider .navigation .pager .pItem').each(function(i) {
			if (i == activeSlide)
				$jquery(this).addClass('active');
		})
		$jquery('.staticBlockPageSlider .widget-static-block').each(function(i) {
			if (i == activeSlide)
				activeHeight = $jquery(this).height();
		})
		/*
		if (activeHeight < 100)
			activeHeight = 540;

		if (pub.level)
			var heightPlus = 80;
		else
			var heightPlus = 200;
		*/
		$jquery('.staticBlockPageSlider .sliderContainer').animate({'margin-left' : '-' + move + 'px', height : activeHeight + 'px'}, 1000);
		//$jquery('.staticBlockPageSlider').parent().animate({height : (activeHeight + heightPlus) + 'px'}, 1000);
	
		var maxW = blockWidth * (blockSize - 1);

		if(move == maxW){
			jQuery('#portfolioNext').show();
			jQuery('#portfolioNext').animate({right : '0px'}, 1000);
		}else{
			jQuery('#portfolioNext').css('right','-' + (maxW - move) + 'px');
		}

		jQuery('#image_title').text($jquery('.staticBlockPageSlider .widget-static-block:eq(' + (activeSlide) + ')').find('img').attr('title')).animate({opacity:0}, 0, function(){ jQuery('#image_title').animate({opacity:1},1000)});

	}

	if ($jquery('.staticBlockPageSlider').size()) {
		$jquery('.staticBlockPageSlider .widget-static-block').each(function(i) {
			if (i == 0) {
				$jquery(this).show();
				blockWidth = $jquery(this).outerWidth();
			}
		});

		blockSize = $jquery('.staticBlockPageSlider .widget-static-block').size();
		for (i = 0; i < blockSize; i++) {
			var active = (i == 0) ? 'active' : '';
			$jquery('.staticBlockPageSlider .navigation .pager').append('<a class="pItem ' + active + '"></a>');
		}
        $jquery('.staticBlockPageSlider .navigation .pager').append('<div class="clr"></div>');

		$jquery('.staticBlockPageSlider .navigation .prevBtn').click(function() {
			pub.ShowPrev();
			return false;
		});

		$jquery('.staticBlockPageSlider .navigation .nextBtn').click(function() {
			pub.ShowNext();
			return false;
		});

		$jquery('.staticBlockPageSlider .navigation .pager .pItem').each(function(i) {
			$jquery(this).click(function() {
				activeSlideNext = i;
				pub.Animation();
				return false;
			});
		})

		setTimeout(function() {
			if (pub.level) {

				if (Query[2]) { // Auto load if isset #page=
					var autoQuery = Query[2].split('=');
					if (autoQuery[0] == 'block') {
						activeSlideNext = autoQuery[1];
						pub.Animation();
						return false;
					}
				} else { // in not set #page= run 0
					activeSlideNext = 0;
					pub.Animation();
				}

			} else {
				if (Query[1]) { // Auto load if isset #page=
					var autoQuery = Query[1].split('=');
					if (autoQuery[0] == 'block') {
						activeSlideNext = autoQuery[1];
						pub.Animation();
						return false;
					}
				} else { // in not set #page= run 0
					activeSlideNext = 0;
					pub.Animation();
					return false;
				}
			}
			
		}, 500);

	}

}


function StaticBlockPageSlider2(level) { // Static block page
	var activeSlide = 0;
	var activeSlideNext = 0;
	var blockSize = 0;
	var blockWidth = 0;
	var pub = {};
	pub.level = level;

	pub.ShowNext = function() {
		if (activeSlide == blockSize - 1)
			activeSlideNext = 0;
		else
			activeSlideNext++;
		pub.Animation();
	}

	pub.ShowPrev = function() {
		if (activeSlide == 0)
			activeSlideNext = blockSize - 1;
		else
			activeSlideNext--;
		pub.Animation();
	}

	pub.Animation = function(level) {

		$jquery('.contentBlock').css({'width' : 555 + 'px', 'overflow' : 'hidden', 'margin' : '0 auto'}); // fix bug in IE, set Width 845px
		$jquery('.contentBlock .ajaxDataBlock').css({'overflow' : 'hidden'});
		var move = (blockWidth * activeSlideNext);
		var activeHeight;
		activeSlide = activeSlideNext;

		if (pub.level) {
			if (Query[1])
				SetQuery(Query[0] + '/' + Query[1] + '/block=' + activeSlide); // for level = 1
		} else
			SetQuery(Query[0]+'/block=' + activeSlide); // for level = 0

		$jquery('.staticBlockPageSlider2 .navigation .pager .active').removeClass('active');
		$jquery('.staticBlockPageSlider2 .navigation .pager .pItem').each(function(i) {
			if (i == activeSlide)
				$jquery(this).addClass('active');
		})
		$jquery('.staticBlockPageSlider2 .widget-static-block').each(function(i) {
			if (i == activeSlide)
				activeHeight = $jquery(this).height();
		})

		if (activeHeight < 100)
			activeHeight = 540;

		if (pub.level)
			var heightPlus = 80;
		else
			var heightPlus = 200;

		$jquery('.staticBlockPageSlider2 .sliderContainer').animate({'margin-left' : '-' + move + 'px', height : activeHeight + 'px'}, 1000);
		$jquery('.staticBlockPageSlider2').parent().animate({height : (activeHeight + heightPlus) + 'px'}, 1000);

	}

	if ($jquery('.staticBlockPageSlider2').size()) {

		$jquery('.staticBlockPageSlider2 .widget-static-block').each(function(i) {
			if (i == 0) {
				$jquery(this).show();
				blockWidth = $jquery(this).width();
			}
		});

		blockSize = $jquery('.staticBlockPageSlider2 .widget-static-block').size();
		for (i = 0; i < blockSize; i++) {
			var active = (i == 0) ? 'active' : '';
			$jquery('.staticBlockPageSlider2 .navigation .pager').append('<a class="pItem ' + active + '">' + (i + 1) + '</a>');
		}
        //$jquery('.staticBlockPageSlider2 .navigation .pager').append('<div class="clr"></div>');

		$jquery('.staticBlockPageSlider2 .navigation .prevBtn').click(function() {
			pub.ShowPrev();
			return false;
		});

		$jquery('.staticBlockPageSlider2 .navigation .nextBtn').click(function() {
			pub.ShowNext();
			return false;
		});

		$jquery('.staticBlockPageSlider2 .navigation .pager .pItem').each(function(i) {
			$jquery(this).click(function() {
				activeSlideNext = i;
				pub.Animation();
				return false;
			});
		})

		setTimeout(function() {
			if (pub.level) {

				if (Query[2]) { // Auto load if isset #page=
					var autoQuery = Query[2].split('=');
					if (autoQuery[0] == 'block') {
						activeSlideNext = autoQuery[1];
						pub.Animation();
						return false;
					}
				} else { // in not set #page= run 0
					activeSlideNext = 0;
					pub.Animation();
				}

			} else {
				if (Query[1]) { // Auto load if isset #page=
					var autoQuery = Query[1].split('=');
					if (autoQuery[0] == 'block') {
						activeSlideNext = autoQuery[1];
						pub.Animation();
						return false;
					}
				} else { // in not set #page= run 0
					activeSlideNext = 0;
					pub.Animation();
					return false;
				}
			}
			
		}, 500);

	}

}


function CategoryTopMenu() {
	$jquery('.topCategoryMenu .line').each(function() {
		$jquery('a:last', this).css({'background' : 'transparent', 'padding-right' : '5px'});
	});
}

$jquery.fn.caruselList = function(options) {

	var pub = {};
	var active = 0;
	var main = this;

	var showPlace = $jquery('.categoryProductDetailsBlock');
	var listBlock = $jquery('.categoryProductListBlock');

	var slideSpeed = 1000;

	var detailQueryActive;

	var blockImgColor, blockDescColor, blockColorColor, activeColor, oldQuery;

	pub.slideInAction = false; // Check if submenu slider in action

	pub.Animation = function() {
		
		/* show top menu active */
		$jquery('.topCategoryMenu a.active', main).removeClass('active');
		$jquery('.topCategoryMenu a:eq(' + active + ')', main).addClass('active');
		
		/* show bottom description */
		$jquery('.products-grid-description .item:visible', main).fadeOut(1000);
		$jquery('.products-grid-description .item:eq(' + active + ')', main).fadeIn(1000);
		$jquery('.products-grid-description', main).animate({'height' : ($jquery('.products-grid-description .item:eq(' + active + ')', main).height() + 40) + 'px'}, 1000);

		/* show image */
		var blockWidth = $jquery('.category-products ul.products-grid li.item:eq(0)').width();
		var move = ((blockWidth +  6)* active);
		$jquery('.category-products ul.products-grid').animate({'margin-left' : '-' + move + 'px'}, 200);
		$jquery('.category-products ul.products-grid li.item.active').delay(100).addClass('preActive').removeClass('active');
		$jquery('.category-products ul.products-grid li#listImage_' + (parseFloat(active) + 1) + '').delay(170).removeClass('preActive').addClass('active');
		
		SetQuery($jquery('.topCategoryMenu a:eq(' + active + ')', main).attr('href').replace(_BASE_URL, ''));

	}

	pub.AjaxOpen = function(ID) {

		var eqId = $jquery('.topCategoryMenu a').index($jquery('a#'+ID));
		var url =  $jquery('#listImage_' + (eqId + 1) + ' .bigImage a', main).attr('href');
				
		$jquery.ajax({
			type: "post",
			url: url,
			success: function(msg){
				listBlock.slideUp(slideSpeed);
				showPlace.html(msg).slideDown(slideSpeed);
				SetQuery(Query[0] + '/' + Query[1]);
				pub.OpenProductDetails();
			},
			error:function (xhr, ajaxOptions, thrownError){
				console.info(thrownError);
			} 
		});

	}

	pub.OpenProductDetails = function() { // Opem product details
	
		$jquery('.topProductMenu a:last').css({'background' : 'transparent', 'padding-right' : '5px'});// Prepare product menu

		$jquery('.topProductMenu a').click(function() { // Set product menu click			
			
			if (pub.slideInAction) // check if submenu slide in action, return false;
				return false;
			var linkIndex = $jquery('.topProductMenu a').index(this);
			pub.OpenProductDetailsSubMenu(linkIndex);

		});

		try {
			if (oldQuery[2]) { // prepare url for product open subdetails
				var autoQuery = oldQuery[2].split('?');
				if (autoQuery[1]) {
					detailQueryActive = $jquery('.topProductMenu a').index($jquery('#prod_'+autoQuery[1]));
				}
			}
		}catch (err){
		}

		if (detailQueryActive) { // set url for product open subdetails
			setTimeout(function() {
				pub.OpenProductDetailsSubMenu(detailQueryActive);
				detailQueryActive = 0;
			}, 1000);
		}
		pub.ColorSwitcherPrepare();

		try {
			$jquery("a.fancybox").fancybox({ // Image gallery start
				'autoDimensions'	: false,
				'showCloseButton'	: false,
				'showNavArrows'		: false,
				'titlePosition'		: 'inside',
				'titleFormat'		: formatTitle2,
				'width'				: 756,
				'height'			: 565,
				'cyclic'			: true
			});	
		}
		catch (err){
		}
		
		MagicMagnify.start(); // Image zoom start

	}

	pub.OpenProductDetailsSubMenu = function(linkIndex) { // Product details open subdetails
		
		var linkObj = $jquery('.topProductMenu a').eq(linkIndex);
		
		$jquery('.topProductMenu a.active').removeClass('active'); // remove parent active menu class
		$jquery(linkObj).addClass('active'); // set link active
		var activeUrl = $jquery(linkObj).attr('href');
		
		/* OPEN SUBPAGES ON ACCESSORIES PAGE TYPE */

		var blockOldName = '.logo';
		var blockOld = $jquery(blockOldName);
		var sliderSubPage = { // set variables
			position : blockOld.position(), // get/set old block position
			width : blockOld.width(), // get/set old block width
			animationTime : 2000, // set animation time
			opacity : 0.1 // set opacity of old block
		};

        sliderSubPage.position.left = 0;
        sliderSubPage.position.top = 0;
        sliderSubPage.position.width = 0;

		if ('productDetails_'+$jquery(linkObj).attr('href') == blockOld.attr('id'))
			return false;

		pub.slideInAction = true; // set menu slide var true

		blockOld.parents('td.level0').children('.contentBlock').css({ // set td overflow -> hidden
			'overflow' : 'hidden',
			'position' : 'relative',
			'min-height' : blockOld.parents('td.level0').height() + 'px'
		});
		
		blockOld.css({ // animate old block
			'float' : 'left',
			'position' : 'absolute',
			'left' : sliderSubPage.position.left + 'px',
			'top' : (sliderSubPage.position.top - 1) + 'px',
			'width' : sliderSubPage.width + 'px'
		})
		.animate({
			'left' : (sliderSubPage.position.left - sliderSubPage.width) + 'px', // move left
			'opacity' : sliderSubPage.opacity
		}, sliderSubPage.animationTime, function() { // remove this block
			
			$jquery(this).attr({'style' : ''}).hide(1);
			$jquery(blockOldName).parents('td.level0').children('.contentBlock').delay(100).removeAttr('style').css({ // set td overflow back -> auto
				'height' : 'auto',
				'display' : 'block'
			});

			pub.slideInAction = false; // set menu slide var false

		});
		
		$jquery('#productDetails_'+$jquery(linkObj).attr('rel')).show().css({ // animate new block
			'opacity' : 0,
			'display' : 'block',
			'float' : 'left',
			'width' : '200px',
			'position' : 'absolute',
			'left' : (sliderSubPage.position.left + sliderSubPage.width) + 'px',
			'top' : (sliderSubPage.position.top - 1) + 'px',
			'width' : sliderSubPage.width + 'px'
		})
		.animate({
			'left' : sliderSubPage.position.left + 'px', // move left
			'opacity' : 1
		}, sliderSubPage.animationTime, function() {
			$jquery(this).attr({'style' : ''}); // remove all addeded styles
		});

		/* / OPEN SUBPAGES ON ACCESSORIES PAGE TYPE */
		
		SetQuery(Query[0] + '/' + Query[1] + '/'+ activeUrl.replace(_BASE_URL, ''));

		/* color block by center */
		try {
			blockColorColor.centerInClient({container : $jquery('.colorSwitcherColorBlock')});	
		} catch (err) {
		}		
			
	}

	pub.ColorSwitcherPrepare = function() { //Prepare colorswitcher
		
		blockImgColor = $jquery('.colorSwitcherImages');
		blockDescColor = $jquery('.colorSwitcherDesc');
		blockColorColor = $jquery('.colorSwitcherColor');
		activeColor = 1;

		if ($jquery('.colorSwitcherImages').size()) {
			
			var lastElem = $jquery('.products-grid li:last', blockImgColor).clone(); // get last image lone
			var firstElem = $jquery('.products-grid li:first', blockImgColor).clone();// get first image clone
			$jquery(lastElem).prependTo('.colorSwitcherImages .products-grid').attr('id', 'listImage_0').addClass('fake'); // copy last image first
			$jquery(firstElem).appendTo('.colorSwitcherImages .products-grid').attr('id', 'listImage_10000').addClass('fake');// copy first image last
			$jquery('.products-grid li.item', blockImgColor).each(function(i) { // change active image
				if (i == 1)
					$jquery(this).addClass('active');
				else
					$jquery(this).addClass('preActive');
			});

			//$jquery(blockDescColor).height($jquery('.item:eq(0)', blockDescColor).height()); // change description

			/* color block by center */
			blockColorColor.centerInClient({container : $jquery('.colorSwitcherColorBlock')});

			$jquery('.colorSwitcherImages .smallImage a').click(function(){ // click on image
				activeColor = $jquery('.colorSwitcherImages .item .smallImage a').index(this);
				if (activeColor != 0 && activeColor != $jquery('.colorSwitcherImages .smallImage a').size() - 1)
					pub.AnimationColorSwitcher();
			});

			$jquery('.colorSwitcherImages ul.products-grid li.item:first .smallImage a').click(function() {// set click in first cloned smallimage
				activeColor = $jquery('.colorSwitcherImages .smallImage a').size() - 2;
				pub.AnimationColorSwitcher();
			});

			$jquery('.colorSwitcherImages ul.products-grid li.item:last .smallImage a').click(function() {// set click in last cloned smallimage
				activeColor = 1;
				pub.AnimationColorSwitcher();
			});

			$jquery('.colorSwitcherColor span').click(function() {// set click in last cloned smallimage
				activeColor = $jquery('.colorSwitcherColor span').index(this) + 1;
				pub.AnimationColorSwitcher();
			});

		}

	}

	pub.AnimationColorSwitcher = function() {
		
		/* show image */
		var blockWidth = $jquery('li.item:eq(0)', blockImgColor).width();
		var move = ((blockWidth + 6) * (activeColor - 1));
		
		$jquery('ul.products-grid', blockImgColor).animate({'margin-left' : '-' + move + 'px'}, 200);
		$jquery('ul.products-grid li.item.active', blockImgColor).delay(100).addClass('preActive').removeClass('active');
		$jquery('ul.products-grid li#listImage_' + (parseFloat(activeColor)) + '', blockImgColor).delay(170).removeClass('preActive').addClass('active');

	}
	

	return this.each(function(i) {
		
		var countElem = $jquery('.category-products ul.products-grid li.item', this).size();

		$jquery('.category-products ul.products-grid li.item', this).each(function(i) { // set click in small image
			var item = i;
			$jquery('.smallImage a', this).click(function(){
				active = item;
				pub.Animation();
			});
		});

		$jquery('.category-products ul.products-grid li.item', this).each(function(i) { // set click in big image
			var item = i;
			$jquery('.bigImage a', this).click(function(){
				pub.AjaxOpen($jquery(this).attr('href').replace(_BASE_URL, '').replace(/\/+/g, '_'));
			});
		});
		
		var lastElem = $jquery('.products-grid li:last', this).clone(); // get last image lone
		var firstElem = $jquery('.products-grid li:first', this).clone();// get first image clone
		$jquery(lastElem).prependTo('.category-products .products-grid', this).attr('id', 'listImage_0').addClass('fake'); // copy last image first
		$jquery(firstElem).appendTo('.category-products .products-grid', this).attr('id', 'listImage_10000').addClass('fake');// copy first image last
		$jquery('.category-products .products-grid li.item', this).each(function(i) { // change active image
			if (i == 1)
				$jquery(this).addClass('active');
			else
				$jquery(this).addClass('preActive');
		});
		$jquery('.products-grid-description', this).height($jquery('.products-grid-description .item:eq(0)', this).height() + 40); // change description

		$jquery('.topCategoryMenu a', this).click(function(i){ // click on top menu
			active = $jquery('.topCategoryMenu a').index(this);
			listBlock.slideDown(slideSpeed);
			showPlace.slideUp(slideSpeed);
			pub.Animation();
			pub.AjaxOpen($jquery(this).attr('id'));
		});

		$jquery('.category-products ul.products-grid li.item:first .smallImage a', this).click(function() {// set click in first cloned smallimage
			active = countElem - 1;
			pub.Animation();
		});

		$jquery('.category-products ul.products-grid li.item:last .smallImage a', this).click(function() {// set click in last cloned smallimage
			active = 0;
			pub.Animation();
		});

		$jquery('.category-products .listBlockNav a.prevBtn', this).click(function() {// set click on prev button
			active = (active == 0) ? countElem - 1 : parseInt(active) - 1 ;
			pub.Animation();
		});

		$jquery('.category-products .listBlockNav a.nextBtn', this).click(function() {// set click on next button
			active = (active == countElem - 1) ? 0 : parseInt(active) + 1 ;
			pub.Animation();
		});

		if (Query[1]) { // set url for product view
			
			if ($jquery('.caruselList').size()) {
				active = $jquery('.topCategoryMenu a').index($jquery('a#'+Query[0]+'_'+Query[1]));
				oldQuery = Query;
				setTimeout(function() {
					pub.Animation();
				}, 500);
				setTimeout(function() {
					pub.AjaxOpen($jquery('a#'+Query[0]+'_'+Query[1]).attr('id'));
				}, 1000);
			}

		}

	});

}

function AccessoriesOpen() { // Open manu type accessories
	
	var main = this;
	var pub = {};
	pub.slideInAction = false; // Check if submenu slider in action
	
	$jquery('.topCategoryMenu2 a').click(function() {
		
		if (pub.slideInAction) // check if submenu slide in action, return false;
			return false;
		var active = $jquery(this);
		var index = $jquery('.topCategoryMenu2 a').index(active);
		pub.SetAjax($jquery(this).attr('id'));

	});

	pub.SetAjax = function(ID) {
		
		var active = $jquery('.topCategoryMenu2 a#'+ID);
		var index = $jquery('.topCategoryMenu2 a').index(active);
		var url = active.attr('href');

		$jquery.ajax({
			type: "post",
			url: url,
			success: function(msg){
				pub.OpenCategory(index, active, msg, url);
			},
			error:function (xhr, ajaxOptions, thrownError){
				console.info(thrownError);
			} 
		});	

	}

	pub.SetActiveMenu = function(active) {
		$jquery('.topCategoryMenu2 a.active').removeClass('active');
		active.addClass('active');
	}

	pub.SetListQuery = function(newQuery) {
		SetQuery(newQuery);
	}

	pub.OpenCategory = function(index, active, msg, url) {

		/* OPEN SUBPAGES ON ACCESSORIES PAGE TYPE */
				
		pub.slideInAction = true; // set menu slide var true
		var blockOldName = '#loadetAjaxContent';
		var blockOld = $jquery(blockOldName);
		var sliderSubPage = { // set variables
			position : blockOld.position(), // get/set old block position
			width : blockOld.width(), // get/set old block width
			animationTime : 2000, // set animation time
			opacity : 0.1 // set opacity of old block
		};
		
		blockOld.parents('td.level0').children('.contentBlock').css({ // set td overflow -> hidden
			'overflow' : 'hidden',
			'position' : 'relative',
			'height' : 'auto',
			'min-height' : '750px'
		});

		blockOld.css({ // animate old block
			'float' : 'left',
			'position' : 'absolute',
			'left' : sliderSubPage.position.left + 'px',
			'top' : (sliderSubPage.position.top - 1) + 'px',
			'width' : sliderSubPage.width + 'px'
		})
		.animate({
			'left' : (sliderSubPage.position.left - sliderSubPage.width) + 'px', // move left
			'opacity' : sliderSubPage.opacity
		}, sliderSubPage.animationTime, function() { // remove this block
			
			$jquery(this).remove();
			$jquery(blockOldName).parents('td.level0').children('.contentBlock').delay(100).removeAttr('style').css({ // set td overflow back -> auto
				'height' : 'auto',
				'display' : 'block'
			});

			/* Start some action after slide the page */
			try {
				$jquery("a.fancybox").fancybox({
					'autoDimensions'	: false,
					'showCloseButton'	: false,
					'showNavArrows'	: false,
					'titlePosition'		: 'inside',
					'titleFormat'		: formatTitle,
					'width'				: 756,
					'height'			: 565,
					'cyclic'			: true
				});
			}
			catch (err) {
			}

			pub.SetActiveMenu(active);
			pub.SetListQuery(url.replace(_BASE_URL, ''));
			pub.slideInAction = false; // set menu slide var false

		});

		$jquery('<div>' + msg + '</div>').css({ // animate new block
			'opacity' : 0,
			'float' : 'left',
			'width' : '200px',
			'position' : 'absolute',
			'left' : (sliderSubPage.position.left + sliderSubPage.width) + 'px',
			'top' : (sliderSubPage.position.top - 1) + 'px',
			'width' : sliderSubPage.width + 'px'
		}).insertAfter(blockOldName) // insert after old block
		.animate({
			'left' : sliderSubPage.position.left + 'px', // move left
			'opacity' : 1
		}, sliderSubPage.animationTime, function() {
			
			$jquery(this).attr({'style' : '', 'id' : 'loadetAjaxContent'}); // remove all addeded styles
			
			// Set conten height after slider
			$jquery('.ajaxDataBlock:first').parent().animate({height : ($jquery('#loadetAjaxContent').height() + 200) + 'px'}, 1000);

		});

		/* / OPEN SUBPAGES ON ACCESSORIES PAGE TYPE */
		
	}
	
	setTimeout(function() {
		if (Query[1]) { // prepare url for product open subdetails			
			if ($jquery('.accessoriesPage').size()) {
				pub.SetAjax(origQuery);
			}
		}
	}, 500);

}


function SimplePage() { // Simple page content
	
	var main = this;
	var pub = {};
	var slideSpeed = 1000; // slide action speed
	var newQuery;
	var autoLoad = false;
	pub.slideInAction = false; // Check if submenu slider in action

	$jquery('.simplePageMenu a:last').css({'background' : 'transparent', 'padding-right' : '5px'}); // remove last poin
	$jquery('.simplePageMenu a:first').addClass('active'); // first add active

	$jquery('.simplePageMenu a').click(function() { // menu prepare click
		
		if (pub.slideInAction) // check if submenu slide in action, return false;
			return false;
		var active = $jquery(this);
		var index = $jquery('.simplePageMenu a').index(active);
		pub.SetAjax(active.attr('id'));

	});

	$jquery('.openLink').die('click').live('click', function() { // Some link load by ajax, link class 'openLink'
		pub.LinkAjax($jquery('.simplePageMenu a.active'), $jquery(this).attr('href'), 'slide');
	});
	
	pub.LinkAjax = function(active, url, animationType) { // Get content by ajax, after click in link with class openLink (example: contact form open)

		var index = $jquery('.simplePageMenu a.active').index(active);
		try {
			$jquery.ajax({
				type: "post",
				url: url,
				success: function(msg){
					pub.Open(index, active, msg, animationType);
				},
				error:function (xhr, ajaxOptions, thrownError){
					console.info(thrownError);
				} 
			});
			return content;
		} catch (err) {}

	}

	pub.ContactFormPrepare = function() {

		//InputPrepate();
		$jquery('#contactForm').die('submit').live('submit', function() {

			var block = $jquery(this);
			var url = block.attr('action');
			
			$jquery.ajax({
				type: "post",
				url: url,
				data: block.serialize(),
				success: function(msg){
					$jquery('.ajaxDataBlock:last').replaceWith(msg);
					//InputPrepate();
					
				},
				error:function (xhr, ajaxOptions, thrownError){
					console.info(thrownError);
				} 
			});	
			return false;
		});

	}

	pub.SetAjax = function(ID) { // get content from link
		
		var url = $jquery('a#'+ID).attr('href');
		var index = $jquery('.simplePageMenu a').index($jquery('a#'+ID));
		var active = $jquery('a#'+ID);

		$jquery.ajax({
			type: "post",
			url: url,
			success: function(msg){
				pub.Open(index, active, msg);
			},
			error:function (xhr, ajaxOptions, thrownError){
				console.info(thrownError);
			} 
		});	

	};

	pub.SetActiveMenu = function(active) { // set active menu
		$jquery('.simplePageMenu a.active').removeClass('active');
		active.addClass('active');
	};

	pub.Open = function(index, active, msg, animationType) { // open content

		pub.SetActiveMenu(active);
		if ($jquery('.simplePageBlock .listBlockText').css('display') != 'none') { // if content not empty

			if (animationType == 'slide') {

				$jquery('.simplePageBlock .listBlockText:first').slideUp(slideSpeed, function() {
					$jquery(this).html(msg).slideDown(slideSpeed, function() {
						if (autoLoad)
							Query = newQuery;
						pub.StartAfterLoad();
					});
				});

			} else {

				/* OPEN SUBPAGES ON SIMPLE PAGE TYPE */

				pub.slideInAction = true; // set menu slide var true

				var blockOldName = '.simplePageBlock .listBlockText';
				var blockOld = $jquery(blockOldName);
				var sliderSubPage = { // set variables
					position : blockOld.position(), // get/set old block position
					width : blockOld.width(), // get/set old block width
					animationTime : 2000, // set animation time
					opacity : 0.1 // set opacity of old block
				};
				
				blockOld.parents('td.level0').children('.contentBlock').css({ // set td overflow -> hidden
					'overflow' : 'hidden',
					'position' : 'relative',
					'min-height' : blockOld.parents('td.level0').height() + 'px'
				});

				blockOld.css({ // animate old block
					'float' : 'left',
					'position' : 'absolute',
					'left' : sliderSubPage.position.left + 'px',
					'top' : (sliderSubPage.position.top - 1) + 'px',
					'width' : sliderSubPage.width + 'px'
				})
				.animate({
					'left' : (sliderSubPage.position.left - sliderSubPage.width) + 'px', // move left
					'opacity' : sliderSubPage.opacity
				}, sliderSubPage.animationTime, function() { // remove this block
					
					$jquery(this).remove();
					$jquery(blockOldName).parents('td.level0').children('.contentBlock').delay(100).removeAttr('style').css({ // set td overflow back -> auto
						'height' : 'auto',
						'display' : 'block'
					});
					// Start some action after slide the page
					if (autoLoad)
						Query = newQuery;
					pub.StartAfterLoad();
					pub.slideInAction = false; // set menu slide var false

				});

				$jquery('<div class="listBlockText">' + msg + '</div>').css({ // animate new block
					'opacity' : 0,
					'float' : 'left',
					'width' : '200px',
					'position' : 'absolute',
					'left' : (sliderSubPage.position.left + sliderSubPage.width) + 'px',
					'top' : (sliderSubPage.position.top - 1) + 'px',
					'width' : sliderSubPage.width + 'px'
				}).insertAfter(blockOldName) // insert after old block
				.animate({
					'left' : sliderSubPage.position.left + 'px', // move left
					'opacity' : 1
				}, sliderSubPage.animationTime, function() {
					$jquery(this).attr('style', ''); // remove all addeded styles
				});

				/* / OPEN SUBPAGES ON SIMPLE PAGE TYPE */

			}

		} else // if empty
			$jquery('.simplePageBlock .listBlockText').html(msg).slideDown(slideSpeed, function() {
				alert('Auto load, need check row:859');
				if (autoLoad)
					Query = newQuery;
				pub.StartAfterLoad();
			});
			
		//SetQuery($jquery('.simplePageMenu a').eq(index).attr('href').replace(_BASE_URL, '')); // set link
		
	}

	pub.SetListQuery = function(queryNew) {
		try {
			SetQuery(Query[0] + queryNew);	
		}
		catch (err) {
		}		
	}

	pub.StartAfterLoad = function() {

		//Query = newQuery;
		StaticBlockPageSlider(1);
		StaticBlockPageSlider2(1);
		if ($jquery('.designerPage').size())// if is open designer page that start this function
			designerPagePrepare();
		pub.ContactFormPrepare();

	}

	setTimeout(function() {
		if (Query[1]) { // prepare url for page open		
			if ($jquery('.simplePageBlock:visible') && ($jquery('#'+Query[0]+'_'+Query[1]+':visible').size() || $jquery('#'+Query[0]+'_'+Query[1]+'_'+Query[2]+':visible').size())) {
				newQuery = Query;
				autoLoad = true;
				if ($jquery('#'+Query[0]+'_'+Query[1]+'_'+Query[2]+':visible').size())
					pub.SetAjax(Query[0]+'_'+Query[1]+'_'+Query[2]);
				else
					pub.SetAjax(Query[0]+'_'+Query[1]);
			}
		} else {		
			if (Query[0] == 'press')
				pub.SetAjax(Query[0]+'_news');
		}
	}, 500);

}

function designerPagePrepare() {
	
	var block = $jquery('.designerPage');
	var pub = {};
	var slideSpeed = 1000; // slid action speed
	pub.slideInAction = false; // Check if submenu slider in action

	$jquery('.topCategoryMenu .line', block).each(function() {
		$jquery('a:last', this).css({'background' : 'transparent', 'padding-right' : '5px'});
	});	
	
	$jquery('.topCategoryMenu a', block).click(function() {// Click on top menu
		
		if (pub.slideInAction) // check if submenu slide in action, return false;
			return false;
		var active = $jquery(this);
		pub.SetAjax(active.attr('id'));

	});

	$jquery('.designerList .category-products li', block).each(function(i) { // Click on image or title		
		var box = this;
		$jquery('a', box).click(function() {
			pub.SetAjax($jquery(this).attr('href').replace(_BASE_URL, '').replace(/\/+/g, '_'));
			return false;
		});
	});

	pub.SetAjax = function(ID) { // get content from link
		
		var url = $jquery('.topCategoryMenu a#'+ID, block).attr('href');
		var active = $jquery('.topCategoryMenu a#'+ID, block);
		var index = $jquery('.topCategoryMenu a', block).index(active);
		
		$jquery.ajax({
			type: "post",
			url: url,
			success: function(msg){
				pub.Open(index, active, msg, url);
			},
			error:function (xhr, ajaxOptions, thrownError){
				console.info(thrownError);
			} 
		});	

	};

	pub.SetActiveMenu = function(active) { // set active menu
		$jquery('.topCategoryMenu a.active', block).removeClass('active');
		active.addClass('active');
	};

	pub.Open = function(index, active, msg, url) { // open content

		pub.SetActiveMenu(active);
		/* OPEN SUBPAGES ON SIMPLE PAGE TYPE */
		
		pub.slideInAction = true; // set menu slide var true
		
		var blockOldName = '.designerPage .designerList:first';
		var blockOld = $jquery(blockOldName);
		var sliderSubPage = { // set variables
			position : blockOld.position(), // get/set old block position
			width : blockOld.width(), // get/set old block width
			animationTime : 2000, // set animation time
			opacity : 0.1 // set opacity of old block
		};
		
		blockOld.parents('td.level0').children('.contentBlock').css({ // set td overflow -> hidden
			'overflow' : 'hidden',
			'position' : 'relative',
			'min-height' : blockOld.parents('td.level0').height() + 'px'
		});

		blockOld.css({ // animate old block
			'float' : 'left',
			'position' : 'absolute',
			'left' : sliderSubPage.position.left + 'px',
			'top' : (sliderSubPage.position.top - 1) + 'px',
			'width' : sliderSubPage.width + 'px'
		})
		.animate({
			'left' : (sliderSubPage.position.left - sliderSubPage.width) + 'px', // move left
			'opacity' : sliderSubPage.opacity
		}, sliderSubPage.animationTime, function() { // remove this block
			
			/* Start some action after slide the page */
			$jquery(this).remove();
			$jquery(blockOldName).parents('td.level0').children('.contentBlock').delay(100).removeAttr('style').css({ // set td overflow back -> auto
				'height' : 'auto',
				'display' : 'block'
			});

			pub.slideInAction = false; // set menu slide var false

		});

		$jquery('<div class="designerList">' + msg + '</div>').css({ // animate new block
			'opacity' : 0,
			'float' : 'left',
			'width' : '200px',
			'position' : 'absolute',
			'left' : (sliderSubPage.position.left + sliderSubPage.width) + 'px',
			'top' : (sliderSubPage.position.top - 1) + 'px',
			'width' : sliderSubPage.width + 'px'
		}).insertAfter(blockOldName) // insert after old block
		.animate({
			'left' : sliderSubPage.position.left + 'px', // move left
			'opacity' : 1
		}, sliderSubPage.animationTime, function() {
			$jquery(this).attr('style', ''); // remove all addeded styles
		});

		/* / OPEN SUBPAGES ON SIMPLE PAGE TYPE */		
		pub.SetListQuery(url.replace(_BASE_URL, '')); // set link
		
	}

	pub.SetListQuery = function(newQuery) {
		SetQuery(newQuery);
	}

	setTimeout(function() {
		if (Query[2]) { // prepare url for page open		
			if ($jquery('.designerPage:visible')) {
				autoLoad = true;
				pub.SetAjax(origQuery);
			}
		}
	}, 500);

}

/* position center */
$jquery.fn.centerInClient = function(options) {
    var opt = {forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null,
                setLeft: true,
                setLeftPadding: 0,
                setTop: true,
                setTopPadding: 0
              };
    $jquery.extend(opt, options);
   
    return this.each(function(i) {
        var el = $jquery(this);
        var jWin = $jquery(opt.container);
        var isWin = opt.container == window;

        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        el.css("position", "absolute");

        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        if (opt.setLeft)
			el.css("left", x + jWin.scrollLeft() + opt.setLeftPadding);
        if (opt.setTop)
			el.css("top", y + jWin.scrollTop() + opt.setTopPadding);

        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}

function setLocationAjaxSelect(url, content) { //
	
	var pub = {};
	var slideSpeed = 1000; // slid action speed

	$jquery.ajax({
		type: "post",
		url: url,
		success: function(msg){					
			pub.Open(msg);
		},
		error:function (xhr, ajaxOptions, thrownError){
			console.info(thrownError);
		} 
	});	

	pub.Open = function(msg) {
		
		$jquery(content).slideUp(slideSpeed, function() { 
			$jquery(this).html(msg).slideDown(slideSpeed);
		});

	}

}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
	var text, nav;
	
	text = '<div class="fancy-text-block">' + $jquery('#fancySlider_' + currentIndex).html() + '</div>';
	
	nav = '<div class="fancy-nav">';
	for (i = 0; i < currentArray.length; i++) {
		if (i == currentIndex)
			nav += '<span class="current">' + (i + 1) + '</span>';
		else
			nav += '<span>' + (i + 1) + '</span>';
	}
	nav += '</div>';
	nav += '<div class="fancy-arrow"><div class="prev" onclick="$jquery.fancybox.prev()"></div><div class="next" onclick="$jquery.fancybox.next()"></div></div>';
	
	return '<div id="tip7-title">' + text + nav + '</div>';
}

function formatTitle2(title, currentArray, currentIndex, currentOpts) {
	var text, nav;
	
	nav = '<div class="fancy-nav" style="display:none;">';
	for (i = 0; i < currentArray.length; i++) {
		if (i == currentIndex)
			nav += '<span class="current">' + (i + 1) + '</span>';
		else
			nav += '<span>' + (i + 1) + '</span>';
	}
	nav += '</div>';
	nav += '<div class="fancy-arrow"><div class="prev" onclick="$jquery.fancybox.prev()"></div><div class="next" onclick="$jquery.fancybox.next()"></div></div>';
	
	return '<div id="tip7-title">' + nav + '</div>';
}

function InputPrepate() {
	
	/* -------- FOR INPUT TITLE TO VALUE ------------------- */
	$jquery('input[type=text][title!=""]').each(function() {
		if ($jquery.trim($jquery(this).val()) == '') $jquery(this).val($jquery(this).attr('title'));
		if ($jquery(this).val() == $jquery(this).attr('title')) $jquery(this).addClass('exampleText');
	}).focus(switchText).blur(switchText);
	/* -------- END FOR INPUT TITLE TO VALUE ------------------- */
	/* -------- FOR TEXTAREA TITLE TO VALUE ------------------- */
	$jquery('textarea[title!=""]').each(function() {
		if ($jquery.trim($jquery(this).val()) == '') $jquery(this).val($jquery(this).attr('title'));
		if ($jquery(this).val() == $jquery(this).attr('title')) $jquery(this).addClass('exampleText');
	}).focus(switchText).blur(switchText);
	/* -------- END FOR TEXTAREA TITLE TO VALUE ------------------- */
	
}

function switchText(){
	
	if ($jquery(this).val() == $jquery(this).attr('title'))
		$jquery(this).val('').removeClass('exampleText');
	else if ($jquery.trim($jquery(this).val()) == '')
		$jquery(this).addClass('exampleText').val($jquery(this).attr('title'));
		
}

function IntroPrepare() { // Intro after page login
	
	var position = $jquery('#homeNavigationMenu td:first').position();
	var windowSize = $jquery(window).width();
	
	$jquery('#introFirstBlock .leftSide').css({'width' : position.left + 'px'});
	$jquery('#introFirstBlock .rightSide').css({'left' : (position.left + 10) + 'px', 'width' : (windowSize - position.left) + 'px'});
	$jquery('#introFirstBlock .text').css({'left' : (position.left + 10) + 'px'});
		
	try
	{
		
		if (Query[0] == '' || !Query[0]) {
			
			$jquery('.mainConteiner').find('a').animate({'opacity' : '0'}, 10);
	
			$jquery('#introFirstBlock .leftSide').delay(3000)
			.animate({
				'width' : '40%'
			}, 4000)
			.animate({
				'width' : '0',
				'opacity' : 0
			}, 3000);

			
			$jquery('#introFirstBlock .rightSide').delay(3000)
			.animate({
				'width' : '40%',
				'left' : '60%'
			}, 4000)
			.animate({
				'width' : '0',
				'opacity' : 0,
				'left' : '100%'
			}, 3000);

			$jquery('#introFirstBlock .text')
			.animate({
				'left' : '120px'
			}, 3000)
			.animate({
				'left' : '10px',
				'opacity' : 0
			}, 3000);

			$jquery('.mainConteiner')
			.find('a').delay(5000).animate({'opacity' : '1'}, 2000);

		} else
			$jquery('#introFirstBlock').remove();

	}
	catch (err) {
		
		$jquery('#introFirstBlock').remove();

	};

}
                                                                    
