
var _url_base = 'apps2.mystart.com';
//var _url_base = 'apps2.dev.vmn.net';
//var _url_base = 'apps.localhost';

var api_url_base = _url_base + '/api/';

var api_version2 = '2_0';
var api_version3 = '3_0';
var hashTag = parseHashTag();

var api_url_apps = 'http://' + api_url_base + api_version3 + '/apps/?' + 'tb=' + hashTag['id'] + '&v=' + hashTag['v'] + '&fwv=' + hashTag['fwv'] + '&partner=' + hashTag['partner'] + '&format=json';
var api_url_categories = 'http://' + api_url_base + api_version2 + '/categories/?' + 'tb=' + hashTag['id'] + '&v=' + hashTag['v'] + '&fwv=' + hashTag['fwv'] + '&partner=' + hashTag['partner'] + '&format=json';
var api_url_countries = 'http://' + api_url_base + api_version2 + '/countries/?active=true&order=order_index DESC';
var api_url_manifest = api_url_base + api_version2 + '/manifest/';

var view_table_limit = 20;
var offset = 0;
var params = {offset: 0, more: false, sort: 'DateAdded'};
var moveToNextLoop = true;
var initialCall = true;

var tooltipText = 'Double-click to add the app';

window.widgetData = {};

$(document).ready(function(){
	
	if($.browser.msie){
		$('body').addClass('IE');
	}
	
	// some hacks if not displayed in panel
	if(hashTag['panel'] != 'true')
	{
		// if not shown in panel, display close button
		$('#top #dtx-widgetbutton-close').show();
	}
	
	$('#sortByFilter').change(function(){
		params.more = false;
		params.offset = 0;
		params.sort = $(this).val();
		getApps(params);
	});	
	
	$('#languageFilter').change(function(){
		params.more = false;
		params.offset = 0;
		params.lang = $(this).val();
		getApps(params);
	});		
	
	$('#countryFilter').change(function(){
		params.more = false;
		params.offset = 0;
		params.country = $(this).val();
		getApps(params);
	});		
	
	$('#searchFormBox input').click(function(){
		if($(this).val() == 'Search')
			$(this).val('');
	}).blur(function(){
		if($(this).val() === '')
			$(this).val('Search');
	});
	
	$('#searchFormBox input').keypress(function(event){
		if(event.keyCode == 13)
		{	
			params.more = false;
			params.offset = 0;
			params.search = $(this).val();
			getApps(params);
			return false;
		}	
	});	
	
	// create DropDownList from select HTML element                   
	$("select").uniform();
	
	$('#leftArrow').click(function(){
		var e = jQuery.Event("keydown");
		e.which = 37; // # Some key code value
		$("body").trigger(e);
	});

	$('#rightArrow').click(function(){
		var e = jQuery.Event("keydown");
		e.which = 39; // # Some key code value
		$("body").trigger(e);
	});

	// if you click on a category
	$('#categories li').click(function(){
		 $('#categories').find('li').removeClass('current');
		 $(this).addClass('current');
		 moveToNextLoop = true;
	});
	
	$('#cat_featured').click(function(){
		resetSearchField();
		params.cat = '';
		params.sort = 'DateAdded';
		params.more = false;
		params.offset = 0;
		params.lang = $(this).val();
		params.search = 0;
		getApps(params);
	});
	
	$('#cat_most_popular').click(function(){
		resetSearchField();
		params.cat = '';
		params.sort = 'DownloadCountPeriod';
		params.more = false;
		params.offset = 0;
		params.lang = $(this).val();
		getApps(params);
	});
	
	$('#cat_most_liked').click(function(){
		resetSearchField();
		params.cat = '';
		params.sort = 'LikesCount';
		params.more = false;
		params.offset = 0;
		params.lang = $(this).val();
		getApps(params);
	});
	
	getCategories();
	getCountries();
	
	//simulate click on "Featured" to get featured apps
	$('#cat_featured').trigger('click');
	
	initHoverImage();	
	initArrowKeyPress();
	
});

function showMoreApps(){
	if($('#widgetList.overview').height() + $('#widgetList.overview').position().top - $('.viewport').height() < 75){
		loadMoreApps();
    }	
}

function loadMoreApps(){
	 params.offset = params.offset + view_table_limit;
	 params.more = true;
	 getApps(params);
}

