jQuery(document).ready(function() {
	
	
	
	//Main menu
	jQuery(".menu-menu-container ul li ").removeAttr('title');
	jQuery("ul.sub-menu").css({display: "none"}); // Fixes opera Bug
	jQuery(".menu-menu-container ul li").hover(function() {
		jQuery(this).find('ul:first').css({display: "block", opacity: 0}).stop().animate({ opacity: 1 }, 200); //Slides down when hover the UL
		jQuery(this).children('a').addClass("hovered"); //Adds a hovered class, so you can see the menu path you are following
	},function() {
		jQuery(this).find('ul:first').css({display: "none"}); //Slides up on mouseleave
		jQuery(this).children('a').removeClass("hovered"); //removes the hovered class.
	});
	
	
	
	//Horizontal Carousel
	jQuery('#mycarousel').jcarousel({animation: 500,wrap: 'circular',scroll: 1});
	jQuery('.jcarousel-item').each(function(){
		var cont = jQuery(this).html();
		var link = jQuery('img',this).attr('id');
		var title = jQuery('img',this).attr('rev');
		jQuery(this).html('<a href="'+link+'" title="'+title+'">'+cont+'<div class="image-preview-horizontal"></div></a>');
		jQuery('img',this).animate({opacity:0.4},0);
	});
	jQuery('a','#mycarousel').hover(function(){
		jQuery('img',this).stop().animate({opacity:1},500);
	},function(){
		jQuery('img',this).stop().animate({opacity:0.4},300);
	});
	
	 //Calendar Hack
    jQuery('#wp-calendar tfoot td#prev a').html("");
    jQuery('#wp-calendar tfoot td#next a').html("");
	
    var cal = jQuery('.right_content #wp-calendar');
	var text = jQuery('caption',cal).html();
	if(text !== null){
		jQuery('caption',cal).html('<span>'+text.substring(0,3)+'</span>');
	}
	jQuery('tbody tr',cal).last().css('background','none');
	jQuery('#prev',cal).css('display','block');
	jQuery('#next',cal).css('display','block');

	var cal = jQuery('.footer_one_content #wp-calendar');
	var text = jQuery('caption',cal).html();
	if(text !== null){
		jQuery('caption',cal).html('<span>'+text.substring(0,3)+'</span>');
	}
	jQuery('tbody tr',cal).last().css('background','none');
	jQuery('#prev',cal).css('display','block');
	jQuery('#next',cal).css('display','block');
	
	
    
    //Adding click function on image-preview icon
	jQuery('.image-preview').live('click',function(){
		var parent = jQuery(this).parent(".portfolio_image_bg");
		jQuery('.pirobox',parent).last().click();
	});
		
	//Tabbed
	jQuery('.recent_butt').click(function(){
		jQuery('a',this).click();		
	});
	jQuery('.popular_butt').click(function(){
		jQuery('a',this).click();		
	});
	jQuery('.comments_butt').click(function(){
		jQuery('a',this).click();		
	});
	
	//Adding Holders for widgets
	jQuery('.footer_one_widget[class*="calendar-"]').addClass('calendarholder');
	jQuery('.footer_one_widget[class*="meta-"]').addClass('metaholder');
	jQuery('.footer_one_widget[class*="app_flickr"]').addClass('flickrholder');
	jQuery('.one_widget[class*="app_flickr"]').addClass('flickrholder');
	jQuery('.one_widget[class*="categories"]').addClass('categoriesholder');
	jQuery('.one_widget[class*="links"]').addClass('linksholder');
	jQuery('.one_widget[class*="meta"]').addClass('metaholder');
	jQuery('.footer_one_widget[class*="app_recent"]').addClass('recentholder');
	jQuery('.footer_one_widget[class*="archives"]').addClass('archiveholder');
	jQuery('.footer_one_widget[class*="recent-posts"]').addClass('recentpostsholder');
	jQuery('.footer_one_widget[class*="pages-"]').addClass('pagesholderholder');
	jQuery('.footer_one_widget[class*="app_twitter"]').addClass('twitterholder');
	
	jQuery('.recentholder .app_recent_post').last().attr('style','background:none!important;padding-bottom:0!important');
	jQuery('.twitterholder li').last().attr('style','background:none!important;padding-bottom:0!important');
	
	//adding Class to footer bagde image
	jQuery('.flickr_badge_image','#footer').each(function(){jQuery(this).addClass('footer_flickr_badge_image')})
	var c = 1;
	jQuery('.right_content .flickrholder .flickr_badge_image').each(function(){
		if(c == 3){
			jQuery(this).addClass('last');
			c = 0;
		}
		c++;
	});
	//Remove underline from last in submenu
	jQuery('.sub-menu').each(function(){
	jQuery('li.menu-item',this).last().attr('style','background:none!important');
	});
	//Remove Pirobox for frontpage small images
	jQuery('#three-columns .cell_image_front a').removeClass('pirobox').attr('href','javascript:void()');
	jQuery('#four-columns .cell_image_front a').removeClass('pirobox').attr('href','javascript:void()');
	
	//Init Pirobox
	jQuery().piroBox({
		my_speed: 300, //animation speed
		bg_alpha: 0.5, //background opacity
		slideShow : 'true', // true == slideshow on, false == slideshow off
		slideSpeed : 3, //slideshow
		close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
	});
	
	//Prevent empty search form submit
	jQuery('#searchsubmit').click(function(e){
		e.preventDefault();
		var value = jQuery('#s').val();
		if(value !== ""){
			jQuery('#searchform').submit();
		}
	});
	
	jQuery('#four-columns').each(function(){
		var element = jQuery(this);
		jQuery('.one_cell',element).last().addClass('last');
	});
		
	
	
	// Page wigdets
	jQuery('.one_widget','.big_widget_box').last().addClass('last').css('float','right');
	
	jQuery('.one_widget').each(function(){
		var element = jQuery(this);
		jQuery('li',element).last().attr('style','margin-bottom:0!important;padding-bottom:0!important');
		jQuery('li a',element).last().attr('style','margin-bottom:0!important;padding-bottom:0!important');
	});
	
});

			
