// Allows console to alert in IE
if( !console ) { var console = { log: function(msg) { alert(msg); } } }

$().ready(function() {
	/*XML*/
		$.ajax({
		url: 'xml/portfolio.xml',
		type: 'GET',
		dataType: 'xml',
		timeout: 3000,
		error: function(){
			alert('Error loading XML document');
		},
		success: function(xml){ XMLContentLoader(xml); }
		});
	
		function XMLContentLoader(xml){
			$(xml).find('portfolio').children().each(function(c,childrenList){ 
					var projectLink = $(childrenList).children().find('project_link');
					var smThumbNailHref = $(childrenList).children().find('smthumbnail');
					var projectlink;
					$(projectLink).each(function(p, plinks){
						$((smThumbNailHref)[p]).each(function(img,findImg){
							var getOneImg = $(findImg).find('imgname').eq(0);
							var html1 = "";
							html1 += "<a href='"+$(plinks).text()+"'><img src='"+$(getOneImg).text()+"' alt='"+$(getOneImg).attr("title")+"' title='"+$(getOneImg).attr("title")+"' width='"+$(getOneImg).attr("width")+"' height='"+$(getOneImg).attr("height")+"' /></a>";
							$("#portfolio_pane").append(html1);
						});
					});//projectLink
			});//xml portfolio
			//add custom scroll
			//$('#portfolio_pane').jScrollPane({showArrows:true, scrollbarWidth:10, scrollbarMargin:10});		
			
			if(parseparam){
				passParam();
				$().find('.introTxt').hide();
				$().find('.portfolioWrapper').show();
				$(xml).find(typetName).each(function(index, elements){
					var clientInformation = $(this).find(projectName);
					$(".projectName").append($(this).find(projectName).attr('name'));
					$(clientInformation).each(function(i, ele){
						var lgImg = $('<img />').attr({ 
							src: $(ele).find("lgthumbnail").text(),
							title: $(ele).find("lgthumbnail").attr("title"),
							alt: $(ele).find("lgthumbnail").attr("title"),
							width: $(ele).find("lgthumbnail").attr("width"),
							height: $(ele).find("lgthumbnail").attr("height")
						});
						$(".portfolioLgthumbnail").hide().append(lgImg).animate({opacity: 1}, 900 ).show(1000);
						//$(".portfolioLgthumbnail").append(lgImg);
						//description
						$(".skills").append($(ele).find("description").find("skills").text());
						$(".roles").append($(ele).find("description").find("roles").text());
						$(".partners").append($(ele).find("description").find("partners").text());
						//console.log($(ele).find("description").find("summary").text().length);
						if($(ele).find("description").find("summary").text().length >= 1){
							$(".summary").prev("p").show();
							$(".summary").append($(ele).find("description").find("summary").text()).show();
						}
						$(".links").append($(ele).find("description").find("links").text());
						
						//smthumbnail
						$(ele).find("smthumbnail").find("imgname").each(function(k,imgs){
							var smImg = $('<img />').attr({ 
								src: $(imgs).text(),
								title: $(imgs).attr("title"),
								alt: $(imgs).attr("title"),
								width: $(imgs).attr("width"),
								height: $(imgs).attr("height")
							});
							$(".thumbnails").append(smImg)
						});
					});//clientInformation			
				});//xml portfolio detail
			}//if parseparam
		}//XMLContentLoader
});//main