$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());
			}
	);

});

//




var error_animation=function(objects)
{  

	objects.css( 'background-color','pink');

}




// 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').find('input[type="text"], textarea').each( function() {
				if ($nym(this).hasClass('v-noempty')) {
					if (!validateNoempty($nym(this).val())) {
						
						
						error_animation($nym(this));
						
						
						error = true;
					}

				} else if ($nym(this).hasClass('v-text')) {
					if (!validateText($nym(this).val())) {
						
						error_animation($nym(this));
						
						error = true;
					}
				} else if ($nym(this).hasClass('v-mail')) {
					if (!validateEmail($nym(this).val())) {
						
						error_animation($nym(this));
						
						error = true;
					}
				}
			});

			if (!error) {

				$nym(this).parents('form').submit();
				$nym(this).parents('.add-commentbox').animate({height:'hide',opacity:'hide'}, 'slow');
			}

			return false;
		}
	);

});
//



// 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');
		}
	);

});
//




var enableimg=function(objects)
{  

	objects.each
	(
			function(i,val)
			{	
			
			
				var i=$nym(this).find('span');
				
				
							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(img).load
	(		
		function()
		{
			$nym(dest).append( $nym(this) );
		}
	);	
}









// SHOW post
$nym(document).ready
(
 
 function(){
	$nym('a.open-post').click( function(event) 
		{
			
			var node = $nym(this).parents('.post').children('.post-container');
			var nodeshow = $nym(this).parents('.post').children('.pt-open-link');
			var nodeclose = $nym(this).parents('.post').children('.pt-close-link');
			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('.img-holder');
			
			
			
			if(node.css('display') == 'none')
			{	
				
				$nym('.post-container').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('.pt-open-link');
			var nodehide = $nym('.pt-close-link');
			
			var imgs=$nym('.post').children('.post-container').children('.post-content').find('.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 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");
			}

			
			
		}
	);

  }
);
//



// 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');
			}
			
			
		}










	



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

	$nym('#archives .down').click( function(event) 
		{
			var node=$nym(this).parents('#archives').children('.archives-m').children('div');
			go_down(node,node.children('p'),4);
		});
	
	$nym('#archives .up').click( function(event) 
		{
			var node=$nym(this).parents('#archives').children('.archives-m').children('div');
			go_up(node,node.children('p'),4);
		});
	
}
);





/*
node - items container with overflow hidden parameter
step_node - items to roll
fix - cufont fix, usually cufont adds some pixels
*/

var go_down=function(node,step_node,fix) 
		{
			var len=step_node.length;
			var h=node.innerHeight();
			var step=Math.floor(h/len)+fix;
			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');
			}
			
			
		}



/*
node - items container with overflow hidden parameter
step_node - items to roll
fix - cufont fix, usually cufont adds some pixels
*/

var go_up=function(node,step_node,fix) 
		{
			var len=step_node.length;
			var h=node.innerHeight();
			var step=Math.floor(h/len)+fix;
			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');
			}
			
			
		}





$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:'4'});

};


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

$nym('.b-com-scroll').jScrollPane({scrollbarWidth:'4'});

});











	var flashvars = {};
	var params = {};
	var attributes = {wmode:'transparent'};
	swfobject.embedSWF(_site_path+"/rima_header_transparent-2-1100x155.swf", "head-logo", "1100", "155", "9.0.0",flashvars,params,attributes);


	swfobject.embedSWF(_site_path+"/header.swf", "vimeo_player_holder", "900", "376", "9.0.0",flashvars,params,attributes);



Cufon.replace('h1,h2,#tail,.tail-page,.ad-image-description strong');

