/* Author: Thomas W. Dean III - Oct. 2011 */


/***************************************************
	    IMAGE HOVER
***************************************************/

jQuery(document).ready(function($){

            $('.portfolio-img,.home-bottom-ad').each(function() {
                $(this).hover(
                    function() {
                        $(this).stop().animate({ opacity: 0.5 }, 300);
                    },
                   function() {
                       $(this).stop().animate({ opacity: 1.0 }, 300);
                   })
                });
});


/***************************************************
	  Shorten links for blog
**************************************************/

jQuery(document).ready(function($){
	$('.blogsitesummary li a').each(function()
 		{

	if( $(this).text().length > 45 ) 
		{
		$(this).text($(this).text().substring(0,42)+"...");
	} 
	else
		{ 
	   $(this).text($(this).text().substring(0,42));
	}
 	});
});


/***************************************************
	  Shorten links in recent blogs
**************************************************/

jQuery(document).ready(function($){
	$('.BlogRecentPost li a').each(function()
		{

	if( $(this).text().length > 42 ) 
	{
		$(this).text($(this).text().substring(0,40)+"...");
	} 
	else
		{ 
	   $(this).text($(this).text().substring(0,40));
	}
	});
});


/***************************************************
	  ACCORDION FOR MY ACCOUNT
**************************************************/

jQuery(document).ready(function($){

	$('.accordionButton').click(function() {

		$('.accordionButton').removeClass('on');
		  
	 	$('.accordionContent').slideUp('normal');
   
		if($(this).next().is(':hidden') == true) {
			
			$(this).addClass('on');
			  
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');						
	});	
	
	$('.accordionContent').hide();
	
	/********************************************************************************************************************
	OPENS THE DIV THAT IS ASSIGNED WITH THE ID open
	*******************************************************************************************************************	
	$("div.accordionButton:eq(0)").trigger('click');
	*/
});



/***************************************************
	  REPLACE BC ALERTS WITH SOME AJAX
**************************************************/

jQuery(document).ready(function($){

$.alertMessageHolder = function(note, messageStyle) {
    
    messageStyle = (messageStyle == 'error') ? 'alertMessageHolder_error' : 'alertMessageHolder_success'; 
         
    $('html').animate({ scrollTop: 0 }, 'slow', function(){
      $('#alertMessageHolder').fadeOut('fast', function(){
        $('#alertMessageHolder p').attr('class', messageStyle).html(note);
        $('#alertMessageHolder').fadeIn('slow');
      });
    });
  }

window.alert = function(msg){
    messageStyle = 'success';
    
    if ((msg.indexOf('ERROR:') >= 0) || (msg.indexOf('- ') >= 0))
    {
      messageStyle = 'error';  
    }   
    $.alertMessageHolder(msg, messageStyle);
  }
  return false;
  
});   

function changeEmptyCartMessage() {
    var ajax_url = '/empty_cart_page.html';
    $.ajax({
      url:     ajax_url,
      data:    '',
      success: function(output){
        $('#catCartDetails .cartLink').remove();
        $('#catCartDetails').html(output);
      }
    });
}

function UpdateProductExtras(c, p, res) {
        if (res == -1) {
        changeEmptyCartMessage();
        }
}
