//Set jQuery into no conflict mode
//var $jq = jQuery.noConflict();

$jq(document).ready(function() {
	var selector = '#accordion .kwicks li';

	var gap = 4;
	
	var items = $jq(selector).length;
	var width = parseInt($jq('.accordion-wrapper').width() / items) - gap;
	
	$jq("UL.kwicks").width($jq('.accordion-wrapper').width());

	width += parseInt(gap/items);
	
	var rule = "{ width: " + width + "px;}";
	var sheet = document.styleSheets[document.styleSheets.length - 1];
	if (sheet.insertRule) {
		try {
			sheet.insertRule(selector + " " + rule);
		}
		catch(e) {
			sheet.insertRule(selector + " " + rule, sheet.cssRules.length);
		}
	}
	if (sheet.addRule) {
		sheet.addRule(selector, rule);
	}
		
	//$jq("a.kwicks-anchor-link").each(function(i){$jq(this).width(width);});
		
	// hover effect for the kwicks accordion
	$jq('.kwicks li div.accordion-overlay').hover(function() {
		$jq(this).children('div.accordion-textbox').stop().animate( {top : '95px'}, 600, 'easeOutCubic');
	}, function() {
		$jq(this).children('div.accordion-textbox').stop().animate( {top : '300px'}, 1000, 'easeOutCubic');
	});
		
	$jq('.kwicks li div.accordion-overlay').hover(
		function() {
			$jq(this).children('span.modern-position').stop(true, true).animate( {left : '-170px'}, 600);
			$jq(this).children('span.ie-position').stop(true, true).animate( {left : '-34px'}, 300);
		},
		function() {
			$jq(this).children('span.modern-position').stop(true, true).animate( {left : '-134px'}, 600);
			$jq(this).children('span.ie-position').stop(true, true).animate( {left : '0px'}, 300);
			});
	
	// Browser Specific Code to make Accordion degrade geacefully
	if (jQuery.browser.msie) {		
		if (parseInt(jQuery.browser.version) <= 8) {
			$jq('span.accordion-title').removeClass('modern-position').addClass('ie-position');
		}
	}
		
	if ($jq.browser.safari && parseInt($jq.browser.version.substr(0, 3)) < 528) {
		$jq('span.accordion-title').hide(300);
	}

	if ($jq.browser.opera) {
		$jq('span.accordion-title').hide(300);
	}

	if ($jq.browser.mozilla && $jq.browser.version <= "1.9") {
		$jq('span.accordion-title').hide(300);
	}
	
	$jq('.kwicks').children('li').each(function(i){$jq(this).width(width);});
	
	setTimeout(function(){
	// Sets the Kwicks Accordion in motion
	$jq('.kwicks').kwicks( {
			min : 1,
			max : 630,
			spacing : gap,
			duration : 1000,
			easing : 'easeOutCubic'
		});}, 100);

});