function resetSearchField(){
	$('#searchFormBox input').val('Search');
}

function getCountries(){
		  $.getJSON(api_url_countries + '&callback=?', function(data) {
		  var items = [];
	
		  $.each(data, function(key, val) {
			if(val.name.length > 17)
				val.name = val.name.substr(0 ,17) + '...';
		    items.push('<option value="' + val.id + '">' + val.name + '</option>');
		  });
	
		 $('#countryFilter').append(items.join(''));
	});	
}

function getCategories(){
	var toolbar = $.url.param('toolbar');
		  $.getJSON(api_url_categories + '&callback=?', function(data) {
		  var items = [];

		  $.each(data, function(key, val) {
		    items.push('<li id="cat_' + val.id + '">' + val.name + '</li>');
		  });

		 $('#categoryList').empty().html(items.join(''));

		 // if you click on a category
		 $('#categoryList li').click(function(){
			 $('#categories').find('li').removeClass('current');
			 resetSearchField();
			 $(this).addClass('current');
			 var id = $(this).attr('id');	
			 params.more = false;
			 params.offset = 0;
			 params.cat = id.substr(4,id.length);
			 getApps(params);
		 });	 
	});

}

function getApps(params){
	
	$('#extendedDetails').hide();
	$('#list').show();
	
	var url = api_url_apps + '&limit=' + view_table_limit;
	if(params)
	{
		if(params.cat)
		{
			url += '&cid=' + params.cat;
		}
		if(params.offset)
		{
			url += '&start=' + params.offset;
		}
		else
		{			
			url += '&start=0';
		}
		if(params.sort && params.sort != 0)
		{
			url += '&sort=' + params.sort;
		}
		if(params.lang && params.lang != 0)
		{			
			url += '&lang=' + params.lang;
		}
		if(params.country && params.country != 0)
		{			
			url += '&country=' + params.country;
		}
		if(params.search)
		{
			url += '&search=' + params.search;
		}
	}
	
	// when doing a search, ignore the featured param
	if($('#cat_featured').hasClass('current') && !params.search)
	{
		url += '&featured=true';
	}
		
	// reset params
	params.search = '';
	
	// if not more, first delete all current items
	if(params && params.more !== true)
	{	
		$('#widgetList').html('<div id="loader"><img src="images/ajax-loader.gif" /></div>');
	}
	else
	{
		$('#showMoreApps').remove();
		$('#widgetList').append('<div id="loader"><img src="images/ajax-loader.gif" /></div>');	
	}	

	$.getJSON(url + '&callback=?', function(data) {
		
		if(data.total > 0)
		{	
			 var items = [];
			 $.each(data.widgets, function(key, val) {
				
				val.widgetManifestURL = 'http://' + api_url_manifest + '?wid=' + val.id;	
				val.widgetManifestURLDragAndDrop = 'http://' + api_url_manifest + '?wid=' + val.id;
				
				var rating = new Number(val.rating);
				
				// put all apps into array with key equals AppId
				window.widgetData[val.id] = val;
				var mouseOutParam = 'out'; 
			    items.push('<div class="widgetItem" id="app_' + val.id + '">' 
			    			+ '<div class="appImageArea">'
			    			+ '<a title="'+tooltipText+'" onclick="return false;" href="' + val.widgetManifestURLDragAndDrop + '">'
			    			+ '<img class="appImage" src="http://' + val.iconLocation +'">'
			    			+ '</a>'
			    			+ '<div onmouseout="backToOriginalStars(event, this);" ><div onmouseover="changeRatingStars(this);" class="starRating" title="Rating: ' + rating.toPrecision(2) + '"></div></div></div>'
			    			+ '<div class="appTitle" title="' + val.description + '">' + val.title + '</div>' 
			    			+ '<div class="appDescription"><span>' + val.description + '</span></div>' 		    			
			    			+ '</div>');
			 });
			 
			 $('#loader').replaceWith(items.join(''));
			 
			 addStarRating();
			 
			 // display "show more" link if there is more
			 if(data.total > data.start + view_table_limit)
				 $(document).bind('scroll', showMoreApps);
			 else
				 $(document).unbind('scroll', showMoreApps);
			 
			 // if you click on an item, select it
			 $('#widgetList .widgetItem').click(function(){
				moveToNextLoop = false;
				$(this).siblings().removeClass('current');
				$(this).addClass('current');
				updateAppDetails();
			 });
			 
//			 // if you doubleclick on an item, install it
//			 $('#widgetList .widgetItem').unbind('dblclick').dblclick(function(){
//				 $('#dtx-widgetbutton-summary-add-image').trigger('click');				 
//			 });			 
			 
			 // if none is currently selected, select first one
			 if(params.more === false)
			 {			 
				 $('#widgetList .widgetItem:first').trigger('click');
				 $('#widgetList .widgetItem:first').focus();
			 }
			 
			 var oScrollbar = $("#scrollbar1");
			 if(params.offset === 0)
				 oScrollbar.tinyscrollbar();
			 else
				 oScrollbar.tinyscrollbar_update('relative');
			 
			 makeQtips($('#content .appImage'));	 
		}
		else
		{
			$('#content #round_corners_table').hide();
			$('#content #widgetList').html('<div id="noCategoryFound">No apps found.</div>');
			var oScrollbar = $("#scrollbar1");
			oScrollbar.tinyscrollbar_update();
		}	
		
	}, 	$(document).trigger('mouseup') );
}

