jQuery(document).ready(function() {
	
	// Sets CSS-styled scrollbar
			jQuery('.scroll-pane').jScrollPane({showArrows:true});
	
	// Compile var to be passed to browser cookie
			var thisPage = 	jQuery("body").attr("class");	
			jQuery("input[@type=checkbox]").click(function() {
				jQuery.cookie(thisPage, null);
				var selectedVals = '';
				jQuery('input[@type=checkbox]:checked').each(function() {
						var thisId = jQuery(this).val();
						selectedVals = selectedVals + thisId + ",";
				});
	// Create cookie
				jQuery.cookie(thisPage, selectedVals, { path: '/' });
				var cookieValTest = jQuery.cookie(thisPage);
			});
			
	// Read cookie

				var cookieVal = jQuery.cookie(thisPage);
	// Preselect appropriate checkboxes
				if(cookieVal != null) {
			// Delimit to two characters
					var temp = new Array();
					temp = cookieVal.split(',');
			// Select appropriate checkboxes based on cookie values
				// Loop through array
					jQuery(temp).each(function(i) {
				// Loop through checkboxes
						jQuery('input[@type=checkbox]').each(function() {
				// Match values			
							if (this.value == temp[i]) {
				// Select appropriate checkboxes				
								jQuery(this).attr("checked", "checked");
							}else{
								jQuery(this).attr("unchecked");	
							};
						});
					});
				};
			
				
	// Append concatenated cookie value to url
			jQuery("area").click(function() {
		// Loop through and concatenate cookies	
				var cookieArray = new Array('br_weddingday','br_intimates','br_shoes','br_gifts','br_planners');

				var concatCookie = "";
				jQuery(cookieArray).each(function(i) {
					var tempCookie = jQuery.cookie(cookieArray[i]);
					if (tempCookie == null) {
						var tempCookie = '';
					}else{
						concatCookie = concatCookie + tempCookie;
					};	
				});
				
		// Remove commas
			//concatCookie = concatCookie.replace(/[^a-zA-Z 0-9]+/g,'');
		// Load desired page
			 var goToUrl = "/promotions/crystallized/"+(this.id)+"/?selected="+concatCookie;
			 
			 if(this.id == 'view') {
				 GBS_show('', goToUrl, 875, 880);
				 // reload the frame loaded if using Internet Explorer
                if(navigator.appVersion.indexOf("MSIE 6.0") != -1){
                        document.frames['GBS_frame'].location.href = goToUrl;
                }
                if (navigator.appVersion.indexOf("MSIE 7.0") != -1){
                        document.frames['GBS_frame'].location.href = goToUrl;
                } 
			 }else if(this.id == 'print'){
				 window.open(goToUrl); 
			 }else if(this.id == 'email') {
				 //parent.parent.GBS_hide();
				 GBS_show('', goToUrl, 430, 870);
				 if(navigator.appVersion.indexOf("MSIE 6.0") != -1){
                        document.frames['GBS_frame'].location.href = goToUrl;
                }
                if (navigator.appVersion.indexOf("MSIE 7.0") != -1){
                        document.frames['GBS_frame'].location.href = goToUrl;
                }
			 };
			 //jQuery("div#tagFrame").hide();
			 //window.location =("/promotions/crystallized/"+(this.id)+"/?selected="+concatCookie)
			 
			});
				
	});