/*******************************************************************
 * This file and the cfc.interact namespace it contains are for objects
 * which add basic interactivity, such as hover and click states for elements
 * on the page.
 *
 * @Author primmee
 * 
 * objects included in this file - 
 * btn, cb, toolTip, helper, jump
 *
 * JavaScript File Dependencies  (in order):
 *   jQuery
 *   cfc.js
 *******************************************************************/
//Create Namespace
cfc.namespace("interact");

/*
 * Static object that provides basic interactivity for buttons defined
 * with specific CFC css classes, e.g, .c-stdBtn...
 */
cfc.interact.btn = (function(objSpec){

    /****************************************
     * PRIVATE Members -- Dependencies
     ****************************************/
    // state any objects this object is dependent upon like jQuery
    var $ = objSpec.$;
    
    /****************************************
     * PRIVATE Members
     ****************************************/
    // Except this object's dependencies, place all private functions, variables, etc. here 
    
    /****************************************
     * PUBLIC API
     ****************************************/
    // create obj to hold the public API and will be returned to the object under the namespace
    var publicApi = {};
    
    // assign public members to publicApi
    
    //Add active class when button pressed
    publicApi.stdBtnDown = (function(){
        $(".c-stdBtn").mousedown(function(){
            $(this).addClass("c-stdActive");
            $(this).removeClass("c-stdHover");
        });
    });
    
    //Remove active class when button is released
    publicApi.stdBtnUp = (function(){
        $(".c-stdBtn").mouseup(function(){
            $(this).removeClass("c-stdActive");
        });
    });
    
    //Toggle class for standard button hover state
    publicApi.stdBtnHvr = (function(){
        $(".c-stdBtn").hover(function(){
            $(this).addClass("c-stdHover");
        }, function(){
            $(this).removeClass("c-stdHover");
        });
    });
    
    //Add active class when attn button pressed
    publicApi.attnBtnDwn = (function(){
        $(".c-attnBtn").mousedown(function(){
            $(this).addClass(".c-stdActive");
            $(this).removeClass(".c-attnHover");
        });
    });
    
    //Remove active class when button is released
    publicApi.attnBtnUp = (function(){
        $(".c-attnBtn").mouseup(function(){
            $(this).removeClass(".c-stdActive");
        });
    });
    
    //Toggle class for attention button hover state
    publicApi.attnBtnHvr = (function(){
        $(".c-attnBtn").hover(function(){
            $(this).addClass("c-attnHover");
        }, function(){
            $(this).removeClass("c-attnHover");
        });
    });
	
 //   $('button.c-stdBtn, input.c-stdBtn').not('.c-disBtn').hover(function(){
 //       $(this).addClass('c-stdHover');
 //   }, function(){
 //       $(this).removeClass('c-stdHover');
 //   });
 //   $('button.c-attnBtn, input.c-attnBtn').not('.c-disAttnBtn').hover(function(){
 //       $(this).addClass('c-attnHover');
 //   }, function(){
 //       $(this).removeClass('c-attnHover');
 //   });
	
	
    
    publicApi.initPage = (function(){
        //start standard button interactions
        publicApi.stdBtnDown();
        publicApi.stdBtnUp();
        publicApi.stdBtnHvr();
        
        //start attention buttons interactions
        publicApi.attnBtnDwn();
        publicApi.attnBtnUp
        publicApi.attnBtnHvr();
    });
    
    return publicApi;
    
    /*
     * Optional literal objSpec parameter used to set all necessary internal parameters.
     * All dependencies should be provided through this objSpec parameter.
     */
})({
    $: jQuery
});

/*
 * cfc.interact.cb - Checkboxes
 * Static object to provide basic interactivity for checkboxes
 *
 * @receives - nothing
 * @returns - nothing
 */

cfc.interact.cb = (function(objSpec){

    /****************************************
     * PRIVATE Members -- Dependencies
     ****************************************/
    // state any objects this object is dependent upon like jQuery
    var $ = objSpec.$;
    
    /****************************************
     * PRIVATE Members
     ****************************************/
    // Except this object's dependencies, place all private functions, variables, etc. here 
    var cbToggle = $('#c-cbToggle');
    if (cbToggle.length) {
        var cbList = cbToggle.closest('table').find('tbody input[type=checkbox]');
    }
    
    /****************************************
     * PUBLIC API
     ****************************************/
    // create obj to hold the public API and will be returned to the object under the namespace
    var publicApi = {};
    
    // assign public members to publicApi
    
    //if element is marked checked unmark it, if not, mark it
    publicApi.cbClick = (function(){
    
        $('#c-cbToggle').click(function(ev){
            var cb = $(this);
            
            if ($('#c-cbToggle').attr('checked')) {
                alert("checked");
                cbToggle.closest('table').find('tbody input[type=checkbox]').attr('checked', 'checked');
            }
            else {
                cbToggle.closest('table').find('tbody input[type=checkbox]').attr('checked', '');
            }
        });
        
    });
    
    publicApi.initPage = (function(){
    
        //start checkbox interactions
        publicApi.cbClick();
        
    });
    
    return publicApi;
    
    /*
     * Optional literal objSpec parameter used to set all necessary internal parameters.
     * All dependencies should be provided through this objSpec parameter.
     */
})({
    $: jQuery
});


