// JavaScript Document
var blog_catid = '';

//google.load("feeds", "1");
     	
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(){
	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(){
	var feedUrl = 'http://www.ipevo.com/blog/?feed=rss2&cat=64';
	var item_feed = '';
	if(blog_catid.length>0){
		feedUrl = feedUrl+'&'+blog_catid;	
	}
	
	var feed = new google.feeds.Feed(feedUrl);
      feed.load(function(result) {
        if (!result.error) {
			for (var i = 0; i < result.feed.entries.length; i++) {
			 var entry = result.feed.entries[i];
			 if(i==result.feed.entries.length-1)
				 item_feed = '<div class="gray_comments gray_comments_no_border">';
			 else
			 	item_feed = '<div class="gray_comments">';
				 item_feed = item_feed +
					 '<a href="'+entry.link+'">'+entry.title+'</a>.<br />'+
					 entry.contentSnippet+
				 '</div>';
			 $('#relateds').append(item_feed);
			}
        }
      });			
}*/

function loadYoutube(obj){
	$('#pl_youtube').html(obj);	
}

function loadPackage(obj){
	$('#pl_package').html(obj);	
}

/*function loadDownloads(obj){
	$('#pl_downloads').html(obj);	
}*/

//sleep
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}


function loadJson(p){
	//$.getJSON("http://support.ipevo.com/services/rest.php?method=3dcart&prod=76&limit=5&jsoncallback=?",				
	var url = "http://support.ipevo.com/services/rest.php?action=3dcart&"+p+"&limit=5&jsoncallback=?";
	$.getJSON(url,
        function(datas){
			if(datas.success){
				var html = "", len = 0;
				
				$.each(datas.data, function(i,item){											
					//alert(item.review.length + '\n' + item.download.length);
					if(item.review.length > 0){
						len = item.review.length;
						$.each(item.review, function(j,item){
							if(j == (len-1)){
								html += '<div class="gray_comments gray_comments_no_border">';
							}
							else{
								html += '<div class="gray_comments">';
							}
							
							html += '<a href="'+item.link+'" title="'+item.subject+'" target="_blank">'+item.subject+'</a><br />'+
								item.summary;
								
							if(j == (len-1)){
								html += '<br /><br /><a href="http://support.ipevo.com/reviews_'+p.replace("prod=", "")+'_1.html" style="float:right;" target="_blank">more</a>'
							}
							
							html += '</div>';
							
							 $('#relateds').html(html);
						});						
					}
				
					if(item.download.length > 0){												
						var type = "";
						html = "";
						$.each(item.download, function(j,item){							
							len_dr = item.driver.length;
							if(len_dr > 0){							
								$.each(item.driver, function(k,item){									
									if(item.type !== type){
										if(type != "") html+='</ul>';
										html+='<ul><li><span style="font-weight: bold;">'+item.type+':</span></li></ul>';
										html+='<ul id="right_content_spec">';
										type = item.type;
									}
									if(item.tid < 3){
										html+='<li><a title="' + item.name + ' version ' + item.version + '" href="'+item.filepath+'">'+ item.name + ' version ' + item.version +'</a>&nbsp;<img src="'+item.icon+'" /></li>';
									}
									else{
										html+='<li><a title="' + item.name + '" href="'+item.filepath+'">'+ item.name + '</a>&nbsp;<img src="'+item.icon+'" /></li>';
									}
										
									if(k == (len_dr-1)){
										
										html+='</ul>';
										
									}									
								});
							}
							
							len_doc = item.doc.length;
							if(len_doc > 0 ){								
								//$('#pl_downloads').append('<ul><li><span style="font-weight: bold;">Document:</span></li></ul>');
								html+='<ul><li><span style="font-weight: bold;">Document:</span></li></ul>';
								$.each(item.doc, function(k,item){
									if(k == 0) html+='<ul id="right_content_spec">';
																		
									html+='<li><a title="' + item.name + '" href="'+item.filepath+'">'+ item.name +'</a>&nbsp;<img src="'+item.icon+'" /></li>';
									
									if(k == (len_doc-1)) html+='</ul>';
								});
							}
							
							$('#pl_downloads').html(html);																										
						});
						//alert(html);
					}

					if(item.faq.length > 0){
						html = "";
						len = item.faq.length;						
						html += '<ul id="right_content_spec">';
						$.each(item.faq, function(j,item){
							
							
							html += '<li><a href="'+item.link+'" title="'+item.question+'" target="_blank">'+item.question+'</a></li>';														
						});
						html += '</ul>';
						html += '<a href="http://support.ipevo.com/faq_'+p.replace("prod=", "")+'.html" style="float:right;text-decoration:underline;" target="_blank">more</a>'
						$('#faq').html(html);
					}
					
					
					if(item.galleries != ""){
						Shadowbox.init({
							language: 'en',
							players: ["iframe"]
						});
						$('#btnGallery').attr("href", item.galleries);
						sleep(3000);
						$('#btnGallery').parent().css("display", "block");
					}
					else{
						$('#btnGallery').parent().css("display", "none");
					}
										
				});	
				
				if($('#pl_downloads').html().length == 0){
					$('#p_downloads').css("display", "none");	
				}
				
				if($('#relateds').html().length == 0){
					$('#p_relateds').css("display", "none");	
				}
				
				if($('#faq').html().length == 0){
					$('#p_faq').css("display", "none");	
				}
								
				
			}
			else{
				alert(datas.msg);	
			}
        });	
}

$(document).ready(function() {
	/* nav */
	$('#products').addClass('current'); //2010.03.09 add							   
						   
	shopping_cart();
		
	
	/* search */
	//Search
	$('#keywords').click(function(){
		if($(this).val() == 'Search'){
			$(this).val('');
		}
	}).blur(function(){
		if(	$(this).val().length == 0){
			$(this).val('Search');
		}
	});
});