﻿/// <reference path="../lib/jquery/jquery-1.3.1-vsdocs.js" />

var Accepted = false;
var ChosenCharacter = '';
var ChosenProduct = '';

$(document).ready(function() {

    $('#ProductMenu a').hover(function() {
        var newPos = '0px -' + $(this).attr('rel').replace(/#/,'') + 'px';
        $(this).parent().css({'background-position' : newPos});
    }, function() {
        $(this).parent().css({'background-position' : '0px 0px'});
    });

    $('.product').click(function() {
        ChosenProduct =  $(this).attr('id');
    });
    
    $('.btn-program').click(function() {
    
        if(ChosenProduct != '') {
            // document.location = "/character.aspx?id=" + ChosenProduct;
        } else {
            // showError('Please select a product to continue.');
        }
        
    });
        
    $('#characters a').hover(function(e) {
        e.preventDefault();
        $('#characters a').removeClass('product_hover');
        $(this).addClass('product_hover');
//        
    }, function(e) {
        e.preventDefault();
        $('#characters a').removeClass('product_hover');
    });
    
    $('#characters a').click(function() {
        ChosenCharacter = $(this).attr('rel');
        $('#characters a').removeClass('product_on');
        $(this).addClass('product_on');
        document.location = "/program.aspx?id=" + ProductID + "&ChosenCharacter=" + ChosenCharacter;
        
    });
    
    $('div.radio').click(function() {
        $('div.radio').removeClass('radio_on');
        $(this).addClass('radio_on');
        
        if($(this).attr('id') == 'accepted') {
            Accepted = true;
        } else {
            Accepted = false;
        }
    });
    
    $('#CharacterButton').click(function(e) {
        e.preventDefault();
        if(ChosenCharacter != '') {
            document.location = "/program.aspx?id=" + ProductID + "&ChosenCharacter=" + ChosenCharacter;
        } else {
            showError('Please select a character to continue.');
        }
    });
    
    var modalBG;
    var modalContent;
    
    $('.modal').click(function(e) {
        e.preventDefault();
        if(!modalBG) {
            modalBG = jQuery('<div id="ModalBG"></div>').css({zIndex: 200,opacity: 0.5,width: jQuery(document).width(),height: jQuery(document).height()}).appendTo(document.body);
        }
        modalBG.fadeIn();
         //$('#ModalBG').fadeIn();
        $($(this).attr('href')).css({zIndex:1000}).fadeIn();            
    });
    
    $('.dialog').click(function(e) {
        e.preventDefault();
        $($(this).attr('href')).css({zIndex:1000}).fadeIn();  
               
    });
    
    $('.close').live('click', function() {
        $('#ModalBG').fadeOut();
        $('#box').fadeOut();
        $('#arrow-box').fadeOut();
    });
    
});

function showError(Message, fn) {

    var dialog = new Boxy("<div style='width:300px'><p>" + Message + "</p></div>", {title:'Error',modal:true, afterHide:fn});
}

function showSpelling(f) {
    $('#uiNameSpelling').val(f.replace(/[0-9]/g,'').replace(/_/g,' ').capitalize());
}

String.prototype.capitalize = function(){ //v1.0
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};
