/**
 * This script is supposed to hold all necessary helper functions for the 
 * Review section of the Columbia Storefront.
 */ 
var myreview = (function(jQuery)
{
	return { // <== this curly bracket has
		// dw scope public
		// note, that this code relies on single dialog modals (multi dialog, e.g. modal in modal is not supported)
		
		// app initializations called from jQuery(document).ready at the end of the file
		init: function( root ) {
			/* 
			here go all the inits.  One part of it
			is attaching the onClick functions to the buttons and other elements
			*/
			if ( root == null )
			{
				root = 'body ';
			}
			else
			{
				root += ' ';
			}
			
			//####################################################
			//
			//####################################################

			jQuery( root + 'a#checknickname').click(function(){ 
					var options = {
							triggeredObject: this, 
							hookItHereDivId: 'nickname-messages', 
							callBack: function( options ) { 
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});
			
			jQuery( root + 'a#read-reviews').click(function(){ 
					var options = {
							triggeredObject: this, 
							hookItHereDivId: 'user-reviews', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});

			
			jQuery( root + 'a.next').click(function(){ 
					var options = {
							triggeredObject: this, 
							hookItHereDivId: 'user-reviews', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});
			
			jQuery( root + 'a.prev').click(function(){ 
					var options = {
							triggeredObject: this, 
							hookItHereDivId: 'user-reviews', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});
			
			jQuery( root + 'a.positive').click(function(){ 
					var options = {
							triggeredObject: this, 
							actionValue    : this.id,
							hookItHereDivId: 'review-global-message', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});
			
			jQuery( root + 'a.negative').click(function(){ 
					var options = {
							triggeredObject: this,
							actionValue    : this.id,
							hookItHereDivId: 'review-global-message', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});
			
			jQuery( root + 'a.helpful-vote').click(function(){ 
					var options = {
							triggeredObject: this, 
							actionValue    : this.id,
							hookItHereDivId: 'review-global-message', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});	

			jQuery( root + "select[rel='rfselectreview'][class='rfselect']").change(function(){ 
					var options = {
							triggeredObject: this, 
							actionName     : "dwfrm_product_productreview_sortbyAction", 							
							hookItHereDivId: 'user-reviews', 
							callBack: function( options ) {
									myreview.init( '#' + options.hookItHereDivId + " " ); 
							} };
					app.ajaxSubmitAndShow( options ); 
					return false; 
			});
		}
	}
}
)(jQuery);

jQuery(document).ready(function(){
	
	myreview.init();
});
 
