$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.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 );

}



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


	$nym('.js-proceed').click( function(event) {
		
		error=false;
		
		$nym(this).parents('form').find('input[type="text"], textarea').each( function() 
		{
			
			if($nym(this).hasClass('v-text')&&($nym(this).val()==$nym(this).attr('title')||$nym(this).val()==''))
			{
				error=true;	
				error_animation($nym(this));
			}
			
			if($nym(this).hasClass('v-mail')&&!isValidEmailAddress($nym(this).val()))
			{
				error=true;	
				error_animation($nym(this));		
			}
			
		});
		
		if(!error)
		{	
			var url_node=$nym(this).parents('form').find("input[name='url']");
			
			if(url_node.val()==url_node.attr('title'))
			{
				url_node.val('');	
			}
			
			$nym(this).parents('form').submit();	
			url_node.val(url_node.attr('title'));
			
			var scroll_node=$nym(this).parents('.post-container').find('.b-com-scroll').attr('id');
			
			setTimeout(function(){ apply_scroller($nym('#'+scroll_node)); },3000);
			setTimeout(function(){ $nym('.note').html(''); },10000);
			
		}
		
	});
});



function isValidEmailAddress(emailAddress) {

var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

return pattern.test(emailAddress);

}




// 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'),
									height : i.attr('height'),
									width : i.attr('width')
								}
				
				var img='<img src="'+o.src+'" id="'+o.id+'" class="'+o.cl+'" alt="'+o.alt+'" title="'+o.ttl+'" width="'+o.width+'" height="'+o.height+'"  />';
				
				var destination=$nym(this);
				
				var container=$nym(this).parents('.img-holder');
				
				destination.css('min-height',o.height+'px');
				
				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 fn = $nym(this);
			var node = $nym(this).parents('.post').find('.post-container');
			var nodeshow = $nym(this).parents('.post').find('.post-title .op');
			var nodeclose = $nym(this).parents('.post').find('.post-title .cl');
			var scroller= node.find('.b-com-scroll');
			var imgs=$nym(this).parents('.post').find('.img-holder');
			
			if(node.css('display') == 'none')
			{	
				
				$nym('.post-container').css('display','none');
				$nym('.post-title .op').css('display','block');
				$nym('.post-title .cl').css('display','none');
				
				nodeshow.css("display","none");
				nodeclose.css("display","block");
				node.animate({height:'show',opacity:'show'}, 'slow');
				apply_scroller(scroller);

				if (!node.hasClass('cached')) {
					enableimg(imgs);					
					node.addClass('cached');
				}

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

var posts = $nym('.post');
if (posts.length == 1) {
	posts.find('a.open-post:first').trigger('click');
}

});
//

//INITIATE SHOW POST

// $nym(document).ready
// (
//  function() 
//  {
// 
// setTimeout( 
//  function(){
// 	
// 	
// 	var posts = $nym('.post');
// 	
// 	var count=$nym('.post').length;
// 	
// 	
// 	if (count == 1) {
// 		$nym('a.open-post').trigger('click');
// 	}
// 			// var node=$nym('.post-container');
// 			// 
// 			// var nodeshow = $nym('.post-title .op');
// 			// var nodehide = $nym('.post-title .cl');
// 			// 
// 			// 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");
				
				
					$nym.scrollTo( node, 1000 );

			}
			else
			{
			
				node.animate({height:'hide',opacity:'hide'}, 'slow');
				//nodeview.css("display","block");
				//nodehide.css("display","none");
				var obj=$nym(this).parents('.post-container').children('.comment-box');
				
			}
			
			

			
		}
	);

  }
);
//



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




/*FANCY scrollers*/

var apply_scroller=
function(scroller) 
{

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

};








// JavaScript Document


function ajaxupdater(box_id,type)
{
	var xmlHttp;
	try
	  {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    try
	      {
	    	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      }
	    catch (e)
	      {
	    	alert("Your browser does not support AJAX!");
	    	return false;
	      }
	    }
	  }
	 
	  xmlHttp.onreadystatechange=function()
	    { 
	    
		  if(xmlHttp.readyState==4)
	      {
			  if(type=="comments")
			  { idprefix="commentbox-"; 
			 
			  	$nym('#'+idprefix+box_id).html(xmlHttp.responseText);
				  
			  }
			  else
			  { idprefix="com-num-"; 
			  
			  	$nym('#post-'+box_id).find('.com-num').html(xmlHttp.responseText);
			  
			  }
			  
		  }
		  
		  	  
		  
		  
	    
		}
		

   	  var myDomain = document.domain;
	  
	  var url=_site_path+"comments-ajax.php";
	  
	  url=url+"?id="+box_id+"&type="+type+"&rand="+Math.random()*9999999999999;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);

}





function ajaxupdater_daemon(x)
{
	id=x;
	type1="comments"; 
	setTimeout("ajaxupdater(id,type1)", 300);
	type2="com-num"; 
	setTimeout("ajaxupdater(id,type2)", 300);
}




function note_updater(id,note,success)
{

	parent.document.getElementById("comments-note-"+id).innerHTML=note;
	if(success=="yes")
	{
		parent.document.getElementById("comment-"+id).value="";
	}
	
}



function info_reset(id)
{
	x=id;
	document.getElementById("comments-note-"+id).innerHTML="Sending...";
	setTimeout("check_comment_status(x)",5000);
	
}


function check_comment_status(id)
{
	status=document.getElementById("comments-note-"+id).innerHTML;	
	if(status=="Sending...")
	{	
		note="Comment not sent. Please check required fields! Or it is spam/duplicate comment.";
		x=id;
		setTimeout("note_updater(x,note)",200);	
	}
}





	var flashvars = {};
	var params = {wmode:'transparent'};
	var attributes = {wmode:'transparent',loop:'false'};
	swfobject.embedSWF(_site_path+'iDrop-944x366-transparent-1.swf', "logo-cont", "944", "366", "9.0.0",flashvars,params,attributes);


