﻿$(document).ready(function() {

	$('textarea').markItUp(bbCode);

    // lightbox-ify
	$('.thumbnailWrapper a').lightBox(
        {
            imageLoading: '/images/lightbox-ico-loading.gif',
            imageBtnPrev: '/images/lightbox-btn-prev.gif',
            imageBtnNext: '/images/lightbox-btn-next.gif',
            imageBtnClose: '/images/lightbox-btn-close.gif',
            imageBlank: '/images/lightbox-blank.gif',
            containerResizeSpeed: 100,
            txtImage: 'Photo'
        }
    );

	$('.rating li').click(
				function() {
					var parentul = $(this).parent('ul');
					//check whether its the same
					parentul.removeClass('rating');
					parentul.attr('class', 'rating ' + $(this).attr('class') + 'star');
					var score = $(this).find('a').text(); //finding the Score
					parentul.next('input').val(score);
				});

	//setTimeout("ScoreUpdate()", 5000);

});

function playAudio(file) {
	var o = new SWFObject('/swf/mp3player.swf', 'line', '0', '0', '7');
	o.addVariable('file', file);
	o.addVariable('autostart', 'true');
	o.addVariable('repeat', 'false');
	o.addVariable('showdigits', 'false');
	o.addVariable('showdownload', 'false');
	o.addVariable('width', '0');
	o.addVariable('height', '0');
	o.write('audioPlayer');
}

function swap(toDisplay) {
	$('#' + toDisplay).hide();
	switch (toDisplay) {
		case 'suggestPhotoFromFiles':
			$('#suggestPhotoFromWeb').show();
			break;
		case 'suggestPhotoFromWeb':
			$('#suggestPhotoFromFiles').show();
			break;
	}
	return false;
}

function ScoreUpdate() {
    var json = new Object();
    json.ProfileId = ProfileId;
    sendAJAX("UpdateRealTimeScore", json, this);
}

function sendAJAX(action, data, sender) {
    $.ajax({
        type: "POST",
        url: "/webservices/PersonService.svc/" + action,
        data: $.toJSON(data),
        processData: true,
        contentType: "application/json",
        dataType: "json",
        success:
            function(response, textStatus) {
                AfterAjax(response, sender, action);
            },
        error:
            function(XMLHttpRequest, textStatus, errorThrown) {
                var msg = eval("(" + XMLHttpRequest.responseText + ")").Message;
            }
    });
}

function AfterAjax(response, sender, action) {
    if (parseFloat($('.SCSMinor').text()) > parseFloat(response.SCSMinor)) {
        $('.scs').colorBlend([{ fromColor: "white", toColor: "#ffd6d6", param: "background", cycles: 1}]);
    }
    else if (parseFloat($('.SCSMinor').text()) < parseFloat(response.SCSMinor)) {
        $('.scs').colorBlend([{ fromColor: "white", toColor: "#d7ecb3", param: "background", cycles: 1}]);
    }

    $('.SCSMinor').text(response.SCSMinor);

    //setTimeout("ScoreUpdate()", 5000);
}