function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

	var $j = jQuery.noConflict();

	$j(document).ready(function() {	
	
		pwdbox();
        get_rss_feed();
        get_news_rss_feed(); 
		/*
		$j(".various3").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		*/
		
		/* slider 		*/
		$j(function(){
		
			if ($j('ul#product_slider').length > 0) {
			  var slider = $j('ul#product_slider').bxSlider({
				controls: false
			  });

			  $j('#go-prev').click(function(){
				slider.goToPreviousSlide();
				return false;
			  });

			  $j('#go-next').click(function(){
				slider.goToNextSlide();
				return false;
			  });
			 }
			});	
			
		if ($j('ul#product_slider').length > 0) {$j('ul#product_slider li').css('width', "915px");}
        });	
	
	
	
	function pwdbox() {
		$j('#mini-password-clear').show();

		$j('#mini-password').hide(); 

		$j('#mini-password-clear').focus(function() {

			$j('#mini-password-clear').hide();
			$j('#mini-password').show();
			$j('#mini-password').focus();

		});

		$j('#mini-password').blur(function() {
			if($j('#mini-password').val() == '') {
				$j('#mini-password-clear').show();
				$j('#mini-password').hide();
			}

		});
		
		$j('#mini-login').focus(function() {
			if($j('#mini-login').val() == 'Email') {				
				$j('#mini-login').val('');
			}
		});
		$j('#mini-login').blur(function() {
			if($j('#mini-login').val() == '') {				
				$j('#mini-login').val('Email');
			}
		});
	}
	
	    function get_news_rss_feed() {
		
			//clear the content in the div for the next feed.
			//if($j("#news-and-events")){
			$j("#news-and-events").empty();
			
			//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
			$j.get(RSS_URL, function(d) {		
				
				//find each 'item' in the file and parse it
				i = 0;
				$j(d).find('item').each(function() {		
									
					//name the current found item this for this particular loop run
					var $item = $j(this);
					// grab the post title
					var title = trim($item.children('title').text());		
					// grab the post's URL
					var link = $item.find('link').text();
					// next, the description
					var description = $item.find('description').text();
					//$(this).find('media\\:content').attr('url')
					
					var url=$item.find("[nodeName=media:content]").eq(1).attr('url'); //fix for Chrome						
					
					if(typeof  url!='undefined')
							{
						//	var picture = 	"<img src=". url .">";
						var picture = "<IMG SRC='"+ url +"' height=160>";
							}else{
							var picture = "";
							}									
					
					// now create a var 'html' to store the markup we're using to output the feed to the browser window
					var html = "<div class=\"news-feed\">";
					html += picture;
					html += "<p class=\"entry\"><a href=\"" + link +"\" target=\"_blank\">" + trim(title.substr(0,100)) + "<\/a><\/p>";
					html += "<p>" + trim(description) +" ...<\/p>";					
					html += "</div>";
					//put that feed content on the screen!
					if(i<5) $j('#news-and-events').append($j(html));  
					i++;
				});				
				
			});
			//};
		};
		
		function get_rss_feed() {

			//clear the content in the div for the next feed.
			$j("#feedContent").empty();

			//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
			$j.get(RSS_URL, function(d) {		
				
				//find each 'item' in the file and parse it
				i = 0;
				$j(d).find('item').each(function() {		
									
					//name the current found item this for this particular loop run
					var $item = $j(this);
					// grab the post title
					var title = trim($item.children('title').text());		
					// grab the post's URL
					var link = $item.find('link').text();
					// next, the description
					var description = $item.find('description').text();
					
					// now create a var 'html' to store the markup we're using to output the feed to the browser window
					var html = "<p class=\"entry\"><a href=\"" + link +"\" target=\"_blank\">" + trim(title.substr(0,53)) + "<\/a><\/p>";
					html += "<p>" + trim(description.substr(0,53)) +" ...<\/p>";					
					
					//put that feed content on the screen!
					if(i<3) $j("#feedContent").append($j(html));  
					i++;
				});				
				
			});
			
		};
