/*************************************************************
Custom scripts for Company K Media's Wordpress template. 
Requires JQuery library.
*************************************************************/

// Some global vars
KK_NAV_BG_IMAGE_WIDTH = 193;																					// Width (pixels) of the BG image used on nav hover
KK_THEME_IMAGE_PATH = 'http://www.companykmedia.com/wp-content/themes/companyk/images';		// Path to images from root of site

// Position the nav highlight shadow behind the currently selected nav item
function kkHightlightNav(evt)
{
	width = jQuery(this).width();																			// Get width of the nav item
	offset = evt.target.offsetLeft+(1024-document.getElementById('nav').offsetWidth);						// Get left offset from of container div
	jQuery('#navbox').css('backgroundPosition', (offset+(width/2)-(KK_NAV_BG_IMAGE_WIDTH/2)) +'px top');  	// Calculate center of nav item and position bg image there
	return true;
}

// Remove the nav highlight
function kkUnighlightNav()
{
	jQuery('#navbox').css('backgroundPosition', '-9000px top');
	return true;
}

function _debug(v) {
	jQuery('#debug').append(v);	
}

/***********************
* Do stuff onload
***********************/
jQuery(document).ready(function(){
	jQuery('#nav > li').hover(kkHightlightNav,kkUnighlightNav);						// Add hover handlers to nav items

	// Make fancy ordered lists - each bullet image contains a number
	var lists = jQuery('#innerpage #content ol');														// Get list objects
	// Loop over and apply new background images
	lists.each(function() {
			jQuery(this).children().each(function(index) {
					if( (index+1) <= 20 ) {
						jQuery(this).css('backgroundImage', 'url('+KK_THEME_IMAGE_PATH+'/bullets/'+(index+1)+'.png)');
					}else{
						jQuery(this).css('backgroundImage', 'url('+KK_THEME_IMAGE_PATH+'/bullets/pound.png)');
					}
				});
		});

	// Add fade effect to all DandyID images
	var dandyicons = jQuery('.dandyid_publicserviceswidget img');
	dandyicons.fadeTo(0, 0.5);
	dandyicons.hover(function(){jQuery(this).fadeTo(0, 1.0);}, function(){jQuery(this).fadeTo(0, 0.5);});
	
	// Dynamically set height of box
	var dandyiconsbox = jQuery('#homepage .dandyid_publicserviceswidget');
	dandyiconsbox.css('height', dandyiconsbox.height());
	
	// Add double quote to blockquotes. Also mod styles for blockquote inner <p>'s for browser that don't recognize our css.
	jQuery('blockquote p:first-child').css('marginTop', '0px').prepend('<div class="lquote"><img src="'+KK_THEME_IMAGE_PATH+'/lquote.png" alt="" /></div> ');
	jQuery('blockquote p:last-child').css('marginBottom', '0px').append('<div class="rquote"><img src="'+KK_THEME_IMAGE_PATH+'/rquote.png" alt="" /></div> ');
});