/*
 * Tool tip - When a user hovers over an element of the specified 
 * class, another element is made visible on the page to offer helpful
 * contextual information.
 *
 * @receives - nothing
 * @returns - nothing
 */

cfc.interact.tooltip = (function(objSpec){

    /****************************************
     * PRIVATE Members -- Dependencies
     ****************************************/
    // state any objects this object is dependent upon like jQuery
    var $ = objSpec.$;
    
    /****************************************
     * PRIVATE Members
     ****************************************/
    // Except this object's dependencies, place all private functions, variables, etc. here 
    
    
    /****************************************
     * PUBLIC API
     ****************************************/
    // create obj to hold the public API and will be returned to the object under the namespace
    var publicApi = {};
    
    // assign public members to publicApi
	
	//helper tooltip
    publicApi.helper = (function(){

        $('.c-helper .c-helpLink').hover(function(){
		   $(this).siblings('.c-toolTip').show();
        }, function(){
            $(this).siblings('.c-toolTip').hide();
        });

		
    });
    
    
    publicApi.initPage = (function(){
    
        //start checkbox interactions
        publicApi.helper();
        
    });
    
    return publicApi;
    
    /*
     * Optional literal objSpec parameter used to set all necessary internal parameters.
     * All dependencies should be provided through this objSpec parameter.
     */
})({
    $: jQuery
});


/*
 * cfc.interact.jump
 * Jump - When a user selects an item from a dropdown with one 
 * of the ids specified in the methods within this object the
 * page will redirect to the specified URL
 *
 */

cfc.interact.jump = (function(objSpec) {

    /****************************************
     * PRIVATE Members -- Dependencies
     ****************************************/
    // state any objects this object is dependent upon like jQuery
    var $ = objSpec.$;	
	
    
    /****************************************
     * PRIVATE Members
     ****************************************/
    // Except this object's dependencies, place all private functions, variables, etc. here 
	
	var redirectPage = (function(e){
	    var jumpUrl = $("#prodServ").val();
	    if (jumpUrl != null && jumpUrl != "") {
	        window.location.pathname = jumpUrl;
	    }
	    else {
	        alert("Please select a product.");
	    }
	    
	    //prevent the form submission
	    e.preventDefault();
	});
	
    
    /****************************************
     * PUBLIC API
     ****************************************/
    // create obj to hold the public API and will be returned to the namespace
    var publicApi = {};
    
    // assign public members to publicApi
    
   //Jump assigned to #jumpButton 
    publicApi.genJump = (function(){    
    	$("#jumpButton").bind("click", redirectPage);
    });
    
    //Jump assigned to #prodServ     
    publicApi.prodJump = (function(){    
        	$("#prodServ").bind("change", redirectPage);
        });    
    
    publicApi.initPage = (function(){
        publicApi.prodJump(); 
        publicApi.genJump();        
    });        	
    
	
    return publicApi;
 
/*
 * Optional literal objSpec parameter used to set all necessary intenral parameters.
 * All dependencies should be provided through this objSpec parameter.
 */ 
})(
{
    $: jQuery
});





/*
 * Description of static object which in turn is actually
 * a property of the namespace you created with "yourNamespace"
 */
cfc.interact.photo = (function(objSpec) {

    /****************************************
     * PRIVATE Members -- Dependencies
     ****************************************/
    // state any objects this object is dependent upon like jQuery
	     var $ = objSpec.$;
    
    /****************************************
     * PRIVATE Members
     ****************************************/
    // Except this object's dependencies, place all private functions, variables, etc. here 
	
    
    /****************************************
     * PUBLIC API
     ****************************************/
    // create obj to hold the public API and will be returned to the namespace
    var publicApi = {};
	
	
    
    // assign public members to publicApi
    publicApi.hover = (function(){
    
        // method body goes here
		// toggle hover class for c-photo element
        $('.c-photo').hover(function(){
            $(this).addClass('c-hover');
        }, function(){
            $(this).removeClass('c-hover');
        });
        
    });
	 
	 
	 //initialize the page
    publicApi.initPage = (function(){
    	publicApi.hover(); 

   
    }); 
	
    return publicApi;
 
/*
 * Optional literal objSpec parameter used to set all necessary intenral parameters.
 * All dependencies should be provided through this objSpec parameter.
 */ 
})(
{
	$: jQuery

});


/*******************************************************************
 Load scripts in page when DOM ready
 *******************************************************************/
$(document).ready(function(){
    cfc.interact.btn.initPage();
	cfc.interact.tooltip.initPage();
	cfc.interact.cb.initPage();
	cfc.interact.jump.initPage();	
	cfc.interact.photo.initPage();
});

//alert("cfc.interact");


