$(function(){
	
	//collapse more
		$("#collapse_more").append("<a href='#' class='btn_read_more_close' title='Read less'>Read less -</a>").hide();
		$(".btn_read_more").click(function(){
			if ( $(this).next().is(":hidden") ) {
				$(this).next().slideDown("fast");
				$(this).hide();
			} else {
			$(".btn_read_more").next().hide();
				$(this).next().slideDown("fast");
				$(this).show();
			}
		return false;
		})
		$(".btn_read_more_close").click(function(){
			var btnReadMore = $(this).parent().prev()
				$(this).parent().slideUp("fast", function(){
				$(btnReadMore).fadeIn("fast")
		});
		return false;
		})
		
		
		
		// Promo Banner
	
		$.fn.extend({
		customStyle : function(options) {
		  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
		  return this.each(function() {	  
				var currentSelected = $(this).find(':selected');
				$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
				var selectBoxSpan = $(this).next();
				var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
				var selectBoxSpanInner = selectBoxSpan.find(':first-child');
				selectBoxSpan.css({display:'inline-block'});
				selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
				var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
				$(this).height(selectBoxHeight).change(function(){				
				selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');			
			});			
		  });
		  }
		}
	 });
	 $('.styled').customStyle();
		
	});
	jQuery(document).ready(function($) {

	$( '.rotator' ).jCarouselLite({
        btnNext: ".next",
        btnPrev: ".previous",
		afterEnd: function(a) {
			var next_href = $( a.children( 'a' ) ).attr( 'rel' );
			$( '.visit-site' ).attr( 'href', next_href );
			
			var current_num = $( a ).attr( 'id' );
			$( '.current' ).html( current_num );
		}
    });
	
	$(document).keyup(function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		
		switch(code) {
			case 37: $( '.previous' ).trigger( 'click' ); break;
			case 39: $( '.next' ).trigger( 'click' ); break;
		}
	});
	
	$().offsetSlider();
	
	$(window).resize(function() {
		$().offsetSlider();
	});
	
	
	$( '.rotator li' ).live( 'hover', function() {
		$( this ).children( '.actions' ).fadeToggle( 'fast' );
	});
	
}); 
  
jQuery.fn.offsetSlider = function() {
	var windowWidth = jQuery(window).width();
	if ($.browser.msie) {
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 998 ) / 2 ) + 'px'
	});
	}else if ($.browser.msie && parseInt($.browser.version) < 8){
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 988 ) / 2 ) + 'px'
	});
	}else if ($.browser.msie && parseInt($.browser.version) > 9){
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 750 ) / 2 ) + 'px'
	});
	}else if ($.browser.mozilla) {
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 998 ) / 2 ) + 'px'
	});
	}else if ($.browser.chrome) {
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 999 ) / 2 ) + 'px'
	});
	}/*else if ($.browser.safari) {
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 998 ) / 2 ) + 'px'
	});
	}*/else{
		jQuery( '.rotator' ).css({
		padding : '0 0 0 0' + ( ( windowWidth - 998 ) / 2 ) + 'px'
	});
}

	/*jQuery( '.rotator' ).css({
		padding : '0 0 0 ' + ( ( windowWidth - 1000 ) / 2 ) + 'px'
	});*/
	if ($.browser.msie) {
		jQuery( '#slider .slider-navigation' ).css({ 
		right : Math.round( ( windowWidth / 2 ) - 499 ) + 'px'
	});
	}else if ($.browser.msie && parseInt($.browser.version) > 9){
		jQuery( '#slider .slider-navigation' ).css({ 
		right : Math.round( ( windowWidth / 2 ) - 492 ) + 'px'
	});
	}else{
		jQuery( '#slider .slider-navigation' ).css({ 
		right : Math.round( ( windowWidth / 2 ) - 500 ) + 'px'
	});
	}
	
}