function makeQtips(selector){
	   $(selector).each(function() {
	      if( typeof $(this).data('qtip') === 'object') { return true; }
	 
		 $(this).qtip({
				content: tooltipText,
				position: {
					container: $('#wrapper'),
					my: "bottom center",
					at: "top center"
				},
				show: {
					event: "mouseover"
				},
				hide: {
					event: "mouseout"
				},
				style: {
					width: 90,
					tip: true,
					classes: "qtip-dark"
				}
			}
);
	   });
}

function initArrowKeyPress(){
	$(document).keydown(function(e){
		try{
    		var oScrollbar = $("#scrollbar1");
			var currentItem = $('#widgetList .current');
			var hasChanged = false;
			var keyCode = e.keyCode || e.which,
		    	arrow = { pageup: 33, pagedown: 34, end: 35, home: 36, left: 37, up: 38, right: 39, down: 40 };

			var positionCurrent = $('#widgetList .current').position();
			var currentRow = Math.floor(currentItem.prevAll().size()/4) + 1;  

			  switch (keyCode) {
			    case arrow.home:
			    	if(currentItem.is(':first-child') !== true){
			    		// go to first element
			    		currentItem.removeClass('current');
			    		currentItem.parent().children(':first').addClass('current');
			    		oScrollbar.tinyscrollbar_update();
			    	}
			    break;
			    case arrow.end:
			    	if(currentItem.is(':last-child') !== true){
			    		// go to last element
			    		currentItem.removeClass('current');
			    		currentItem.parent().children(':last').addClass('current');
			    		oScrollbar.tinyscrollbar_update('bottom');
			    	}	
			    break;
			    case arrow.left:
			    	if(currentItem.prev('.widgetItem').length > 0){	
			    		currentItem.removeClass('current');
			    		currentItem.prev('.widgetItem').addClass('current');
			    	}
			    	else
			    	{
			    		oScrollbar.tinyscrollbar_update();
			    	}	
			    break;
			    case arrow.up:
			    case arrow.pageup:
			    	if(currentItem.prevAll().eq(3).length > 0){
			    		currentItem.removeClass('current');
			    		currentItem.prevAll().eq(3).addClass('current');
		  			}
			    	else
			    	{
			    		oScrollbar.tinyscrollbar_update();
			    	}	
			    break;
			    case arrow.right:
			    	if(currentItem.next('.widgetItem').length > 0){
			    		currentItem.removeClass('current');
			    		currentItem.next('.widgetItem').addClass('current');
		  			}
			    	else
			    	{
			    		oScrollbar.tinyscrollbar_update('bottom');
			    	}	
			    break;
			    case arrow.down:
			    case arrow.pagedown:
			    	if(currentItem.nextAll().eq(3).length > 0){
			       		currentItem.removeClass('current');
			    		currentItem.nextAll().eq(3).addClass('current');
		  			}
			    	else
			    	{
			    		oScrollbar.tinyscrollbar_update('bottom');
			    	}	

			    break;	
			  }

			var numRows = Math.floor($('#widgetList').children().size()/4);
			var newItem = $('#widgetList .current');
			var newRow = Math.floor(newItem.prevAll().size()/4) + 1;  
						  
			if(currentRow != newRow){ // if row has changed
				// go down until 2nd to last row	  
				if(currentRow < newRow && newRow > 3 && currentRow < numRows)  
				{
			    	oScrollbar.tinyscrollbar_update(positionCurrent.top);
				}
				
				if(currentRow < newRow && currentRow + 1 == numRows)
					loadMoreApps();

				if(currentRow > newRow && currentRow <= numRows && currentRow > 1)  // going up
				{
					var offset = positionCurrent.top - 100;
			    	oScrollbar.tinyscrollbar_update(offset);
				}
			}  

			// update the details whenever app is changed
			if(currentItem.attr('id') != newItem.attr('id'))
				updateAppDetails();			
			
		}catch(ex){
			alert(ex.message);
		}
		
	});
}

