var URL    = 'http://www.kemerergroup.com/';
var www    = 'http://www.kemerergroup.com/';
var no_www = 'http://kemerergroup.com/';

// check if img src exists on http://www.keme...  and http://keme...
function check( img, value ) {

  if ( img.attr('src') === www + 'assets/images/' + value ||  img.attr('src') === no_www + 'assets/images/' + value ) {
    return true;
  } else {
    return false;
  }

}
        
$(function(){
	
        


        // Image Map Hover
	$('.imap').hover(
		function() {
		var	id = $(this).attr('id').substr(1, 1),
			article = $('#a' + id).find('.article-headline'),
			img = article.find('img');
			
			article.css('color', '#7c131d');
			
			if (check( img, 'plus-button.jpg')) {
                          img.attr('src', URL + 'assets/images/plus-button-ro.jpg');
			}
		},
		function() {
		var	id = $(this).attr('id').substr(1, 1),
			article = $('#a' + id).find('.article-headline'),
			img = article.find('img');
			
			if (check( img, 'plus-button-ro.jpg') ) {
				article.css('color', '#949494');
				img.attr('src', URL + 'assets/images/plus-button.jpg');
			}
		}
	);	
	
	// Image Map Control
	$('.imap').click(function() {
		var	id = $(this).attr('id').substr(1, 1),
			article = $('#a' + id).find('.article-headline'),
			img = article.find('img');
		
		// If not open yet - close everything else then open
		if (check( img, 'plus-button-ro.jpg') ) {
			$('.article-copy').slideUp();
			$('.article-headline').css('color', '#949494').find('img').attr('src', URL + 'assets/images/plus-button.jpg');

			article.css('color', '#7c131d')
				   .find('img')
				   .attr('src', URL + 'assets/images/minus-button.jpg');
			article.siblings('.article-copy').slideDown();
		}
		
		// If already open - close it
		else if (check( img, 'minus-button.jpg') ) {
			article.css('color', '#949494');
			article.find('img').attr('src', URL + 'assets/images/plus-button.jpg');
			article.siblings('.article-copy').slideUp();
		}
	});


	// Accordion Hover	
	$('.article-headline').hover(
		function() {
			var article = $(this),
                            img = article.find('img');
			
			if (check(img, 'plus-button.jpg') ) {
			        article.css('color', '#7c131d');
				img.attr('src', URL + 'assets/images/plus-button-ro.jpg');
			}
		},
		function() {
			var article = $(this);
			var img = article.find('img');
			
			if ( check(img, 'plus-button-ro.jpg') ) {
				article.css('color', '#949494');
				img.attr('src', URL + 'assets/images/plus-button.jpg');
			}
		}
	);
	
	// Accordion Control	
	$('.article-headline').click(function() {
		var article = $(this),
			img = article.find('img');

                        
		// If not open yet - close everything else then open
		if (check(img, 'plus-button-ro.jpg') )  {
			$('.article-copy').slideUp();
			$('.article-headline').css('color', '#949494').find('img').attr('src', URL + 'assets/images/plus-button.jpg');

			article.css('color', '#7c131d')
			img.attr('src', URL + 'assets/images/minus-button.jpg');
			article.siblings('.article-copy').slideDown();
		}
		
		// If already open - close it
		else if (check( img, 'minus-button.jpg') ) {
			article.css('color', '#949494');
			img.attr('src', URL + 'assets/images/plus-button.jpg');
			article.siblings('.article-copy').slideUp();
		}
	});
	
	settings = {
          tl: { radius: 6 },
          tr: { radius: 6 },
          bl: { radius: 0 },
          br: { radius: 0 },
          antiAlias: true,
          autoPad: true
      }
	  $('.tabs').corner(settings);
});
