// SCRIPTS FOR PROFILE PAGE
var buttonAltColor = 'Black';

// NOTES
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}


var notesFocused=false;
function closePopup() {
         $("#popupRefine").fadeOut(200);
}

$(document).ready(function($){
//-- Refine Search Start
/*
   $('.topNavigation .refine_search a').click( function(e) {
     if( ! $("#popupRefine").is(':visible') ) {
         $("#popupRefine").css({
             'top': $(this).parents('.topNavigation').offset().top + $(this).parents('.topNavigation').outerHeight(), 
             'left': $(this).parent().offset().left + $(this).parent().outerWidth() - $("#popupRefine").width()
         });
         $("#popupRefine").load($(this).attr('href') + " #popup_body",null,function() {
           $("#popupRefine").fadeIn(200);
         });
     } else {
         closePopup();
     }
     return false;
   });
   */
//-- Refine Search End

//-- Tab Start
    $(".tabs a").click( function() {
         //-- Change the tab colors
         $(this).addClass(buttonAltColor);
         $.each($(this).parent('li').siblings(), function() {
             $(this).find('a').removeClass(buttonAltColor);
         });
         //-- Hide the other tabs
         var elem = $(this).parents('.profileTile');
         var className = $(this).text().toLowerCase();
         elem.find('.tab:visible').fadeOut(400, function() { 
             elem.find('.tab.'+className).fadeIn(600);
         });
         return false;
    });
//-- Tab End

//-- Toggle Buttons Start
    $(".flexBtn").click( function() {
         //-- Change the tab colors
         $(this).addClass(buttonAltColor);
         $.each($(this).siblings(), function() {
             $(this).removeClass(buttonAltColor);
         });
         //-- Hide the other tabs
//-- TODO: Uncomment next line to enable buttons
//         return false;
    });
//-- Toggle Buttons End

//-- Note Button Start
    $("#noteButton").click( function() {
        if ($(this).attr("alt") == 'save') {
		        $(this).attr("width", 16 );
		        $(this).attr("src", 'images/note_plus.gif' );
		        $(this).attr("alt", '+' );
        } else {
		        $(this).attr("width", 34 );
		        $(this).attr("src", 'images/note_save.gif');
		        $(this).attr("alt", 'save' );
            $("#noteField").focus();
        };
        return false;
    });
    $("#noteField")
        .keypress( function(e) {
            if (e.which == 8 || $(this).val().length <= 115) {
                return true;
            } else {
                return false;
            }
        })
        .focus( function() {
            if ($(this).attr('edited') != "true" ) {
                $(this).val('');
            }
            if ($("#noteButton").attr("alt") == 'save') {
		            $("#noteButton").attr("width", 34 );
		            $("#noteButton").attr("src", 'images/note_save.gif');
		            $("#noteButton").attr("alt", 'save' );
            }
        })
        .blur( function() {
            $(this).attr('edited', 'true');
            if ($("#noteButton").attr("alt") != 'save') {
		            $("#noteButton").attr("width", 16 );
		            $("#noteButton").attr("src", 'images/note_plus.gif' );
		            $("#noteButton").attr("alt", '+' );
            }
        });
//-- Note Button End

});


// TABS / BUTTON SWITCH & QUIZ LOADER
function switchTab(clickedTab, tabId, tabCount, actType, tabSize, tabType){
	
	if(tabId == 'quizzesButton'){
	var quizzLinkArray = ['quizzes/quiz_stupidity.html','quizzes/quiz_breakup.html','quizzes/quiz_fetish.html','quizzes/quiz_high_maintenance.html','quizzes/quiz_who_would_you.html'];	
	document.getElementById('quizzFrame').src = quizzLinkArray[clickedTab];
	}
	
	for (x=0; x<=tabCount-1; x++){
	if(x!=clickedTab){
		document.getElementById(tabId+x+'LeftEdge').className = tabType+'Gray'+tabSize+'Edge floatLeft';
		document.getElementById(tabId+x+'Label').className = tabType+'Gray'+tabSize+actType+'Label floatLeft';
		document.getElementById(tabId+x+'RightEdge').className = tabType+'Gray'+tabSize+'Edge floatLeft '+tabType+'RightEdge';
		} else if (x==clickedTab){
		document.getElementById(tabId+x+'LeftEdge').className = tabType+'Blue'+tabSize+'Edge floatLeft';
		document.getElementById(tabId+x+'Label').className = tabType+'Blue'+tabSize+actType+'Label floatLeft';
		document.getElementById(tabId+x+'RightEdge').className = tabType+'Blue'+tabSize+'Edge floatLeft '+tabType+'RightEdge';
		}
	}
	
}



var photoRated=false;
var profileRated=false;

// HOVER RATINGS
function hoverRating(starType, hoveredStar){
	if (photoRated == false && starType=='photo'){
		document.getElementById(starType+'RatingsString').innerHTML = 'PHOTO RATING: '+hoveredStar+'.0';
		for (x=1; x<=10; x++){
			if (x<=hoveredStar){
			document.getElementById(starType+'Star'+x).src = 'images/blue_star.gif';
			} else if (x>hoveredStar){
			document.getElementById(starType+'Star'+x).src = 'images/gray_star.gif';
			}
		}
	} else if (profileRated == false && starType=='profile'){
		document.getElementById(starType+'RatingsString').innerHTML = 'PROFILE RATING: '+hoveredStar+'.0';
		for (x=1; x<=10; x++){
			if (x<=hoveredStar){
			document.getElementById(starType+'Star'+x).src = 'images/blue_star.gif';
			} else if (x>hoveredStar){
			document.getElementById(starType+'Star'+x).src = 'images/gray_star.gif';
			}
		}
	}
}

// SET RATING
function setRating(starType, clickedStar){
	if (starType == 'photo' && photoRated == false){
		photoRated=true;
		document.getElementById(starType+'RatingsString').innerHTML = 'THANK YOU!';
	} else if (starType == 'profile' && profileRated == false){
		profileRated=true;
		document.getElementById(starType+'RatingsString').innerHTML = 'THANK YOU!';
	}

}

function show(id)
{
	document.getElementById(id).className = 'showing';
}

function hide(id)
{
	document.getElementById(id).className = 'hidden';
}

function resizeQuizIframe(iframeHeight){
	
	document.getElementById('quizzFrame').style.height=iframeHeight+'px';
	//alert(iframeHeight);
	
}