function updateAppDetails()
{
	try{
		$('#innerDetailsArea').css('opacity',0);
		$('#innerDetailsArea').empty();
		$('#content #round_corners_table').show();
		$('#widgetList .current').clone().appendTo('#innerDetailsArea');
		$('#innerDetailsArea .widgetItem').removeClass('current');
		
		$('#innerDetailsArea .appTitle').addClass('toggleDetails');
		$('#innerDetailsArea .appDescription').addClass('toggleDetails');
			
		// set new title
		var title = 'Click to show full details';
		$('#innerDetailsArea .appTitle').attr('title',title);
		$('#innerDetailsArea .appDescription').attr('title',title);
		
		var p=$('#innerDetailsArea .appDescription span');
		var divh=$('#innerDetailsArea .appDescription').height();
		while ($(p).outerHeight()>divh) {
		    $(p).text(function (index, text) {
		        return text.replace(/\W*\s(\S)*$/, '...');
		    });
		}
	
		var appId = getCurrentWidgetId();
		$('#innerDetailsArea').append('<div id="buttonArea"><div class="dtx-add-buuton"><a onclick="return false;" href="' + window.widgetData[appId].widgetManifestURL + '"><img id="dtx-widgetbutton-summary-add-image" class="hoverImage" src="images/btn-add.png"></a></div><div class="dtx-launch-buuton" ><a onclick="return false;" href="' + window.widgetData[appId].widgetManifestURL + '"><img id="dtx-widgetbutton-summary-run-image" class="hoverImage" src="images/btn-launch.png"></a></div></div>');
		
		$('#innerDetailsArea').find('div.starRating').attr('id' , 'rating_'+appId);
		$('#buttonArea').append('<div class="fb-like"><iframe src="http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent('http://apps2.mystart.com/ui/site/details.php?eid='+window.widgetData[appId].externalID) + '&layout=button_count&locale=en_US&ref=AppPanel" scrolling="no" frameborder="0" allowTransparency="true"></iframe></div>');

		if (document.createEventObject){
		    // dispatch for IE
		    var event = document.createEventObject();
			event.type = 'readystatechange';
			document.fireEvent('onreadystatechange',event);
		}else{
		    // dispatch for firefox + others
		    var evt = document.createEvent("HTMLEvents");
		    evt.initEvent('readystatechange', true, false ); // event type,bubbling,cancelable
		    z = document.dispatchEvent(evt);
		}
					
		$('.toggleDetails').click(function(){
			moveToNextLoop = false;
			showExtendedDetails();			
		});
		
		// if extendet details is currently shows, also update it
		if ($('#extendedDetails').is(':visible')) {
			showExtendedDetails();
		}
		
		$('#innerDetailsArea').animate({ opacity: 1 }, 300);
		
		initHoverImage();

		$('#innerDetailsArea .appImageArea a').attr('title',tooltipText);
		makeQtips($('#innerDetailsArea .appImage'));	

		 // if you doubleclick on an item, install it
		 $('#innerDetailsArea .widgetItem').unbind('dblclick').dblclick(function(){
			 $('#dtx-widgetbutton-summary-add-image').trigger('click');		
		 });	
		
	} catch(e){alert(e.message);}
}

function showExtendedDetails(){
	$('#extendedDetails').html('<a class="toggleDetails" href="#" id="extendedDetailsBack"><img class="backImg" src="images/btn-back.png" height="18" width="20" />Back</a>');
	$('#widgetList .current').clone().appendTo('#extendedDetails');
	
	var currentId = getCurrentWidgetId();
	var currentItem = window.widgetData[currentId];
	
	var rating = new Number(currentItem.rating);
	
	$('#extendedDetails').find('div.starRating').attr('id' , 'ratingDetails_'+currentId);
	
	$('#extendedDetails').append('<div id="extendedDetailsItems"></div');
	$('#extendedDetailsItems').append('<div class="extendedDetailsItem"><img src="images/ico-calendar.png" width="16" height="16" title="Added on" alt="Added on" />Date Added: <span class="detailValue">' + currentItem.dateAdded + '</span></div>');
	$('#extendedDetailsItems').append('<div class="extendedDetailsItem"><img src="images/ico-box-next.png" width="16" height="16" title="Published by" alt="Published by" />Published by <span class="detailValue">' + currentItem.publisherName + '</span></div>');
	$('#extendedDetailsItems').append('<div class="extendedDetailsItem"><img src="images/ico-user-monitor.png" width="16" height="16" title="Created by" alt="Created by" />Developed by <span class="detailValue">' + currentItem.developerName + '</span></div>');
	$('#extendedDetailsItems').append('<div class="extendedDetailsItem"><img src="images/ico-download.png" width="16" height="16" title="Installation Count" alt="Installation Count" />Total installations: <span class="detailValue">' + currentItem.downloadCount + '</span></div>');
	$('#extendedDetailsItems').append('<div class="extendedDetailsItem"><img src="images/ico-download.png" width="16" height="16" title="Installation Count 30 days" alt="Installation Count 30 days" />Last 30 days installations: <span class="detailValue">' + currentItem.downloadCountPeriod + '</span></div>');
	$('#extendedDetailsItems').append('<div class="extendedDetailsItem"><img src="images/thumb-up.png" width="16" height="16" title="Rating" alt="Rating" />Rating: <span class="detailValue">' + rating.toPrecision(2) + ' ('+currentItem.totalRatings+')</span></div>');
	$('#list').hide();	
	$('#extendedDetails').show();

	$('#extendedDetailsBack').click(function(){
		$('#extendedDetails').hide();
		$('#list').show();
	});	
	
	$('#extendedDetails .appImageArea a').attr('title',tooltipText);
	makeQtips($('#extendedDetails .appImage'));	 
	
	 // if you doubleclick on an item, install it
	 $('#extendedDetails .widgetItem').unbind('dblclick').dblclick(function(){
		 $('#dtx-widgetbutton-summary-add-image').trigger('click');		
	 });
}

function getCurrentWidgetId(){
	var id = $('#innerDetailsArea .widgetItem').attr('id');
	return id.substr(4,id.length);
}

// this function will add a hover effect to all images that have a hoverImage-class
function initHoverImage() {
	$('.hoverImage').unbind('hover');
	var origImg;
	var hoverImg;
	$('.hoverImage').hover(function(){
		hoverImg = origImg = $(this).attr('src');
		var pos = origImg.lastIndexOf('.');
        if(pos > 0){
          hoverImg = hoverImg.substr(0,pos) + '-over' + hoverImg.substr(pos);
        }  
		$(this).attr('src', hoverImg);
	}, function(){
		$(this).attr('src', origImg);
	});
}

function moveToNextApp() {
	// move only if moveToNextApp is true
	if(moveToNextLoop && $('#widgetList .widgetItem').length > 0)
	{	
		var currentItem = $('#widgetList .current');
		currentItem.removeClass('current');
		if(currentItem.next('.widgetItem').length > 0)
			currentItem.next('.widgetItem').addClass('current');
		else
			currentItem.siblings('.widgetItem').filter(":first").addClass('current');
			
		updateAppDetails();
	}
}

function addStarRating() {
	var starHtml = 	  ' <span onclick="rateApp(this);" class="star_1"><img src="images/star_blank.png" alt="" /></span>'
					+ ' <span onclick="rateApp(this);" class="star_2"><img src="images/star_blank.png" alt="" /></span>'
					+ ' <span onclick="rateApp(this);" class="star_3"><img src="images/star_blank.png" alt="" /></span>'
					+ ' <span onclick="rateApp(this);" class="star_4"><img src="images/star_blank.png" alt="" /></span>'
					+ ' <span onclick="rateApp(this);" class="star_5"><img src="images/star_blank.png" alt="" /></span>';

	$('.starRating').each(function(){
		// add the stars
        $(this).html(starHtml);
        var rating = this.title.substr(8,1);
		for(var loop=1; loop <= 5; loop++)
		{
			if (loop <= rating) {
                $(this).children('.star_' + loop).children('img').attr('src' , 'images/star.png');
            } else { 
                $(this).children('.star_' + loop).children('img').attr('src' , 'images/star_blank.png');
            }
		}
	});
}

function parseHashTag(){
	var paramsRaw = "";
	var params = {};
	try{
		paramsRaw = 
			(location.hash.split("?", 2)[1] || "").split("#")[0].split("&") || [];

		for(var i = 0; i< paramsRaw.length; i++){
			var single = paramsRaw[i].split("=");
			if(single[0])
				params[single[0]] = unescape(encodeURIComponent(single[1]));
		}
	}catch(ex){};
	
	return params;
}


// ----------------------  app rating code------------------------//
var _api_rating_url = 'http://' + api_url_base + api_version3 + '/rating/';

/**
 * get current app external Id
 * @param none
 */
function getCurrentExternalId() {
	return $('.appExtId').attr('id');
}

/**
 * change star colors on mouse out and set to its original rating value
 * @param event e, object obj
 */
function backToOriginalStars(e , obj) {
	// ignore Mouseout event from child element of Mouseover element
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if(reltg == null) return; //Fix issue [VCMYAP-30] Script error received from MyAppStash Team..
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode;
	if (reltg== tg) return;
	// Mouseout took place when mouse actually left layer
	var typeId = $(obj).children().attr('id');
	if((typeof(typeId) != 'undefined') && (typeId != null) ) {
		addStarRating();
	}
}

/**
 * change star colors on mouse over
 * @param object obj
 */		
function changeRatingStars(obj) {
	var typeId = $(obj).attr('id');
	if((typeof(typeId)!='undefined') || (typeId!=null) ) {
	var blockId = typeId.split("_")[0]; 
	rid = $(obj).attr("id").split("_")[1];
	$('#'+blockId+'_'+rid).children("[class^=star_]").children('img').hover(function() {
			$('#'+blockId+'_'+rid).children("[class^=star_]").children('img').attr("src" , "images/star_blank.png");
			var hovered = $(this).parent().attr("class").split("_")[1];
			while(hovered > 0) {
				$('#'+blockId+'_'+rid).children(".star_"+hovered).children('img').attr("src" , "images/star.png");
				hovered--;
			}

		});
	}
}

/**
 * rate an app by clicking on stars
 * @param object obj
 */
function rateApp(obj) {
	typeId = $(obj).parents().find('.starRating').attr('id');
	if((typeof(typeId)!='undefined') || (typeId!=null) ){ 
		var blockId = typeId.split("_")[0];
		var current_star = $(obj).attr("class").split("_")[1];
		var rid = $(obj).parent().attr("id").split("_")[1];
		
		if($.browser.msie)
		{			
			framework = top.framework;
			// check if cookie exists
			checkCookie = framework.hasDomainCookie('http://' + _url_base, 'rated'+rid);
			if(checkCookie == null)
			{
				$.getJSON(_api_rating_url + '?rating='+current_star+'&id='+rid+'&callback=?', function(data) {
					if(data.message == 'SUCCESS')
						$('#'+blockId+'_'+rid).html('<div class="highlight">App Rated!</div>');
					else if(data.message == 'ALREADY_RATED')
						$('#'+blockId+'_'+rid).html('<div class="highlight">Already Rated!</div>');
				});
				framework.createDomainCookie('http://' +  _url_base, 'rated'+rid, true, 30);
			}
			else
			{
				$('#'+blockId+'_'+rid).html('<div class="highlight">Already Rated!</div>');
			}	
		}
		else
		{
			// workaround FF, let the IFRAME create the cookie
			var iframeUrl = _api_rating_url + '?rating='+current_star+'&id='+rid+'&format=html';
			$('#'+blockId+'_'+rid).html('<iframe id="ratingFrame" src="'+iframeUrl+'" />');
		}	
		
		if(blockId=='rating'){
			showExtendedDetails();
		}
		return false;
	}

 }
			
			