$(document).ready(function () {
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
		$('ul.sf-menu').superfish({
			delay: 400,
			animation: {
				height: 'show'
			},
			speed: 275
		})
	} else {
		$('ul.sf-menu').supersubs({
			minWidth: 12,
			maxWidth: 27,
			extraWidth: 0
		}).superfish({
			delay: 400,
			animation: {
				height: 'show'
			},
			speed: 275
		})
	}
	var overlayColor = $('#fancy_overlay').css('background-color') || '#2c2c2c';
	
	$("a.zoom").fancybox({
		'padding': 12,
		'overlayOpacity': 0.2,
		'overlayColor': overlayColor,
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'callbackOnShow': modalStart
	});
	$("a.login").fancybox({
		'padding': 12,
		'overlayOpacity': 0.2,
		'overlayColor': overlayColor,
		'showCloseButton': false,
		'frameWidth': 400,
		'frameHeight': 208,
		'hideOnContentClick': false,
		'callbackOnShow': modalStart
	});
	$('.topReveal').click(function () {
		$('#ContentPanel').slideToggle(800, 'easeOutQuart');
		$.scrollTo('#ContentPanel');
		return false
	});
	
	$("a.img").hover(function () {
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 8) {
			$(this).stop(false, true).toggleClass('imgHover')
		} else {
			$(this).stop(false, true).toggleClass('imgHover', 200)
		}
	});
	
	$.fn.cluetip.defaults.cluetipClass = 'skinned';
	$.fn.cluetip.defaults.cluezIndex = 1234;
	$.fn.cluetip.defaults.dropShadow = false;
	$.fn.cluetip.defaults.topOffset = 35;
	$.fn.cluetip.defaults.fx = {
		open: 'fadeIn',
		openSpeed: '100'
	};
	$.fn.cluetip.defaults.hoverIntent = {
		sensitivity: 3,
		interval: 100,
		timeout: 80
	};
	
	$.fn.cluetip.defaults.onShow = function (ct, c) {
		if ($('#cluetip-inner').html() == '') { (jQuery.browser.msie) ? $('#cluetip').addClass('ieFix') : $('#cluetip').addClass('mozFix')
		} else { (jQuery.browser.msie) ? $('#cluetip').removeClass('ieFix') : $('#cluetip').removeClass('mozFix')
		}
	};
	
	
	$('a[title != ""], .tip').cluetip({
		showtitle: false,
		arrows: true
		/*,splitTitle: '|'*/ /* If used, causes anchor tags not to function without proper title values */
	});
	
	
	$('.tipInclude').cluetip({
		attribute: 'rel',
		showtitle: false,
		arrows: true
	});
	
	$("input[type='text']:not(.noStyle), input[type='password']:not(.noStyle)").each(function () {
		$(this).addClass('textInput')
	});
	$(window).scroll(function () {
		ribbonPosition()
	});
	ribbonPosition();
	$("label.overlabel").overlabel();
	$.localScroll();
	searchInputEffect();
	buttonStyles();
	if (!jQuery.browser.msie) {
		$("a.img, div.img, .textInput, input[type='text'], input[type='password'], textarea").addClass('rounded');
		roundCorners();
	}
});
function modalStart() {
	Cufon.replace('.fancy_title > div');
	$('#fancy_inner').addClass('rounded');
	roundCorners()
}
function ribbonPosition() {
	var t = $(window).scrollTop();
	var h = $(window).height();
	var offset = $(window).height() / 25;
	var zoneSize = $(window).height() / 3;
	var zoneOne = t + zoneSize + offset;
	var zoneTwo = t + zoneSize * 2 - offset;
	$(".ribbon .wrapAround").each(function () {
		var obj = $(this);
		var objH = obj.height();
		var offset = obj.offset();
		if (offset.top + objH <= zoneOne) {
			$(this).css('background-position', '0 0')
		} else if (offset.top >= zoneTwo) {
			$(this).css('background-position', '0 -104px')
		} else {
			$(this).css('background-position', '0 -52px')
		}
	})
}
function searchInputEffect() {
	var searchFocus = false,
	searchHover = false,
	searchCtnr = $('#Search');
	searchInput = $('#SearchInput'),
	searchSubmit = $('#SearchSubmit');
	searchCtnr.hover(function () {
		if (!searchFocus) $(this).addClass('searchHover');
		searchHover = true
	},
	function () {
		if (!searchFocus) $(this).removeClass('searchHover');
		searchHover = false
	}).mousedown(function () {
		if (!searchFocus) $(this).removeClass('searchHover').addClass('searchActive')
	}).mouseup(function () {
		searchInput.focus();
		searchSubmit.show();
		searchFocus = true
	});
	searchInput.blur(function () {
		if (!searchHover) {
			searchCtnr.removeClass('searchActive');
			searchSubmit.hide();
			searchFocus = false
		}
	})
}
function buttonStyles() {
	$("button:not(:has(span),.noStyle), input[type='submit']:not(.noStyle), input[type='button']:not(.noStyle)").each(function () {
		var b = $(this),
		tt = b.html() || b.val();
		if (!b.html()) {
			b = ($(this).attr('type') == 'submit') ? $('<button type="submit">') : $('<button>');
			
			 $.each(this.attributes, function(i, attrib){
			     //alert(b.attr(attrib.name));
			     try {
			     	b.attr(attrib.name, attrib.value);
			     } catch (error) {
			     	//eat the exception
			     }

			     
			  });

			b.insertAfter(this).addClass(this.className).attr('id', this.id);
			$(this).remove();
		}
		b.text('').addClass('btn').append($('<span>').html(tt));
	});
	var styledButtons = $('.btn');
	if (jQuery.browser.mozilla || jQuery.browser.webkit) {
		styledButtons.children("span").css("margin-top", "-1px")
	}
	styledButtons.hover(function () {
		$(this).addClass('submitBtnHover')
	},
	function () {
		$(this).removeClass('submitBtnHover')
	})
	
	
}
function roundCorners() {
	$('.rounded, .ui-corner-all').css({
		'-moz-border-radius': '4px',
		'-webkit-border-radius': '4px',
		'border-radius': '4px'
	})
}
Cufon.replace('h1, h2, h3, h4, h5, h6, .fancy_title div, .replace');
Cufon.replace('.headline', {
		textShadow: '1px 1px rgba(255, 255, 255, 1)'
	})('.ribbon span', {
		hover: true,
		textShadow: '-1px -1px rgba(0, 0, 0, 0.4)'
	})
};

