// JavaScript Document
shopping_cart = function(){
	$('#btn_update_cart').click(function(){
		$('#cart').attr("action", "recalculate.asp");
	});	
	$('#btn_checkout').click(function(){
		$('#cart').attr("action", "checkout.asp?step=1");		
	});
		
}

function showLogin(){
	//$(document).ready(function() {
		var loginStr = '';
		loginStr = '<form action="login.asp?ordertracking=1" method="post">'+		
			'<input type="hidden" name="catalogid" value="0">&nbsp;&nbsp;'+
			'<input type="text" size="12" name="email" id="email" value="E-Mail" class="input">'+
			'<input type="password" size="12" name="password" class="input" id="Password1">'+
			'<input type="submit" value="GO" id="Submit1" name="Submit1">'+
			'</form>';
		$('#login').html(loginStr);
				
		$('#email').click(function(){
			$(this).val('');						   
		});	
	//});
}

function loadBlog(){
	$.jGFeed('http://www.ipevo.com/blog/?feed=rss2',
		function(feeds){
		  // Check for errors
		  if(!feeds){
			// there was an error
			return false;
		  }
		  // do whatever you want with feeds here
		  for(var i=0; i<feeds.entries.length; i++){
			var entry = feeds.entries[i];
			// Entry title
			//alert(entry.title);
			if(i==feeds.entries.length-1)
				item_feed = '<div class="grey_box_item grey_box_item_noborder">';
			else
				item_feed = '<div class="grey_box_item">';
			item_feed = item_feed+
				'<a href="'+entry.link+'">'+entry.title+'</a>.<br />'+
				entry.contentSnippet+
                '</div>';
			$('#blog_news_item').append(item_feed);
		  }
		}, 10);
}

function loadTwitter(){
	var items_len = 3;
	$.jTwitter('ipevo', items_len, function(data){
		var twitter_item='';
		$.each(data, function(i, item){
			if(i < items_len-1){
				twitter_item += '<div class="twittter_item">';
			}
			else{
				twitter_item += '<div class="twittter_item twittter_item_no_border">'
			}
							  
			twitter_txt = item.text;
			
			if(twitter_txt.match(/http:\/\/(.+)/) != null){
				url = twitter_txt.match(/http:\/\/(.+)/g);
				$.each(url, function(i, item){
					//alert(item);					 
					urls = '<a href="'+item+'" target="_blank">'+item+'</a>';
					twitter_txt = twitter_txt.replace(item, urls);
				});
			}
			
			if(twitter_txt.match(/@(.+):\s/g) != null){
				str = twitter_txt.match(/@(.+):\s/i);				
				str_url = '<a href="http://twitter.com/'+str[1]+'" target="_blank">'+str[1]+'</a>';
				//alert(str);
				twitter_txt = twitter_txt.replace(str[1], str_url);
				
			}
										  
			twitter_item += twitter_txt + ' <span>from '+ item.source + '</span></div>';            			
		});

		var twitter_content = $('#twitter_content').html()+twitter_item;
		$('#twitter_content').html(twitter_content);
	});

}

//Today's Special
function loadTodayProd(){
	var today_prod = '';
	$.get("assets/images/json/today_prod.xml", function(xml){
		$('today', xml).each(function(i){
			today_prod = '<div class="product_pic"><a href="'+$(this).find("url").text()+'"><img src="'+$(this).find("img").text()+'" alt="'+$(this).find("name").text()+'" /></a></div>'+
				'<div class="product_txt">'+						  
				'<a style="color:#EB6100;font-weight:bold;font-size:9px;" href="'+$(this).find("url").text()+'">'+$(this).find("name").text()+'</a><br />'+
				'<span class="old_price">'+$(this).find("price_1").text()+'</span>  <span class="highlight" style="color:#333333;font-weight:normal;">'+$(this).find("price_2").text()+'</span>'+
				'<span class="light">'+$(this).find("desc").text()+'</span><br /> <a href="'+$(this).find("url").text()+'" style="text-decoration: underline;" title="read more">Find out more</a>'+
				'</div>';
			//alert($(this).find("name").text());
		});
		$('#today_prod').html(today_prod);	
	});
}

//New Stuffs
function loadNew(){
	var new_prod = '';
	$.get("assets/images/json/new_stuffs.xml", function(xml){
		var stuff_len = $('item', xml).length;
		$('item', xml).each(function(i){			
			if(i<stuff_len-1){
				new_prod = new_prod+'<div class="product_item">';
			}
			else{
				new_prod = new_prod+'<div class="product_item product_item_no_border">';
			}
			
			new_prod = new_prod + '<div class="product_pic"><a href="'+$(this).find("url").text()+'"><img src="'+$(this).find("img").text()+'" alt="'+$(this).find("name").text()+'" /></a></div>'+
				'<div class="product_txt">'+						  
				'<a href="'+$(this).find("url").text()+'">'+$(this).find("name").text()+'</a><br />'+
				'<span class="old_price">'+$(this).find("price_1").text()+'</span>  <span class="highlight">'+$(this).find("price_2").text()+'</span>'+				
				'</div>'+
				'</div>';												
		});
		$('#new_stuffs').html(new_prod);	
	});
}

$(document).ready(function() {
	$('#home').addClass('current'); //2010.03.09 add	   
						   
						   
	//Search
	$('#keywords').click(function(){
		if($(this).val() == 'Search'){
			$(this).val('');
		}
	}).blur(function(){
		if(	$(this).val().length == 0){
			$(this).val('Search');
		}
	});
	
	//New Stuffs
	//loadNew();
	
	//Today Product
	//loadTodayProd();
		
	//TWITTER
	loadTwitter();	
	
	//Newsleter
	$('#email_addr').click(function(){
		if($(this).val() == '-- your email address --'){
			$(this).val('');
		}
	}).blur(function(){
		if(	$(this).val().length == 0){
			$(this).val('-- your email address --');
		}
	});
	
});