$(document).ready(function() {
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab	
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab

		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		//$(activeTab).show(); //show active content
		return false;
	});
	
	$("#andmorelink").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$("ul.tabs li#featureli").addClass("active"); //Add "active" class to selected tab

		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $("ul.tabs li#featureli").find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		$('a[name=featurelink]').show()[0].scrollIntoView(true);
		return false;
	});
	
	$("#reviewlink").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$("ul.tabs li#reviewli").addClass("active"); //Add "active" class to selected tab

		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $("ul.tabs li#reviewli").find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		//$(activeTab).show(); //show active content
		$('a[name=seeReviewlink]').show()[0].scrollIntoView(true);
		return false;
	});
});


$(window).load(function(){
	if($('.pr-snapshot-no-ratings').text()!="") {
		var link = $('.pr-snapshot-no-ratings a').attr('href');
		var norate = "Not yet rated. <br>Be the first to <a href='"+link+"'>Write a Review</a>";
		$(".reviewDetail").html(norate);
	}
	else {
	  var link = $('.pr-snapshot-footer a').attr('href');	
	  var rev_script = "<script>"
						+"function showreview(){"
						+"$(\"ul.tabs li\").removeClass(\"active\");" //Remove any "active" class
						+"$(\"ul.tabs li#reviewli\").addClass(\"active\");" //Add "active" class to selected tab
						+"$(\".tab_content\").hide();" //Hide all tab content
						+"var activeTab = $(\"ul.tabs li#reviewli\").find(\"a\").attr(\"href\");" //Find the rel attribute value to identify the active tab + content
						+"$(activeTab).fadeIn();" //Fade in the active content
		//$(activeTab).show(); //show active content
						+"$('a[name=seeReviewlink]').show()[0].scrollIntoView(true);}"
						+"</script>";
	  var rev_rate = "<a id='reviewlink' href='javascript:showreview();'>See Reviews</a>. | <a href='"+link+"'>Write a Review</a>";
	  var rev_author = $(".pr-review-wrap:first .pr-review-author-name").text();	
	  
	  var rev_comment = $(".pr-review-wrap:first .pr-comments").text()?$(".pr-review-wrap:first .pr-comments").text():"No Comments";
	  var rev_pro = "<br><strong>Pros:</strong>";
	  var rev_con = "<br><strong>Cons:</strong>";
	  var rev_pdrat = "<p style=\"display:inline-block; margin:0; padding:0; width:auto; float:left\">Product Rating</p>";
	  var rev_rate_cnt = parseInt($(".pr-review-wrap:first .pr-rating").html()).toString();
	  //var rev_rate_cnt = '1';
	  var pos = 180 - ( 5 - rev_rate_cnt ) * 36 ;
	  var rev_img_css="<style>#singlereviewstart{ background-position: 0 -"+pos+"px; background-image: url('http://lib.store.yahoo.net/lib/yhst-5006790027353/stars-small.gif'); height:15px;overflow:auto;float:right; width:83px; background-repeat:no-repeat; } </style>";
	  rev_img = "<div id='singlereviewstart'></div>";
	  $(".reviewDetail .authorName").html(rev_author);
	  $(".reviewDetail .reviewTxt").html(rev_comment);
	  $(".reviewDetail .pros").html(rev_pro).append($(".pr-review-wrap:first .pr-attribute-pros .pr-attribute-value").html());
	  $(".reviewDetail .cons").html(rev_con).append($(".pr-review-wrap:first .pr-attribute-cons .pr-attribute-value").html());
	  $(".prodRating").html(rev_pdrat).append(rev_script).append(rev_img_css).append(rev_img);
	  $(".seeWriteReview").html(rev_rate);
	  $(".pr-snippet-read-reviews").html("<a id='reviewlink' class='pr-snippet-link' href='javascript:showreview();'>See Reviews</a>");
	}
						});
