$(document).ready(function(){
	
	applyNavClass();
	
	$(function() {
        $('#imageSort a').lightBox();
    });
	
	//create a mouseover event that animates the social icons when mouseover
	$(".facebook, .twitter, .linkedin").mouseover(function(){
	  $(this).stop(true, true).animate({
		marginTop: '-=13'
	  }, 300 );
	});	
	//create a mouseout event that animates the social icons when mouseout
	$(".facebook, .twitter, .linkedin").mouseout(function(){
	  $(this).stop(true, true).animate({
		marginTop: '+=13'
	  }, 100 );
	});
	
		
	$("#html, #css3, #javascript, #php, #mysql, #xml, #apache").mouseover(function() {
		var id = this.id;
		$(this).animate( {
			marginTop: '-=6'
			},50, 'swing', function() {
				this.src = ( 'images/' + id +'_icon.jpg' );
			});
	});
	
	$("#html, #css3, #javascript, #php, #mysql, #xml, #apache").mouseout(function() {
		var id = this.id;
		$(this).animate( {
			marginTop: '+=6'
			},50, 'swing', function() {
				this.src = ( 'images/' + id +'_icon_down.jpg' );
			});
	});

	//find out which page the user is looking at and apply the selected class to the respective meny item
	function applyNavClass()
	{
		var url = location.pathname;
		var pages = [];
			pages[0] = "index";
			pages[1] = "about";
			pages[2] = "portfolio";
			pages[3] = "products";
			pages[4] = "contact";
			pages[5] = "blog";
			
		for (i=0; i < pages.length; i++)
		{
			var page = url.match(pages[i]);
			
			if (page != null)
			{
				$('#' + page).addClass("selected");
			}
		}
	}
	
	$(".accordionButton").mouseover(function() {
		var imgOpen = "open";
		var openClose = this.src;
		var state = openClose.match(imgOpen);
		if (state == "open")
		{
			$(this).attr("src","images/accordion_button_open_hover.png");
		}
		else
		{
			$(this).attr("src","images/accordion_button_closed_hover.png");
		}
		
	});
	
	$(".accordionButton").mouseout(function() {
		var imgOpen = "open";
		var openClose = this.src;
		var state = openClose.match(imgOpen);
		if (state == "open")
		{
			$(this).attr("src","images/accordion_button_open.png");
		}
		else
		{
			$(this).attr("src","images/accordion_button_closed.png");
		}
		
	});
	
	function moveHover(charPos)
	{
		$("#imageHover" + charPos).animate({
			marginTop: '-150'
			}, 675, function() {

			});
		  
	}
	
	$(".accordionButton").click(function() {
		
		var id = $(this).attr("id");	
		var charPos = id.substr(6);				
		var heightOf = $("#imagePort" + charPos).css("height");
		var divPos = $("#imagePort" + charPos);
		var divAt = divPos.position();
		var v = new Number(divAt.top);
		var total = (v + 20);
		
			
		if (heightOf > '228px' && heightOf < '231px')
		{
			$("#imagePort" + charPos).animate({
				height: '650px'
			}, 1000, function() {
				
			});
			
			$(this).attr("src","images/accordion_button_closed.png");
		}
		else 
		{
			$("#imagePort" + charPos).animate({
				height: '230px'
			}, 1000, function() {

			});
			
			$(this).attr("src","images/accordion_button_open.png");
		}
		
		$(window).scrollTop(total);
	});

	
  
 });
