// Fix background image flickering in IE
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }

// IE6 alpha PNG support
// http://www.dillerdesign.com/experiment/DD_belatedPNG/
var DD_belatedPNG;
if (DD_belatedPNG) {
	DD_belatedPNG.fix('#SiteId img,img.transparent,#ContentChannel .resourcesListings li a.pdf,#ContentChannel .resourcesListings li a.video,#ContentChannel ul.clientList li a.pdf,#ContentChannel ul.clientList li a.video');
}


/* Special search behavior */
var Search = {
  prompt: "Search", // default value - should get real value from markup
  init: function() { this.prompt = jQuery('#SearchField').focus(this.focus).blur(this.blur).val(); },
  focus: function() { if (this.value == Search.prompt) { this.value = ''; } },
  blur: function() { if (this.value.length == 0) { this.value = Search.prompt; } }
};

jQuery(function() {
  Search.init();
});

/* begin - Navigation Primary */
var NavigationPrimary = {
  init: function() {    
		var c = this;
		var n = $('#NavigationPrimary');
		
		// Use bgiframe to fix dropdowns over selects if it's available.
		$.fn.bgiframe && $('li', n).bgiframe();

		// Mark parent elements so that we can style them with CSS
		$('> li', n).each(function() { c.markParents(this); });
  	
  	// Use the hoverintent plugin if it's available
  	// if ($.fn.hoverIntent)
  	//     {
  	//   $('li', n).hoverIntent( {
  	//     sensitivity: 1,
  	//     over: this.mouseenter,
  	//     out: this.mouseleave,
  	//     timeout: 100
  	//   });
  	//     }
  	// else
  	  $('li', n).hover(this.mouseenter, this.mouseleave);
  },
  markParents: function(li) {
    var c = this;
    if ($('> ul', li).size() > 0)
	    $(li).addClass('parent').find('> a').addClass('parent').end().find('> ul li').each( function() { c.markParents(this); });
	},
	mouseenter: function() { $(this).addClass('over').children('a').addClass('over'); },
	mouseleave: function() { $(this).removeClass('over').children('a').removeClass('over'); }
	
};
$(function() { NavigationPrimary.init(); });
/* end - Primary Navigation */

// Convert on-tabbed display into tabbed display and activate tabs
$(document).ready(function() {
	var $tabs = $('div.tabs');
	var $tabnav = $tabs.find('ul.tabNav');
	if ($tabs.length > 0 && $tabnav.length == 0) {
		$tabnav = $tabs.prepend('<ul class="tabNav selfClear"></li>').find('> ul');

		// top link breaks tabs
		$('p.topLink').hide();
		
		$tabs	.find('> div')
			.each( function(i) {
				var id = this.id;
				var $h2 = $(this).find('h2:first');
				var title = $h2.attr('title') || $h2.html();
				$tabnav.append('<li><a href="#' + id + '" class="noPopup"><span>' + title + '</span></a></li>');
				$h2.remove();
			});
		// Need delay for browsers to get their DOM in order
		setTimeout(function() {
			$tabs.tabs();
			$('a.tabLink').click(function() { // bind click event to link
				$tabs.tabs('select', this.hash);
				return false;
			});

 		}, 500);
	}
});

$(document).ready(function() {
	$('#ContactForm').validate();
});

$(document).ready(function() {   
	if($('.home #Mast').length > 0){
        var flashvars = {
          solutionsURL: "/solutions/customer-experience-management.aspx",
          industryURL: "/solutions/customer-experience-management.aspx",
          capabilitiesURL: "/architecture/business-intelligence.aspx"
        };
        var params = { wmode: "transparent" };
        var attributes = {};
        swfobject.embedSWF("/images/home/chordiant_home.swf", "Mast", "964", "333", "9.0.0","/images/home/expressInstall.swf", flashvars, params, attributes);
	}
});

/* begin - open new window for external links and pdfs */
/* Commented out on 01-20-2010.  All links open into same window.  Modify the HTML tags if a certain link needs to act otherwise
$(function() {
	$('a[href^=http://],a[href^=https://],a[href$=.pdf]')
		.not($('a.noPopup,a.expand,a.collapse'))
		.not($('#Footer .siteLinks a[href^=http://www.atre.net]'))
		.not($('a[href^=http://pressroom.chordiant.com],a[href^=http://industrynews.chordiant.com],a[href^=http://pressreleases.chordiant.com],a[href^=http://events.chordiant.com],a[href^=http://videos.chordiant.com]'))
		.popupwindow(); // Fully qualified links and PDF files		
});
*/
/* end - open new window for external links and pdfs */

/* Preload images function */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/* Preload homepage images */
MM_preloadImages("/images/home/button-financial-over.gif", "/images/home/button-insurance-over.gif", "/images/home/button-healthcare-over.gif", "/images/home/button-telecommunications-over.gif","/images/solutions/button-financial-over.gif", "/images/solutions/button-insurance-over.gif", "/images/solutions/button-healthcare-over.gif", "/images/solutions/button-telecommunications-over.gif", "/images/solutions/button-acquisition-over.gif", "/images/solutions/button-sell-over.gif", "/images/solutions/button-retention-over.gif", "/images/solutions/button-customer-service-over.gif");