$nym=jQuery.noConflict();



// CLEAR FORM
$nym(document).ready(function(){

	$nym('.js-clear').click(
	function(event){ 
		$nym(this).parents('form').reset(); 
		
		}
	);

});
//



// FORM AUTOVALUES
$nym(document).ready(function(){

	function populateElement(selector, defvalue) {
		$nym(selector).focus(function() {
			if ($nym(selector).val() == 'Website') {
				$nym(selector).val('http://');
			} else if ($nym(selector).val() == defvalue) {
				$nym(selector).val('');
			}
		});

		$nym(selector).blur(function() {
				if ($nym.trim($nym(selector).val()) == '') {
						$nym(selector).val(defvalue);
				}
		});
	};

	$nym('form').find('input[type="text"], input[type="password"], textarea').each(function() {
				populateElement($nym(this), $nym(this).val());
			}
	);

});
//

// FORM SUBMIT + VALIDATE
$nym(document).ready(function(){
	function validateNoempty(text) {
		if (!text || text.length < 2) { return false;	}

		return true;
	}

	function validateText(text) {
		if (!validateNoempty(text)) { return false; }

		var re_text = /[^A-Za-z0-9\s!@#$nym%^&()_+-=}{';":.,><]/;
		if (text.match(re_text) != null ) { return false; }
		return true;
	}

	function validateEmail(email) {
		if (!validateNoempty(email)) { return false; }

		var splitted = email.match("^(.+)@(.+)$nym");
		if (splitted == null) return false;
		if (splitted[1] != null ) {
			var regexp_user=/^\"?[\w-_\.]*\"?$nym/;
			if (splitted[1].match(regexp_user) == null) { return false; }
		}

		if(splitted[2] != null) {
			var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$nym/;
			if (splitted[2].match(regexp_domain) == null) {
				var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$nym/;
				if (splitted[2].match(regexp_ip) == null) { return false; }
			}
			return true;
		}
		return false;
	}

	$nym('.js-proceed').click( function(event) {
			event.preventDefault();
			error = false;

			$nym(this).parents('form').children('fieldset').children('input[type="text"], textarea').each( function() {
				if ($nym(this).hasClass('v-noempty')) {
					if (!validateNoempty($nym(this).val())) {
						$nym(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}

				} else if ($nym(this).hasClass('v-text')) {
					if (!validateText($nym(this).val())) {
						$nym(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 );
						
						error = true;
					}
				} else if ($nym(this).hasClass('v-mail')) {
					if (!validateEmail($nym(this).val())) {
						$nym(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 );
						error = true;
					}
				}
			});

			if (!error) {
				//var node = $nym(this).parents('.js-hidebox');
				//node.slideUp('slow');
				//loadnote($nym(this));
				$nym(this).parents('form').submit();
			}

			//alert( (error)?'error' : 'no' ) ;
			return false;
		}
	);

	var _char_count = 500;

	$nym('textarea').keydown( function() {
			var node = $nym(this).parents('form').children('.w-left').
												 children('.w-action').children('.js-count-char').children('em');

			if ($nym(this).val().length >= _char_count) {
				$nym(this).val( $nym(this).val().substr(0, _char_count) );
			}

			node.html( _char_count - $nym(this).val().length );

		}
	);

});
//

// TOP MENU
$nym(document).ready(function(){

	$nym('ul.js-automenu').children('li').hover(
		function() {
			$nym(this).children('ul').show('fast');
		},
		function() {
			$nym(this).children('ul').hide('fast');
		}
	);

});
//

// ADD COMMENT ON PICTURE
$nym(document).ready(function(){
	$nym('a.js-add-comment').click( function(event) {
			//var node = $nym(this).parents('.x-post').next('.x-comment').children('.f-add-comment'); // common
			var node = $nym(this).parents('.x-post').children('.x-comment').children('.f-add-comment'); // custom

			var tarea = node.children('form').children('.w-right').children('.js-ta-comm')

			var ax = 'js-add-comment js-img-id-';
			var k = $nym(this).attr('class');
			k = '{img}' + k.substr(ax.length, 255) + '{/img}';

			tarea.val( tarea.val() + k );

			if (node.css('display') == 'none') {
				node.slideDown('fast');
			}
		}
	);

});
//







/*


var enableimg=function(objects)
{  


	objects.each
	(
			function(i,val)
			{	
			
			
				var i=$nym(this).find('span.post-picture');
				
				
							o = {
									id : i.attr('id'),
									cl : i.attr('class'),
									ttl : i.attr('title'),
									src : i.attr('source'),
									alt : i.attr('alt')
								}
				
				var img='<img src="'+o.src+'" id="'+o.id+'" class="'+o.cl+'" alt="'+o.alt+'" title="'+o.ttl+'"  />';
				
			
				$nym(this).append(img);
			
			}
		
	);
	
}
 	

*/




var enableimg=function(objects)
{  


	objects.each
	(
			function(i,val)
			{	
			
			
				var i=$nym(this).find('span.post-picture');
				
				
							o = {
									id : i.attr('id'),
									cl : i.attr('class'),
									ttl : i.attr('title'),
									src : i.attr('source'),
									alt : i.attr('alt')
								}
				
				var img='<img src="'+o.src+'" id="'+o.id+'" class="'+o.cl+'" alt="'+o.alt+'" title="'+o.ttl+'"  />';
			
				var destination=$nym(this);
				
				var container=$nym(this).parents('.img-holder');
				
				loadimg(img,destination,container);
			
			}
		
	);
	
}
 	






var loadimg=function(img,dest,cont)
{   
	
	$nym(cont).addClass('loading');
	$nym(cont).addClass('fade15');
	
	$nym(img).load
	(		
		function()
		{
			$nym(dest).append( $nym(this) );
			$nym(cont).removeClass('loading');
			$nym(cont).removeClass('fade15');
		}
	);	
}





/*makes first image from the post*/
$nym(document).ready(function() {

check=$nym('.post');
if(check.length>0)
{






	check.each
	(
			function()
			{	
					var cont=$nym(this).children('.post-container').children('.post-content');
			
					first_img=cont.find('img').css('display','none');
					img_title_container=cont.parents('.post').children('.post-title').children('.post-title-i').children('.pt-open');
					img_title_container.prepend(first_img.css('display','block'));
					
					
					first_piece=cont.find('.first-piece').html();
					first_piece_container=$nym(this).find('.b-post-title-scroll');
					first_piece_container.html(first_piece);
					cont.find('.first-piece').html('');
					//first_piece_container.prepend(first_piece.css('display','block'));
					
			}
		
	);





}


	

	

	img=$nym('.x-intro-t').find('img').css('display','none');
	noder=$nym('.intro-img');
	noder.prepend(img.css('display','block'));
	


});
//













// SHOW post
$nym(document).ready
(
 
 function(){
	$nym('a.nym-open-post,a.open-post').click( function(event) 
		{
			
			
			var node = $nym(this).parents('.post').children('.post-container');
			var nodeshow = $nym(this).parents('.post-title').children('.x-open');
			var nodeclose = $nym(this).parents('.post-title').children('.x-close');
			var scroller= $nym(this).parents('.post').children('.post-container').find('.b-com-scroll');
			
			var imgs=$nym(this).parents('.post').children('.post-container').children('.post-content').find('.nym-img-holder');
			
			
			

			
			if(node.css('display') == 'none')
			{
				nodeshow.css("display","none");
				nodeclose.css("display","block");
				node.animate({height:'show',opacity:'show'}, 'slow');
				apply_scroller(scroller);
				enableimg(imgs);
				
			}
			else
			{
			
				node.animate({height:'hide',opacity:'hide'}, 'slow');
				nodeshow.css("display","block");
				nodeclose.css("display","none");

			}
			
			

					var obj=$nym(this).parents('.post');
					var goto='.post-title';	
	
					$nym.scrollTo( obj.find(goto), 1000 );

			
			
		}
	);

  }
);
//






//INITIATE SHOW POST

$nym(document).ready
(
 function() 
 {

setTimeout( 
 function(){


			var count=$nym('.post').length;

			var node=$nym('.post-container');
			
			var nodeshow = $nym('.x-open');
			var nodehide = $nym('.x-close');
			
			var imgs=$nym('.post').children('.post-container').children('.post-content').find('.nym-img-holder');
			
			if(count<2)
			{

				node.animate({height:'show',opacity:'show'}, 'slow');
				nodeshow.css("display","none");
				nodehide.css("display","block");
				apply_scroller($nym('.b-com-scroll'));
				enableimg(imgs);
			}
			

  }
  ,300);
 }
);
//






// SHOW ADD COMMENT BOX
$nym(document).ready
(
 function(){
	$nym('.add-comment').click( function(event) 
		{			
			var node = $nym(this).parents('.post-container').children('.add-commentbox');
			//var nodeview = $nym(this).parents('.b-com-add').children('.js-view');
			//var nodehide = $nym(this).parents('.b-com-add').children('.js-hide');
			
			//var node = $nym(".b-com-viewer"); // custom
			
			if(node.css('display') == 'none')
			{
				
				node.animate({height:'show',opacity:'show'}, 'slow');
				//nodeview.css("display","none");
				//nodehide.css("display","block");
				
					var obj=$nym(this).parents('.post-container').children('.comment-box');
					$nym.scrollTo( obj, 1000 );

			}
			else
			{
			
				node.animate({height:'hide',opacity:'hide'}, 'slow');
				//nodeview.css("display","block");
				//nodehide.css("display","none");
			}
			
			

			
		}
	);

  }
);
//








// SHOW ADD COMMENT BOX w/o animation
$nym(document).ready
(
 function(){
	$nym('.js-add-wo').click( function(event) 
		{			
			var node = $nym(this).parents('.b-post').children('.b-post-content').children('.add-commentbox');
			
			if(node.css('display') == 'none')
			{			
				node.animate({height:'show',opacity:'show'}, 'slow');	
			}
			else
			{
				node.animate({height:'hide',opacity:'hide'}, 'fast');
			}	
		}
	);

  }
);
//











// SEND TO A FRIEND BOX
$nym(document).ready
(
 function(){
	$nym('.send-to-a-friend').click( function(event) 
		{			
			var node = $nym(this).parents('.post').children('.send-to-box');
			//var nodeview = $nym(this).parents('.b-com-add').children('.js-view');
			//var nodehide = $nym(this).parents('.b-com-add').children('.js-hide');
			
			//var node = $nym(".b-com-viewer"); // custom
			
			if(node.css('display') == 'none')
			{
				
				node.animate({height:'show',opacity:'show'}, 'slow');
				//nodeview.css("display","none");
				//nodehide.css("display","block");
				
			}
			else
			{
			
				node.animate({height:'hide',opacity:'hide'}, 'slow');
				//nodeview.css("display","block");
				//nodehide.css("display","none");
			}	
		}
	);

  }
);
//








// SEND TO A FRIEND BOX w/o animation
$nym(document).ready
(
 function(){
	$nym('.js-send-wo').click( function(event) 
		{			
			var node = $nym(this).parents('.b-post').children('.b-post-content').children('.send-commentbox');
			
			if(node.css('display') == 'none')
			{			
				node.animate({height:'show',opacity:'show'}, 'slow');	
			}
			else
			{
				node.animate({height:'hide',opacity:'hide'}, 'fast');
			}	
		}
	);

  }
);
//















// SHOW COMMENTS
$nym(document).ready
(
 function(){
	$nym('a.js-show-comments').click( function(event) 
		{
			
			
			var node = $nym(this).parents('.b-com-box').children('.b-com-viewer');
			var nodeview = $nym(this).parents('.b-com-view').children('.js-view');
			var nodehide = $nym(this).parents('.b-com-view').children('.js-hide');
			
			//var node = $nym(".b-com-viewer"); // custom
			
			
			if(node.css('display') == 'none')
			{
				node.animate({height:'show',opacity:'show'}, 'slow');
				nodeview.css("display","none");
				nodehide.css("display","block");	
			
				node.children('.b-com-scroll').jScrollPane();
			
			
			}
			else
			{
			
				node.animate({height:'hide',opacity:'hide'}, 'fast');
				nodeview.css("display","block");
				nodehide.css("display","none");
			}

			
			
		}
	);

  }
);
//






// SHOW COMMENTS w/o animation
$nym(document).ready
(
 function(){
	$nym('a.js-show-comments-wo').click( function(event) 
		{
			
			
			var node = $nym(this).parents('.b-com-box').children('.b-com-viewer');
			
			if(node.css('display') == 'none')
			{
				node.animate({height:'show',opacity:'show'}, 'slow');
			}
			else
			{
				node.animate({height:'hide',opacity:'hide'}, 'fast');
			}

			
			
		}
	);

  }
);
//





// send com
var loadnote=function(button) 
		{
			
			
			var node = button.parents('.comment-box').children('.com-note');
			var nodehide = button.parents('.comment-box').children('.add-commentbox');
			
			if(node.css('display') == 'none')
			{
				node.animate({height:'show',opacity:'show'}, 'slow');
				nodehide.animate({height:'hide',opacity:'hide'}, 'slow');
			}
			
			else
			{			
				node.animate({height:'hide',opacity:'hide'}, 'slow');
				nodehide.animate({height:'show',opacity:'show'}, 'slow');
			}
			
			
		}




// send com
$nym(document).ready
(
 function(){
	$nym('a.send-com').click( function(event) 
		{
			
			
			var node = $nym(this).parents('.comment-box').children('.com-note');
			var nodehide = $nym(this).parents('.comment-box').children('.add-commentbox');
			
			if(node.css('display') == 'none')
			{
				node.animate({height:'show',opacity:'show'}, 'slow');
				nodehide.animate({height:'hide',opacity:'hide'}, 'slow');
			}
			
			else
			{			
				node.animate({height:'hide',opacity:'hide'}, 'slow');
				nodehide.animate({height:'show',opacity:'show'}, 'slow');
			}
			
			
		}
	);

  }
);
//









// SHOW SNEAK PEAK
$nym(document).ready
(
 function(){
	$nym('a.js-show-sneak-peak').click( function(event) 
		{
			
			
			var node1 = $nym(this).parents('#sneak-peak').children('#sneak-peak-content');
			var node2 = $nym(this).parents('#sneak-peak-content').children('.sp-im-con');
			var nodeview = $nym(this).parents('.sp-im-con').children('.js-view');
			var nodehide = $nym(this).parents('.sp-im-con').children('.js-hide');
					
			if(node2.css("top")!="0px")
			{
				node1.animate({height:'375px'}, 'slow');
				node2.animate({top:'0px'}, 'slow');
				nodeview.css("display","none");
				nodehide.css("display","block");
			}
			else
			{
				node1.animate({height:'110px'}, 'slow');
				node2.animate({top:'-105px'}, 'slow');	
				nodeview.css("display","block");
				nodehide.css("display","none");
			}

			
			
		}
	);

  }
);
//







// Gallery scroller right
$nym(document).ready
(
 function(){
	$nym('a.arr-r').click( function(event) 
		{
			var step=113;

			
			var node = $nym(this).parents('.sp-gallery').children('.sp-gal-holder-scroll').children('.sp-gal-holder');
			var h=node.innerWidth();
			var top=node.css("left").replace("px","");
			var topv=top*1;
			var go_to_h=topv-step;
			var fl=top/step - Math.floor(top/step); 
			
			if((h>(-go_to_h)) && fl=="0")
			{
				go_to_h=go_to_h+"px";
				node.animate({left:go_to_h}, 'slow');
			}
			
			
		}
	);

  }
);
//







// Gallery scroller left
$nym(document).ready
(
 function(){
	$nym('a.arr-l').click( function(event) 
		{
			var step=-113;

			
			var node = $nym(this).parents('.sp-gallery').children('.sp-gal-holder-scroll').children('.sp-gal-holder');
			var h=node.innerWidth();
			var top=node.css("left").replace("px","");
			var topv=top*1;
			var go_to_h=topv-step;
			
			var fl=top/step - Math.floor(top/step); 
			
			if((h>(-go_to_h)) && fl=="0")
			{
				go_to_h=go_to_h+"px";
				node.animate({left:go_to_h}, 'slow');
			}
			
			
		}
	);

  }
);
//















// ARCHIVES SCROLLER up
$nym(document).ready
(
 function(){
	$nym('a.js-arc-up').click( function(event) 
		{
			var step=36;

			
			var node = $nym(this).parents('#archives').children('.arc-holder').children('.arc-scr');
			var h=node.innerHeight();
			var top=node.css("top").replace("px","");
			var topv=top*1;
			var go_to_h=topv-step;
			
			var fl=top/step - Math.floor(top/step); 
			
			if((h>(-go_to_h)) && fl=="0")
			{
				go_to_h=go_to_h+"px";
				node.animate({top:go_to_h}, 'slow');
			}
			
			
		}
	);

  }
);
//









// ARCHIVES SCROLLER down
$nym(document).ready
(
 function(){
	$nym('a.js-arc-down').click( function(event) 
		{
			var step=36;

			
			var node = $nym(this).parents('#archives').children('.arc-holder').children('.arc-scr');
			var h=node.innerHeight();
			var top=node.css("top").replace("px","");
			var topv=top*1;
			var fl=top/step - Math.floor(top/step); 
			var go_to_h=topv+step;
			if(top<0 && fl=="0")
			{
				go_to_h=go_to_h+"px";
				node.animate({top:go_to_h}, 'slow');
			}
			
			
		}
	);

  }
);
//

























// COMMENTS BLOCK
$nym(document).ready(function(){

	$nym('.js-hide').click( function(event) {
			event.preventDefault();
			$nym(this).parents('.js-hidebox').slideUp('fast');
		}
	);

	$nym('a[href="#js-add-comment"]').click( function(event) {
			event.preventDefault();

			var node = $nym(this).parents('.x-comment').children('.f-add-comment');
			node.slideToggle('fast');
		}
	);

	$nym('a[href="#js-send-mail"]').click( function(event) {
			event.preventDefault();

			var node = $nym(this).parents('.x-comment').children('.f-send-to-friend');
			node.slideToggle('fast');
		}
	);

});
//

// COMMENTS SCROLLER
$nym(document).ready(function(){
	var scroll_inc, scroll_offs, scroll_speed, scroll_busy;

	scroll_busy = false;
	scroll_inc = 28; /* line-height */
	scroll_speed = 333;

	//var debug = document.getElementById('debug');
	//debug.innerHTML = scroll_node.css('top');

	$nym('a.js-scrolldown').click(function(event) {
			event.preventDefault();
			if (scroll_busy) { return; }

			var scroll_offs = $nym('.x-comment .w-scroll').height() - $nym('.w-hide').height() - scroll_inc;

			var	scroll_node = $nym(this).parents('.w-action').prev('.w-hide').children('.w-scroll');

			if (parseInt(scroll_node.css('top')) >= -scroll_offs) {
				scroll_busy = true;
				scroll_node.stop();

				scroll_move = Math.floor( Math.abs(parseInt(scroll_node.css('top'))) + scroll_inc);

				scroll_node.animate(
					{ top: -scroll_move + 'px' },
					scroll_speed,
					function() { scroll_busy = false; }
				);

			} else {
				scroll_busy = false;
				scroll_node.stop();
			}
		}
	);

	$nym('a.js-scrollup').click(function(event) {
			event.preventDefault();
			if (scroll_busy) { return; }

			var	scroll_node = $nym(this).parents('.w-action').prev('.w-hide').children('.w-scroll');

			if (parseInt(scroll_node.css('top')) <= -1) {
				scroll_busy = true;
				scroll_node.stop();

				scroll_move = Math.floor( parseInt(scroll_node.css('top')) + scroll_inc);

				scroll_node.animate(
					{ top: scroll_move + 'px' },
					scroll_speed,
					function() { scroll_busy = false; }
				);

			} else {
				scroll_busy = false;
				scroll_node.stop();
			}

		}
	);

});
//

// AUX
$nym(document).ready(function(){

	// open link in another window
	$nym('a.js-el').click(function() {
		window.open($nym(this).attr('href'));
		return false;
	});

	// ie6 picture hover
	$nym('div.js-fixHover').each( function() {
		$nym(this).hover(
			function() {
				$nym(this).addClass('hover');
			},
			function() {
				$nym(this).removeClass('hover');
			}
		);
	});

});







// MOUSE WHEEL & SLIDERS CONTROL
$nym(document).ready(function() {
	if ($nym.browser.mozilla) {
      _wheel_coef = 50;
	} else if($nym.browser.safari) {
			_wheel_coef = 40;
	}	else {
		_wheel_coef = 45;
	}

	// mouse wheel over the comments area
	$nym('.w-comment-list').bind('mousewheel', function(event, delta) {
			var node = $nym(this).find('.w-hide');
			if ( node.attr('scrollHeight') > node.outerHeight() + 2 ) {
				var speed = node.height() / node.attr('scrollHeight') * (_wheel_coef);

				var nv = node.scrollTop() - delta * speed;
				node.scrollTop(nv);

				var s_hande =  node.scrollTop() / ( node.attr('scrollHeight') -  node.height() ) * 100;
				$nym(this).parents('.x-comment').find('.slide-comment').slider('option', 'value', -s_hande );

				return false;
			}

			return true;
	});
	//

	// slide comments
	$nym('.slide-comment').each(function() {
		$nym(this).slider({
			animate: false,
			orientation: "vertical",
			min: -100,
			max: 0,
			slide: function(event, ui) {
				var node = $nym(this).parents('.x-comment').find('.w-hide');

				if ( node.attr('scrollHeight') > node.outerHeight() + 2 ) {
					var ratio = node.attr("scrollHeight") - node.height();
					node.attr( { scrollTop: -ui.value * (ratio / 100) } );
				} else {
					return false;
				}

				return true;
			}
		});

	});

});
//







$nym(document).ready(function() {


						   
    $nym('.sp-slides').cycle({
	fx:'scrollHorz',
	next: '.next-slide', 
	prev:'.prev-slide',
	timeout:0
	 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	

 
	
	
});
//




/*FANCY scrollers*/

var apply_scroller=
function(scroller) 
{

scroller.jScrollPane({scrollbarWidth:'3'});

};



$nym(document).ready(function() {

$nym('.t-box').jScrollPane({scrollbarWidth:'3'});

});


$nym(document).ready(function() {

$nym(".menu-lvl-1 li ul li").hover( function(){ 

var classes=$nym(this).parents('.d-holder').attr('class').split(' ');
$nym(this).parents('.d-holder').addClass(classes[0]+'-active');

});

$nym(".menu-navy li").mouseout( function(){ 

var classes=$nym(this).parents('.d-holder').attr('class').split(' ');
$nym(this).parents('.d-holder').removeClass(classes[0]+'-active');

});

});

Cufon.replace('h1');