function mainmenu(){
$("#navigation ul ul ").css({display: "none"}); // Opera Fix
$("#navigation li").hover(function(){
$(this).find('ul:first').parent('li').addClass("active");
$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(300);
},function(){
$(this).find('ul:first').parent('li').removeClass("active");
$(this).find('ul:first').css({visibility: "hidden"});
});
}

$(function() {
 
	 mainmenu();
	
	$('#banner ul#slides li').hide();
	$('#banner ul#slides li:first').show();
	
	var numberofslides = $('ul#slides li').size();
	var x = 1;
	var slideclass;
	var slidep;
	var y = 0;
	
	function slideleft() {
		x--;
		if(x == 0) { x = numberofslides; }
		slideclass = 'ul#slides li.slide'+x;
		$('ul#slides li').fadeOut(500);
		slidep = slideclass+' p';
		$(slideclass).fadeIn(1000);
		$(slidep).animate({"bottom":"-200px"});
		$(slidep).animate({"bottom":"0px"});
		$('ul#circles li').css({"opacity":"0.4"});
		$('ul#circles li').eq(x-1).animate({"opacity":"1"});
	}
	
	function slideright() {
		x++;
		if(x > numberofslides) { x = 1; }
		slideclass = 'ul#slides li.slide'+x;
		$('ul#slides li').fadeOut(500);
		slidep = slideclass+' p';
		$(slideclass).fadeIn(1000);
		$(slidep).animate({"bottom":"-200px"});
		$(slidep).animate({"bottom":"0px"});
		$('ul#circles li').css({"opacity":"0.4"});
		$('ul#circles li').eq(x-1).animate({"opacity":"1"});
	}
	
	if($('.autoslide').text() == "") { } else {
		setInterval(function() {
	if(y == 0) { 
		x++;
		if(x > numberofslides) { x = 1; }
		slideclass = 'ul#slides li.slide'+x;
		$('ul#slides li').fadeOut(500);
		slidep = slideclass+' p';
		$(slideclass).fadeIn(1000);
		$(slidep).animate({"bottom":"-200px"});
		$(slidep).animate({"bottom":"0px"});
		$('ul#circles li').css({"opacity":"0.4"});
		$('ul#circles li').eq(x-1).animate({"opacity":"1"});
	}
		}, $('.autoslide').text());
	}
	
	$('.arrowleft').click(function() {
		slideleft();
		y = 1;
		return false;
	});
	
	$('.arrowright').click(function() {
		slideright();
		y = 1;
		return false;
	});
	
	$('ul#circles li').click(function() {
		y = 1;
		x=$('ul#circles li').index($(this))+ 1;
		slideclass = 'ul#slides li.slide'+x;
		$('ul#slides li').fadeOut(500);
		slidep = slideclass+' p';
		$(slideclass).fadeIn(1000);
		$(slidep).animate({"bottom":"-200px"});
		$(slidep).animate({"bottom":"0px"});
		$('ul#circles li').css({"opacity":"0.4"});
		$(this).animate({"opacity":"1"});
		return false;
	});
	
	
	$('#banner ul#circles li').css({"opacity":"0.4"});
	$('#banner ul#circles li:first').css({"opacity":"1"});
	
	var tabid = 0;
	$('.tabs .tabbar li').click(function() {
		tabid = $(this).parent('.tabbar').find('li').index($(this));
		$(this).parent('.tabbar').find('li').removeClass('active');
		$(this).addClass('active');
		$(this).parent('.tabbar').parent('.tabs').find('.tabpanes').find('.tabpane').hide();
		$(this).parent('.tabbar').parent('.tabs').find('.tabpanes').find('.tabpane').eq(tabid).show();
	});
	
	$('.widget ul li:last-child').css({"border":"0"});
	
	$('.gallery .post').hover(function() {
		$(this).find('.gallerythumb').find('span').fadeIn();
		$(this).find('.gallerythumbslider').find('span').fadeIn();
		$(this).find('h3').addClass('hover');
	}, function() {
		$(this).find('.gallerythumb').find('span').hide();
		$(this).find('.gallerythumbslider').find('span').hide();
		$(this).find('h3').removeClass('hover');
	});
	
	$('.mainimage li:first').show();
	var galleryslidernumber;
	$('.gallery_slider .post .gallerythumbslider').click(function() {
		galleryslidernumber = $(this).parent('p').parent('.post').attr('id');
		$('.mainimage li').hide();
		$('.mainimage li').eq(galleryslidernumber).fadeIn();
		return false;
	});
	
	$('.tabs .tabbar li').eq(0).addClass('active');
	$('.tabs .tabpane').eq(0).addClass('active');
	
	$('.toggle h5 a').click(function() {
		$(this).parent('h5').parent('.toggle').find('.text').slideToggle();
		$(this).parent('h5').parent('.toggle').toggleClass('toggleactive');
		if($(this).find('span.plus').text() == "+") { $(this).find('span.plus').text('-'); } else { $(this).find('span.plus').text('+'); }
		return false;
	});
	
	var sliderid = 0;
	$('.slider ul.thumbs li').css({"opacity":"0.4"});
	$('.slider ul.thumbs li').eq(0).css({"opacity":"1"});
	$('.slider ul.thumbs li').click(function() {
		sliderid = $(this).parent('ul').find('li').index($(this));
		$(this).parent('ul').parent('.slider').find('ul.slides').find('li').fadeOut(1000);
		$(this).parent('ul').parent('.slider').find('ul.slides').find('li').eq(sliderid).fadeIn(1000);
		$(this).parent('ul').find('li').css({"opacity":"0.4"});
		$(this).animate({"opacity":"1"});
	});
	
	var navigationhtml = "<div style='clear:both' class='navigation'>"+$('.navigation').html()+"</div>";
	$('.entry .thenavigation').html(navigationhtml);
	$('.entry .navigation:first').remove();
	
	var navihtml = "<div style='clear:both' class='navigation'><div  class='wp-pagenavi'>"+$('.wp-pagenavi').html()+"</div></div>";
	$('.entry .thenavigation').html(navihtml);
	$('.entry .wp-pagenavi:first').remove();
	
	$('#s').focus(function() {
		if($(this).attr("value") == "Search...") { $(this).attr("value",""); }
	});
	$('#s').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Search..."); }
	});
	
	
	$('ul.circles li').css({"opacity":"0.4"});
	$('ul.circles li.active').css({"opacity":"1"});
	var homelatestpostsnumber = 0;
	$('.homelatestposts ul.circles li').click(function() {
		homelatestpostsnumber = $('.homelatestposts ul.circles li').index($(this));
		$('.homelatestposts .postslider .post').hide();
		if(homelatestpostsnumber == 1) {
			$('.homelatestposts .postslider .post').eq(4).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(5).delay(100).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(6).delay(200).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(7).delay(300).fadeIn(200);
		} else if(homelatestpostsnumber == 2) {
			$('.homelatestposts .postslider .post').eq(8).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(9).delay(100).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(10).delay(200).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(11).delay(300).fadeIn(200);
		} else if(homelatestpostsnumber == 3) {
			$('.homelatestposts .postslider .post').eq(12).fadeIn();
			$('.homelatestposts .postslider .post').eq(13).delay(100).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(14).delay(200).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(15).delay(300).fadeIn(200);
		} else if(homelatestpostsnumber == 4) {
			$('.homelatestposts .postslider .post').eq(16).fadeIn();
			$('.homelatestposts .postslider .post').eq(17).delay(100).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(18).delay(200).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(19).delay(300).fadeIn(200);	
		} else {
			$('.homelatestposts .postslider .post').eq(0).fadeIn();
			$('.homelatestposts .postslider .post').eq(1).delay(100).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(2).delay(200).fadeIn(200);
			$('.homelatestposts .postslider .post').eq(3).delay(300).fadeIn(200);
		}
		$('.homelatestposts ul.circles li').css({"opacity":"0.4"});
		$(this).animate({"opacity":"1"});
	});
	
	$('.feature').hover(function(){
		$(this).css({"borderColor":"#CCC"});
	}, function() {
		$(this).css({"borderColor":"#EEE"});
	});
	
	$('.features p').hide();
	$('.features .feature p').show();
	
	$('.features_cols2 .feature').eq(1).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(2).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(3).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(4).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(5).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(6).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(7).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(8).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(9).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(10).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(11).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(12).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(13).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(14).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols2 .feature').eq(15).css({"marginRight":"0px", "width":"49%"});
	$('.features_cols2 .feature').eq(16).before("<div style='clear:both;display:block;height:10px;'></div>");
	
	$('.features_cols3 .feature').eq(2).css({"marginRight":"0px", "width":"32%"});
	$('.features_cols3 .feature').eq(3).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols3 .feature').eq(5).css({"marginRight":"0px", "width":"32%"});
	$('.features_cols3 .feature').eq(6).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols3 .feature').eq(8).css({"marginRight":"0px", "width":"32%"});
	$('.features_cols3 .feature').eq(9).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols3 .feature').eq(11).css({"marginRight":"0px", "width":"32%"});
	$('.features_cols3 .feature').eq(12).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols3 .feature').eq(14).css({"marginRight":"0px", "width":"32%"});
	$('.features_cols3 .feature').eq(15).before("<div style='clear:both;display:block;height:10px;'></div>");
	
	$('.features_cols4 .feature').eq(3).css({"marginRight":"0px", "width":"24%"});
	$('.features_cols4 .feature').eq(4).before("<div style='clear:both;display:block;height:10px;'></div>");
	$('.features_cols4 .feature').eq(7).css({"marginRight":"0px", "width":"24%"});
	$('.features_cols4 .feature').eq(8).before("<div style='clear:both;display:block;height:10px'></div>");
	$('.features_cols4 .feature').eq(11).css({"marginRight":"0px", "width":"24%"});
	$('.features_cols4 .feature').eq(12).before("<div style='clear:both;display:block;height:10px'></div>");
	$('.features_cols4 .feature').eq(15).css({"marginRight":"0px", "width":"24%"});
	$('.features_cols4 .feature').eq(16).before("<div style='clear:both;display:block;height:10px'></div>");
	
	var latestpostswidgettoshow = 0;
	var latestpostswidgetpostclass;
	$('.latestpostswidget ul.circles li').click(function() {
		latestpostswidgettoshow = $(this).parent('ul').find('li').index($(this));
		latestpostswidgetpostclass = latestpostswidgettoshow + 1;
		latestpostswidgetpostclass = "li.posts"+latestpostswidgetpostclass;
		$(this).parent('ul').parent('.bottom').parent('.latestpostswidget').find('ul.posts').find('li').hide();
		$(this).parent('ul').parent('.bottom').parent('.latestpostswidget').find('ul.posts').find(latestpostswidgetpostclass).fadeIn(200);
		$(this).parent('ul').find('li').css({"opacity":"0.4"});
		$(this).animate({"opacity":"1"});
	});
	
	var testimonialtoshow = 0;
	var testimonialpostclass;
	$('.testimonialswidget ul.circles li').click(function() {
		testimonialtoshow = $(this).parent('ul').find('li').index($(this));
		testimonialpostclass = testimonialtoshow + 1;
		testimonialpostclass = ".quote"+testimonialpostclass;
		$(this).parent('ul').parent('.text').find('.thequote').hide();
		$(this).parent('ul').parent('.text').find(testimonialpostclass).fadeIn();
		$(this).parent('ul').find('li').css({"opacity":"0.4"});
		$(this).animate({"opacity":"1"});
	});
	
	$('.skills .bar p').css({"width":"0%"});
	$('.skills .bar p').each(function() {
		$(this).animate({"width":$(this).find('span').find('span').text()+"%"});
	});
	
	if($.browser.msie){ } else {
	$('.sociallist ul li a img').css({"opacity":"0.7"});
	}
	$('.sociallist ul li a').hover(function() {
	if($.browser.msie){ } else {
		$('.sociallist ul li a img').css({"opacity":"0.7"});
		$(this).find('img').css({"opacity":"1"});
	}
	}, function() {
	if($.browser.msie){ } else {
		$(this).find('img').css({"opacity":"0.7"});
	}
	});
	
	
	$('.portfolioslider ul.circles').show();
	$('.portfolioslider ul.slides li').hide();
	$('.portfolioslider ul.slides li:first').show();
	var portfolioimagetoshow = 0;
	$('.portfolioslider ul.circles li').click(function() {
		portfolioimagetoshow = $('.portfolioslider ul.circles li').index($(this));
		$(this).parent('ul').parent('.portfolioslider').find('ul.slides').find('li').hide();
		$(this).parent('ul').parent('.portfolioslider').find('ul.slides').find('li').eq(portfolioimagetoshow).fadeIn();
		$(this).parent('ul').find('li').css({"opacity":"0.4"});
		$(this).animate({"opacity":"1"});
	});

	
	// IPHONE //
	$('.shownav').click(function() {
		if($(this).text() == "Show Navigation") { $(this).text('Hide Navigation'); } else { $(this).text('Show Navigation'); }
		$('#navigation ul').slideToggle();
		return false;
	});
	
});

$(window).ready(function() {
	$('.feature').each(function(index) {
		$(this).find('.icon').height($(this).height()+20);
	});
});
