(function(j){
	function pagemenu(pageid){
		j(pageid + " ul").css({display: "none"});
		j(pageid).find('a').removeAttr('title');
		var kl = j(pageid + " li").filter(":has(>ul)");
		
		kl.each(function(){
			j(this).css({position: "relative"});
			j(this).find('a:eq(0)').css({position: "relative"}).append('<span class="arrow"></span>');
		
			j(this).hover(function(){
				j(this).addClass('onhove');
				j(this).find('a:eq(0)').addClass('onhov');
				j(this).find('ul:first').stop().css({overflow:"hidden", height:"auto",visibility: "visible",display: "none"}).slideDown(200,
					function(){
						j(this).css({overflow:"visible", height:"auto", paddingBottom: "8px"});
					}
				);	
			}, function(){
				var biz = j(this).find('a:eq(0)');		
				j(this).find('ul:first').stop().css({overflow:"hidden", display:"none"});
				biz.removeClass('onhov');
				j(this).removeClass('onhove');				
			});
		})
		j(pageid +' .current_page_item').find('a:first').addClass('pageactive');
		j(pageid +' .current-menu-item').find('a:first').addClass('pageactive');
		
	};
	
	function portfolio_lists_hover(){
		var plists = j('.portfolio-item-thumb').find('a');
		
		plists.each(function(){
			j(this).hover(function(){
				j(this).find('img').stop().animate({'opacity' : 0.5}, 200);
			}, function(){
				j(this).find('img').stop().animate({'opacity' : 1.0}, 200);
			});
		});
		
	}
	
	function search_press(){
		var input = j('#searchbox');
		
		input.focus( function(){
			var firstPar = j(this).parent('#search-form');
			firstPar.addClass('onpress');
			firstPar.parent('.search-form-container').addClass('onpress');
		});
		
		input.blur(function(){
			var firstPar = j(this).parent('#search-form');
			firstPar.removeClass('onpress');
			firstPar.parent('.search-form-container').removeClass('onpress');
		});
	};
	
	function backtoTopScroll()
	{
		var totop = j('#copyright').find('.backtotop');
		
		totop.each( function()
		{
		
			j(this).click(function()
			{
				j.browser.opera  = /opera/.test(navigator.userAgent.toLowerCase());  
				if (j.browser.opera){
					j('html').animate({scrollTop : 0}, {queue:false, duration:'slow', easing: 'easeInOutCirc'} );
				} else {
					j('html,body').animate({scrollTop : 0}, {queue:false, duration:'slow', easing: 'easeInOutCirc'} );
				}	
				return false;
			});
		
		});
	
	};
	
	function styling_wd(){
		var sb_list = j(".sidebarbox li").filter(":has(>ul)");
		var ft_list = j(".footer-widget li").filter(":has(>ul)");
		
		sb_list.each(function(){
			j(this).css('padding-bottom', '0px');
			j(this).find('ul:first').css('font-size', '11px');
			j(this).find('ul:first').find('li:last').css('border-bottom', '0');
		});
		
		ft_list.each(function(){
			j(this).css('padding-bottom', '0px');
			j(this).find('ul:first').find('li:last').css('border-bottom', '0');
		});
	};
	
	function ContactHandle()
	{
		j('#contact_submit').click( function() {
		
			var name = j('#hname').val();
			var mail = j('#hmail').val();
			var subs = j('#hsubj').val();
			var mess = j('#hmess').val().replace(/\r?\n|\r/g, "<br>");
			
			j('.contactload').fadeIn('fast');
			
			if (name != "" && mail != "" && subs != "" && mess != "")
				{
					var uril = j("#urlto").val();

					j.ajax(
						{
							url: uril,
							type: 'GET',
							data: "hname=" + name + "&hmail=" + mail + "&hsubj=" + subs + "&hmess=" + mess,
							success: function(result) 
							{
								j('.contactload').fadeOut('fast');
								if(result == "email_error") {
									j('#hmail').next('.req').html(' ! <small>please enter your valid email address</small>');
								} else {
									j('#hname, #hmail, #hsubj, #hmess').val("");
									j('<p id="contact_success">' + result + '<span class="jq_close"></span></p>').insertBefore('#adm-contact');
									j('.jq_close').click(function(){
										j(this).parent().fadeOut(300, function(){ j(this).remove(); });
									});
								}
							}
						}
					);
					return false;
					
				} 
			else 
				{
					j('.contactload').fadeOut('fast');
					if(name == "") j('#hname').next('.req').text(' !');
					if(mail == "") j('#hmail').next('.req').text(' !');
					if(subs == "") j('#hsubj').next('.req').text(' !');
					if(mess == "") j('#hmess').next('.req').text(' !');
					return false;
				}
		});
		
		j('#hname, #hmail, #hsubj, #hmess').focus(function(){
			j(this).next('.req').text(' *');
		});
		
	};
	
	function portfolio_and_blog_img_stuff(){
		var pnt = j('.portfolio-object');
		var bnt = j('.featured-image');
		
		pnt.hover(function(){
			j(this).addClass('hover');
			j(this).find('img').stop().animate({'opacity' : 0.5}, 200);
		}, function(){
			j(this).find('img').stop().animate({'opacity' : 1.0}, 200);
		});
		
		bnt.each(function(){
			j(this).hover(function(){
				j(this).addClass('hover');
				j(this).find('img').stop().animate({'opacity' : 0.5}, 200);
			}, function(){
				j(this).find('img').stop().animate({'opacity' : 1.0}, 200);
			});
		});
		
	};
	
	function doPretty(){
		var gal = j('.gallery').find('a');
		gal.each(function(){
			if(this.href.match(/\.(jpe?g|png|bmp|gif|tiff?)$/i)){
				j(this).attr('rel', 'prettyPhoto[gallery]');
			}
		});
	
		j("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	};
	
	function social_link_hover(){
		var sParam = j('.widget_social_links').find('a');
		
		sParam.each(function(){
			j(this).hover(function(){
				j(this).stop().animate({ opacity : 0.5 }, 500);
			}, function(){
				j(this).stop().animate({ opacity : 1.0 }, 500);
			});
		});
	}
	
j(document).ready(function(){
	pagemenu('#eqnav');
	search_press();
	backtoTopScroll();
	styling_wd();
	ContactHandle();
	doPretty();
	social_link_hover();
});

j(window).load(function(){
	portfolio_lists_hover();
	portfolio_and_blog_img_stuff();
});
})(jQuery);
